This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 02:31:05 +03:00
parent 61a55fa735
commit b4eca98e0a
57 changed files with 185 additions and 105 deletions
@@ -1,6 +1,7 @@
using Application.Endpoints;
using Application.Endpoints.MedicalHistories;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
@@ -10,21 +11,21 @@ namespace API.Controllers;
public class MedicalHistoryController : ControllerBase
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IMongoDbService _mongoDbService;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryController(IMedicalHistoryRepository medicalHistoryRepository,
IPatientRepository patientRepository, IMongoDbService mongoDbService)
IPatientRepository patientRepository, IMedicalHistoryMongoDbService mongoDbService)
{
_medicalHistoryRepository = medicalHistoryRepository;
_patientRepository = patientRepository;
_mongoDbService = mongoDbService;
_medicalHistoryMongoDbService = mongoDbService;
}
[HttpGet("{id}")]
public async Task<ActionResult<BaseResponse>> GetAsync(Guid id)
{
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _medicalHistoryMongoDbService);
var response = await handler.HandleGet(id);
return StatusCode(response.StatusCode, response);
}
@@ -32,7 +33,7 @@ public class MedicalHistoryController : ControllerBase
[HttpGet]
public async Task<ActionResult<BaseResponse>> GetAllDoctors()
{
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _medicalHistoryMongoDbService);
var response = await handler.HandleGetAll();
return StatusCode(response.StatusCode, response);
}
@@ -40,7 +41,7 @@ public class MedicalHistoryController : ControllerBase
[HttpPost]
public async Task<ActionResult<BaseResponse>> PostAsync(MedicalHistoryCreateDto medicalHistoryCreateDto)
{
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _medicalHistoryMongoDbService);
var response = await handler.HandleCreate(medicalHistoryCreateDto);
return StatusCode(response.StatusCode, response);
}
@@ -48,7 +49,7 @@ public class MedicalHistoryController : ControllerBase
[HttpPut]
public async Task<ActionResult<BaseResponse>> UpdateAsync(MedicalHistoryUpdateDto medicalHistoryUpdateDto)
{
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _medicalHistoryMongoDbService);
var response = await handler.HandleUpdate(medicalHistoryUpdateDto).ConfigureAwait(false);
return StatusCode(response.StatusCode, response);
}
@@ -56,7 +57,7 @@ public class MedicalHistoryController : ControllerBase
[HttpDelete("{id}")]
public async Task<ActionResult<BaseResponse>> DeleteAsync(Guid id)
{
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _mongoDbService);
var handler = new MedicalHistoryHandler(_medicalHistoryRepository, _patientRepository, _medicalHistoryMongoDbService);
var response = await handler.HandleDelete(id);
return StatusCode(response.StatusCode, response);
}
+6 -1
View File
@@ -7,7 +7,12 @@
},
"ConnectionStrings": {
"HealthcareManagerDatabase": "Host=surus.db.elephantsql.com;Database=newbwuyu;Username=newbwuyu;Password=0end9Ixqo9PeTE4HVslX7_FVwruEhFf-;",
"MongoDBDatabase": "mongodb+srv://andrei_cerbu:andrei_cerbu@cluster0.v80skg6.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
"MongoDBConnection": "mongodb+srv://andrei_cerbu:andrei@cluster0.v80skg6.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
},
"HealthcareManagerDatabase": {
"Name":"HealthcareManager",
"MedicalRecordCollectionName": "MedicalHistory",
"ChatCollectionName": "Chat"
},
"ApiKeySettings": {
"ApiKey": "testapikey"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -7,7 +7,12 @@
},
"ConnectionStrings": {
"HealthcareManagerDatabase": "Host=surus.db.elephantsql.com;Database=newbwuyu;Username=newbwuyu;Password=0end9Ixqo9PeTE4HVslX7_FVwruEhFf-;",
"MongoDBDatabase": "mongodb+srv://andrei_cerbu:andrei_cerbu@cluster0.v80skg6.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
"MongoDBConnection": "mongodb+srv://andrei_cerbu:andrei@cluster0.v80skg6.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
},
"HealthcareManagerDatabase": {
"Name":"HealthcareManager",
"MedicalRecordCollectionName": "MedicalHistory",
"ChatCollectionName": "Chat"
},
"ApiKeySettings": {
"ApiKey": "testapikey"
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("API")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b48d5ee19e5228d9bcb979f2140f996fe7a12723")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+61a55fa7353346bdad2d677f0ec3c044c3aa87d5")]
[assembly: System.Reflection.AssemblyProductAttribute("API")]
[assembly: System.Reflection.AssemblyTitleAttribute("API")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
2a4e1c7096998582acfb9acc87d23cdf43dae534213aaa9d36839c4312b69e45
9384050dd4f92ebe3a80d1f56d1515196db26fe72de654a1ee0d4041a1b7e633
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/b48d5ee19e5228d9bcb979f2140f996fe7a12723/*"}}
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/61a55fa7353346bdad2d677f0ec3c044c3aa87d5/*"}}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -46,7 +46,7 @@ public class DoctorProfileHandler
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
StatusCode = HttpStatusCodes.NoContent,
Message = "Doctors not found",
Data = null
};
@@ -2,6 +2,6 @@
public class MedicalHistoryAuthorisationModel
{
public Guid Id { get; set; }
public List<Guid> Authorisation { get; set; } = new List<Guid>();
public string Id { get; set; }
public List<string> Authorisation { get; set; } = new List<string>();
}
@@ -1,4 +1,5 @@
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Core.Entities;
namespace Application.Endpoints.MedicalHistories;
@@ -6,15 +7,15 @@ namespace Application.Endpoints.MedicalHistories;
public class MedicalHistoryHandler
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IMongoDbService _mongoDbService;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryHandler(IMedicalHistoryRepository medicalHistoryRepository,
IPatientRepository patientRepository, IMongoDbService mongoDbService)
IPatientRepository patientRepository, IMedicalHistoryMongoDbService medicalHistoryMongoDbService)
{
_medicalHistoryRepository = medicalHistoryRepository;
_patientRepository = patientRepository;
_mongoDbService = mongoDbService;
_medicalHistoryMongoDbService = medicalHistoryMongoDbService;
}
public async Task<BaseResponse> HandleGetAll()
@@ -30,7 +31,7 @@ public class MedicalHistoryHandler
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
StatusCode = HttpStatusCodes.NoContent,
Message = "Medical histories not found",
Data = null
};
@@ -80,18 +81,15 @@ public class MedicalHistoryHandler
Content = medicalHistoryCreateDto.Content
};
await _medicalHistoryRepository.AddAsync(medicalHistory);
//TODO add to MongoDB
var medicalHistoryId = medicalHistory.Id;
var newMedicalHistory = new MedicalHistoryAuthorisationModel
{
Id = medicalHistoryId,
Authorisation = new List<Guid>()
Id = medicalHistoryId.ToString(),
Authorisation = new List<string>()
};
await _mongoDbService.AddAsync("MedicalHistory", newMedicalHistory);
await _medicalHistoryMongoDbService.AddAsync(newMedicalHistory);
await _medicalHistoryRepository.AddAsync(medicalHistory);
return new BaseResponse
{
@@ -143,6 +141,8 @@ public class MedicalHistoryHandler
Data = null
};
await _medicalHistoryMongoDbService.DeleteAsync<MedicalHistoryAuthorisationModel>("_id", id.ToString());
await _medicalHistoryRepository.DeleteAsync(medicalRecord);
//TODO delete from MongoDB
@@ -46,7 +46,7 @@ public class PatientProfileHandler
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
StatusCode = HttpStatusCodes.NoContent,
Message = "Patients not found",
Data = null
};
@@ -1,12 +0,0 @@
using MongoDB.Driver;
namespace Application.Services.Database;
public interface IMongoDbService
{
IMongoCollection<T> GetCollection<T>(string collectionName);
Task<List<T>> FindAsync<T>(string collectionName, List<(string FieldName, string Value)> criteria);
Task AddAsync<T>(string collectionName, T document);
Task ModifyAsync<T>(string collectionName, string keyField, string keyValue, T document);
Task DeleteAsync<T>(string collectionName, string keyField, string keyValue);
}
@@ -0,0 +1,6 @@
namespace Application.Services.Database.MongoDB;
public interface IChatMongoDbService
{
// Additional methods specific to Chat database
}
@@ -0,0 +1,17 @@
using Application.Endpoints.MedicalHistories;
using MongoDB.Driver;
namespace Application.Services.Database.MongoDB;
public interface IMedicalHistoryMongoDbService
{
IMongoCollection<MedicalHistoryAuthorisationModel> GetCollection<MedicalHistoryAuthorisationModel>();
Task<List<MedicalHistoryAuthorisationModel>> FindAsync<MedicalHistoryAuthorisationModel>(List<(string FieldName, string Value)> criteria);
Task AddAsync<MedicalHistoryAuthorisationModel>(MedicalHistoryAuthorisationModel document);
Task ModifyAsync<MedicalHistoryAuthorisationModel>(string keyField, string keyValue, MedicalHistoryAuthorisationModel document);
Task DeleteAsync<MedicalHistoryAuthorisationModel>(string keyField, string keyValue);
}
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Application")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b48d5ee19e5228d9bcb979f2140f996fe7a12723")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+61a55fa7353346bdad2d677f0ec3c044c3aa87d5")]
[assembly: System.Reflection.AssemblyProductAttribute("Application")]
[assembly: System.Reflection.AssemblyTitleAttribute("Application")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
e01bb5cb416ac609d6eb58b4e5e6dea85ea3572d0845400409f93dd3761941e3
ca8d9dbfc6e022b60b63524e70a3acb8ce1eaa86a2b066fce9c4864553b6125d
@@ -1 +1 @@
747e745a68129206db481649de2eb8593ffa6704b63c0c2bd731c9a83a9d670a
e99f7362e6da84368608067cdbb0c281eef010bca303f59d33c712edf6a9964f
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/b48d5ee19e5228d9bcb979f2140f996fe7a12723/*"}}
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/61a55fa7353346bdad2d677f0ec3c044c3aa87d5/*"}}
+21 -2
View File
@@ -1,4 +1,5 @@
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.HashingAlgorithms;
using Infrastructure.Data;
using Infrastructure.Services.HashingAlgorithms;
@@ -7,6 +8,7 @@ using Infrastructure.Services.PostgreSQL;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
namespace Infrastructure;
@@ -24,8 +26,19 @@ public static class DependencyInjection
services.AddScoped<IMedicalHistoryRepository, MedicalHistoryRepository>();
// MongoDB Service
var mongoDbConnection = configuration.GetConnectionString("MongoDBDatabase");
services.AddSingleton<IMongoDbService>(serviceProvider => new MongoDbService(mongoDbConnection));
var mongoDbConnectionString = configuration.GetValue<string>("ConnectionStrings:MongoDBConnection");
// Extract MongoDB database names
var healthcareManagerDatabaseName = configuration.GetValue<string>("HealthcareManagerDatabase:Name");
var medicalHistoryCollectionName = configuration.GetValue<string>("HealthcareManagerDatabase:MedicalRecordCollectionName");
var chatCollectionName = configuration.GetValue<string>("HealthcareManagerDatabase:ChatCollectionName");
// Register MongoDB services
services.AddSingleton<IMedicalHistoryMongoDbService>(serviceProvider =>
new MedicalHistoryMongoDbService(mongoDbConnectionString, healthcareManagerDatabaseName, medicalHistoryCollectionName));
services.AddSingleton<IChatMongoDbService>(serviceProvider =>
new ChatMongoDbService(mongoDbConnectionString, healthcareManagerDatabaseName, chatCollectionName));
// Other Services
@@ -34,4 +47,10 @@ public static class DependencyInjection
return services;
}
private static string ExtractMongoDbDatabaseName(string connectionString)
{
var connectionStringBuilder = new MongoUrlBuilder(connectionString);
return connectionStringBuilder.DatabaseName;
}
}
@@ -0,0 +1,13 @@
using Application.Services.Database.MongoDB;
namespace Infrastructure.Services.MongoDB;
public class ChatMongoDbService : MongoDbService, IChatMongoDbService
{
public ChatMongoDbService(string connectionString, string databaseName, string collectionName)
: base(connectionString, databaseName, collectionName)
{
}
// Implement additional methods specific to Chat database if needed
}
@@ -0,0 +1,13 @@
using Application.Services.Database.MongoDB;
namespace Infrastructure.Services.MongoDB;
public class MedicalHistoryMongoDbService : MongoDbService, IMedicalHistoryMongoDbService
{
public MedicalHistoryMongoDbService(string connectionString, string databaseName, string collectionName)
: base(connectionString, databaseName, collectionName)
{
}
// Implement additional methods specific to Medical History database if needed
}
@@ -1,35 +1,47 @@
using Application.Services.Database;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Bson;
namespace Infrastructure.Services.MongoDB;
public class MongoDbService : IMongoDbService
namespace Infrastructure.Services.MongoDB
{
private readonly IMongoDatabase _database;
public MongoDbService(string connectionString)
public class MongoDbService
{
private readonly IMongoClient _database;
private readonly string _databaseName;
private readonly string _collectionName;
public MongoDbService(string connectionString, string databaseName, string collectionName)
{
_databaseName = databaseName;
_collectionName = collectionName;
Console.WriteLine($"Connection string: {connectionString}");
Console.WriteLine($"Database Name: {databaseName}");
Console.WriteLine($"Collection Name: {collectionName}");
var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.ServerApi = new ServerApi(ServerApiVersion.V1);
var _database = new MongoClient(settings);
_database = new MongoClient(settings);
try {
try
{
var result = _database.GetDatabase("admin").RunCommand<BsonDocument>(new BsonDocument("ping", 1));
Console.WriteLine("Pinged your deployment. You successfully connected to MongoDB!");
} catch (Exception ex) {
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public IMongoCollection<T> GetCollection<T>(string collectionName)
public IMongoCollection<T> GetCollection<T>()
{
return _database.GetCollection<T>(collectionName);
return _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
}
public async Task<List<T>> FindAsync<T>(string collectionName, List<(string FieldName, string Value)> criteria)
public async Task<List<T>> FindAsync<T>(List<(string FieldName, string Value)> criteria)
{
var collection = _database.GetCollection<T>(collectionName);
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
var filters = new List<FilterDefinition<T>>();
foreach (var (FieldName, Value) in criteria) filters.Add(Builders<T>.Filter.Eq(FieldName, Value));
@@ -39,23 +51,24 @@ public class MongoDbService : IMongoDbService
return await collection.Find(combinedFilter).ToListAsync();
}
public async Task AddAsync<T>(string collectionName, T document)
public async Task AddAsync<T>(T document)
{
var collection = _database.GetCollection<T>(collectionName);
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
await collection.InsertOneAsync(document);
}
public async Task ModifyAsync<T>(string collectionName, string keyField, string keyValue, T document)
public async Task ModifyAsync<T>(string keyField, string keyValue, T document)
{
var collection = _database.GetCollection<T>(collectionName);
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
await collection.ReplaceOneAsync(filter, document, new ReplaceOptions { IsUpsert = true });
}
public async Task DeleteAsync<T>(string collectionName, string keyField, string keyValue)
public async Task DeleteAsync<T>(string keyField, string keyValue)
{
var collection = _database.GetCollection<T>(collectionName);
var collection = _database.GetDatabase(_databaseName).GetCollection<T>(_collectionName);
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
await collection.DeleteOneAsync(filter);
}
}
}
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b48d5ee19e5228d9bcb979f2140f996fe7a12723")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+61a55fa7353346bdad2d677f0ec3c044c3aa87d5")]
[assembly: System.Reflection.AssemblyProductAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyTitleAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
1eff5085180ba5a7e0c455493bf156ab7c10e42899382b41bdf7799d2b2ca6d6
08604fac7a3083586b55565c1ab1f39ea8637dd70dd31c4daa6a7693d2108c04
@@ -1 +1 @@
8ecca766b80ccc6e510e107ea1369b5001c45e66e3507ff5e47c4d13fae048e4
39d9df72cda14e46450bf8a8087069ed85d06562c962bd2ab07df607c60c7cf4
@@ -1 +1 @@
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/b48d5ee19e5228d9bcb979f2140f996fe7a12723/*"}}
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/61a55fa7353346bdad2d677f0ec3c044c3aa87d5/*"}}