From cbee21dae7b662e371b66a9f8d6485c1c9691a50 Mon Sep 17 00:00:00 2001 From: Benoy Bose Date: Fri, 13 Dec 2024 18:17:45 +0530 Subject: [PATCH] Added endpoints --- .gitignore | 400 ++++++++++++++++++++++++++ Controllers/MessageController.cs | 13 - Controllers/MessagesController.cs | 82 ++++++ Controllers/ObservationsController.cs | 80 ++++++ Controllers/PatientsController.cs | 80 ++++++ DTO/MessageDTO.cs | 33 +++ DTO/ObservationDTO.cs | 21 ++ DTO/PatientDTO.cs | 14 + HL7DbContext.cs | 18 ++ MessageProfile.cs | 18 ++ Models/Message.cs | 23 +- Models/Observation.cs | 12 + Models/Patient.cs | 12 + Program.cs | 23 +- Services/MessageService.cs | 55 ++++ Services/ObservationService.cs | 55 ++++ Services/PatientService.cs | 56 ++++ SimpleLIS.csproj | 1 + Views/Message/Index.cshtml | 3 - 19 files changed, 980 insertions(+), 19 deletions(-) delete mode 100644 Controllers/MessageController.cs create mode 100644 Controllers/MessagesController.cs create mode 100644 Controllers/ObservationsController.cs create mode 100644 Controllers/PatientsController.cs create mode 100644 DTO/MessageDTO.cs create mode 100644 DTO/ObservationDTO.cs create mode 100644 DTO/PatientDTO.cs create mode 100644 MessageProfile.cs create mode 100644 Services/MessageService.cs create mode 100644 Services/ObservationService.cs create mode 100644 Services/PatientService.cs delete mode 100644 Views/Message/Index.cshtml diff --git a/.gitignore b/.gitignore index cdebbbd..7b31e97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,403 @@ bin/ obj/ *.db +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +# but not Directory.Build.rsp, as it configures directory-level build defaults +!Directory.Build.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml \ No newline at end of file diff --git a/Controllers/MessageController.cs b/Controllers/MessageController.cs deleted file mode 100644 index bd21df6..0000000 --- a/Controllers/MessageController.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace SimpleLIS.Controllers; - -[ApiController] -[Route("messages")] -public class MessageController : Controller -{ - public IActionResult Index() - { - return View(); - } -} diff --git a/Controllers/MessagesController.cs b/Controllers/MessagesController.cs new file mode 100644 index 0000000..255ce1a --- /dev/null +++ b/Controllers/MessagesController.cs @@ -0,0 +1,82 @@ +using AutoMapper; +using Microsoft.AspNetCore.Mvc; +using SimpleLIS.DTO; +using SimpleLIS.Models; +using SimpleLIS.Services; + +namespace SimpleLIS.Controllers; + +[ApiController] +[Route("api/messages")] +public class MessagesController : ControllerBase +{ + private readonly MessageService _messageService; + private readonly IMapper _mapper; + + public MessagesController(MessageService messageService, IMapper mapper) + { + _messageService = messageService; + _mapper = mapper; + } + + [HttpPost] + public async Task CreateMessage([FromBody] MessageDTO messageDto) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + var message = _mapper.Map(messageDto); + var createdMessage = await _messageService.CreateMessageAsync(message); + + var createdMessageDto = _mapper.Map(createdMessage); + return Ok(createdMessageDto); + } + + [HttpGet("{id}")] + public async Task GetMessage(int id) + { + var message = await _messageService.GetMessageByIdAsync(id); + if (message == null) return NotFound(); + + var messageDto = _mapper.Map(message); + return Ok(messageDto); + } + + [HttpGet] + public async Task ListMessages() + { + var messages = await _messageService.ListMessagesAsync(); + var messagesDto = _mapper.Map>(messages); + + return Ok(messagesDto); + } + + // PUT: api/Messages/{id} + [HttpPut("{id}")] + public async Task UpdateMessage(int id, [FromBody] MessageDTO messageDto) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + if (!await _messageService.MessageExistsAsync(id)) + { + return NotFound(); + } + + var message = _mapper.Map(messageDto); + message.MessageId = id; // Ensure the correct ID is used + + var updatedMessage = await _messageService.UpdateMessageAsync(message); + var updatedMessageDto = _mapper.Map(updatedMessage); + + return Ok(updatedMessageDto); + } + + // DELETE: api/Messages/{id} + [HttpDelete("{id}")] + public async Task DeleteMessage(int id) + { + var deleted = await _messageService.DeleteMessageAsync(id); + if (!deleted) return NotFound(); + + return NoContent(); + } +} diff --git a/Controllers/ObservationsController.cs b/Controllers/ObservationsController.cs new file mode 100644 index 0000000..b177408 --- /dev/null +++ b/Controllers/ObservationsController.cs @@ -0,0 +1,80 @@ +using AutoMapper; +using Microsoft.AspNetCore.Mvc; +using SimpleLIS.DTO; +using SimpleLIS.Models; +using SimpleLIS.Services; + +namespace SimpleLIS.Controllers; + +[ApiController] +[Route("api/observations")] +public class ObservationsController : ControllerBase +{ + private readonly ObservationService _observationService; + private readonly IMapper _mapper; + + public ObservationsController(ObservationService observationService, IMapper mapper) + { + _observationService = observationService; + _mapper = mapper; + } + + [HttpPost] + public async Task CreateObservation([FromBody] ObservationDTO observationDto) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + var observation = _mapper.Map(observationDto); + var createdObservation = await _observationService.CreateObservationAsync(observation); + + var createdObservationDto = _mapper.Map(createdObservation); + return Ok(createdObservationDto); + } + + [HttpGet("{id}")] + public async Task GetObservation(int id) + { + var observation = await _observationService.GetObservationByIdAsync(id); + if (observation == null) return NotFound(); + + var observationDto = _mapper.Map(observation); + return Ok(observationDto); + } + + [HttpGet] + public async Task ListObservations() + { + var observations = await _observationService.ListObservationsAsync(); + var observationsDto = _mapper.Map>(observations); + + return Ok(observationsDto); + } + + [HttpPut("{id}")] + public async Task UpdateObservation(int id, [FromBody] ObservationDTO observationDto) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + if (!await _observationService.ObservationExistsAsync(id)) + { + return NotFound(); + } + + var observation = _mapper.Map(observationDto); + observation.ObservationId = id; + + var updatedObservation = await _observationService.UpdateObservationAsync(observation); + var updatedObservationDto = _mapper.Map(updatedObservation); + + return Ok(updatedObservationDto); + } + + [HttpDelete("{id}")] + public async Task DeleteObservation(int id) + { + var deleted = await _observationService.DeleteObservationAsync(id); + if (!deleted) return NotFound(); + + return NoContent(); + } +} diff --git a/Controllers/PatientsController.cs b/Controllers/PatientsController.cs new file mode 100644 index 0000000..561a1dc --- /dev/null +++ b/Controllers/PatientsController.cs @@ -0,0 +1,80 @@ +using AutoMapper; +using Microsoft.AspNetCore.Mvc; +using SimpleLIS.Models; +using SimpleLIS.Services; + +namespace SimpleLIS.Controllers; + +[ApiController] +[Route("api/patients")] +public class PatientsController : ControllerBase +{ + private readonly PatientService _patientService; + private readonly IMapper _mapper; + + public PatientsController(PatientService patientService, IMapper mapper) + { + _patientService = patientService; + _mapper = mapper; + } + + // POST: api/Patients + [HttpPost] + public async Task CreatePatient([FromBody] PatientDTO patientDto) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + var patient = _mapper.Map(patientDto); + var createdPatient = await _patientService.CreatePatientAsync(patient); + + var createdPatientDto = _mapper.Map(createdPatient); + return Ok(createdPatientDto); + } + + [HttpGet("{id}")] + public async Task GetPatient(int id) + { + var patient = await _patientService.GetPatientByIdAsync(id); + if (patient == null) return NotFound(); + + var patientDto = _mapper.Map(patient); + return Ok(patientDto); + } + + [HttpGet] + public async Task ListPatients() + { + var patients = await _patientService.ListPatientsAsync(); + var patientsDto = _mapper.Map>(patients); + + return Ok(patientsDto); + } + + [HttpPut("{id}")] + public async Task UpdatePatient(int id, [FromBody] PatientDTO patientDto) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + if (!await _patientService.PatientExistsAsync(id)) + { + return NotFound(); + } + + var patient = _mapper.Map(patientDto); + patient.PatientId = id; + + var updatedPatient = await _patientService.UpdatePatientAsync(patient); + var updatedPatientDto = _mapper.Map(updatedPatient); + + return Ok(updatedPatientDto); + } + + [HttpDelete("{id}")] + public async Task DeletePatient(int id) + { + var deleted = await _patientService.DeletePatientAsync(id); + if (!deleted) return NotFound(); + + return NoContent(); + } +} diff --git a/DTO/MessageDTO.cs b/DTO/MessageDTO.cs new file mode 100644 index 0000000..f6e256b --- /dev/null +++ b/DTO/MessageDTO.cs @@ -0,0 +1,33 @@ +namespace SimpleLIS.DTO; + +public class MessageDTO +{ + public int MessageId { get; set; } +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string ControlId { get; set; } // Unique identifier for the HL7 message +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string MessageType { get; set; } // Type of HL7 message (e.g., ORU^R01) +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string SendingApp { get; set; } // Sending application +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string SendingFacility { get; set; } // Sending facility +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string ReceivingApp { get; set; } // Receiving application +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string ReceivingFacility { get; set; } // Receiving facility +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public DateTime Timestamp { get; set; } // Message creation time +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string Version { get; set; } // HL7 version +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + + // Associated Observations +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public List Observations { get; set; } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +} diff --git a/DTO/ObservationDTO.cs b/DTO/ObservationDTO.cs new file mode 100644 index 0000000..616bc4c --- /dev/null +++ b/DTO/ObservationDTO.cs @@ -0,0 +1,21 @@ +namespace SimpleLIS.DTO; + +public class ObservationDTO +{ +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string ObservationCode { get; set; } // Code identifying the observation (e.g., WBC, HGB) +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string ObservationValue { get; set; } // The observed value +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string Units { get; set; } // Units of measurement (e.g., g/dL, %) +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string AbnormalFlag { get; set; } // Indicates if the result is abnormal +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public string ResultStatus { get; set; } // Status of the result (e.g., F for final) + public int ObservationId { get; internal set; } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. +} diff --git a/DTO/PatientDTO.cs b/DTO/PatientDTO.cs new file mode 100644 index 0000000..9057b31 --- /dev/null +++ b/DTO/PatientDTO.cs @@ -0,0 +1,14 @@ +public class PatientDTO +{ + public int PatientId { get; set; } +#pragma warning disable CS8618 + public string LastName { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 + public string FirstName { get; set; } +#pragma warning restore CS8618 + public DateTime DateOfBirth { get; set; } +#pragma warning disable CS8618 + public string Gender { get; set; } +#pragma warning restore CS8618 +} diff --git a/HL7DbContext.cs b/HL7DbContext.cs index 410a939..98c4032 100644 --- a/HL7DbContext.cs +++ b/HL7DbContext.cs @@ -5,9 +5,15 @@ using SimpleLIS.Models; public class HL7DbContext : DbContext { +#pragma warning disable CS8618 public DbSet Messages { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public DbSet Patients { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public DbSet Observations { get; set; } +#pragma warning restore CS8618 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { @@ -29,5 +35,17 @@ public class HL7DbContext : DbContext .HasMany(m => m.Observations) .WithOne(o => o.Message) .HasForeignKey(o => o.MessageId); + + modelBuilder.Entity() + .HasOne(m => m.Patient) + .WithMany(p => p.Messages) + .HasForeignKey(m => m.PatientId) + .OnDelete(DeleteBehavior.Cascade); + + modelBuilder.Entity() + .HasOne(o => o.Message) + .WithMany(m => m.Observations) + .HasForeignKey(o => o.MessageId) + .OnDelete(DeleteBehavior.Cascade); } } diff --git a/MessageProfile.cs b/MessageProfile.cs new file mode 100644 index 0000000..f391d48 --- /dev/null +++ b/MessageProfile.cs @@ -0,0 +1,18 @@ +using AutoMapper; +using SimpleLIS.DTO; +using SimpleLIS.Models; + +namespace SimpleLIS; + +public class MappingProfile : Profile +{ + public MappingProfile() + { + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + } +} diff --git a/Models/Message.cs b/Models/Message.cs index 4a2fdc5..06d8867 100644 --- a/Models/Message.cs +++ b/Models/Message.cs @@ -3,15 +3,36 @@ namespace SimpleLIS.Models; public class Message { public int MessageId { get; set; } +#pragma warning disable CS8618 public string ControlId { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string MessageType { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string SendingApp { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string SendingFacility { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string ReceivingApp { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string ReceivingFacility { get; set; } +#pragma warning restore CS8618 public DateTime Timestamp { get; set; } +#pragma warning disable CS8618 public string Version { get; set; } +#pragma warning restore CS8618 - // Navigation Property + // Navigation Property for Observations +#pragma warning disable CS8618 public ICollection Observations { get; set; } +#pragma warning restore CS8618 + + public int PatientId { get; set; } +#pragma warning disable CS8618 + public Patient Patient { get; set; } +#pragma warning restore CS8618 } diff --git a/Models/Observation.cs b/Models/Observation.cs index 65ec161..cc9415f 100644 --- a/Models/Observation.cs +++ b/Models/Observation.cs @@ -4,12 +4,24 @@ public class Observation { public int ObservationId { get; set; } public int MessageId { get; set; } // Foreign Key +#pragma warning disable CS8618 public string ObservationCode { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string ObservationValue { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string Units { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string AbnormalFlag { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string ResultStatus { get; set; } +#pragma warning restore CS8618 // Navigation Property +#pragma warning disable CS8618 public Message Message { get; set; } +#pragma warning restore CS8618 } diff --git a/Models/Patient.cs b/Models/Patient.cs index ec71e70..9fb9f25 100644 --- a/Models/Patient.cs +++ b/Models/Patient.cs @@ -3,9 +3,21 @@ namespace SimpleLIS.Models; public class Patient { public int PatientId { get; set; } +#pragma warning disable CS8618 public string HL7PatientId { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string LastName { get; set; } +#pragma warning restore CS8618 +#pragma warning disable CS8618 public string FirstName { get; set; } +#pragma warning restore CS8618 public DateTime DateOfBirth { get; set; } +#pragma warning disable CS8618 public string Gender { get; set; } +#pragma warning restore CS8618 + +#pragma warning disable CS8618 + public ICollection Messages { get; set; } +#pragma warning restore CS8618 } diff --git a/Program.cs b/Program.cs index c1b1411..2fb82f5 100644 --- a/Program.cs +++ b/Program.cs @@ -1,16 +1,29 @@ +using Microsoft.OpenApi.Models; +using SimpleLIS; +using SimpleLIS.Services; + var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddControllersWithViews(); +builder.Services.AddAutoMapper(typeof(Program)); + +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddDbContext(); + +builder.Services.AddSwaggerGen(options => +{ + options.SwaggerDoc("v1", new OpenApiInfo { Title = "SimpleLIS", Version = "v1" }); +}); var app = builder.Build(); -// Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } @@ -25,4 +38,10 @@ app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); +app.UseSwagger(); +app.UseSwaggerUI(c => +{ + c.SwaggerEndpoint("/swagger/v1/swagger.json", "SimpleLIS V1"); +}); + app.Run(); diff --git a/Services/MessageService.cs b/Services/MessageService.cs new file mode 100644 index 0000000..c257801 --- /dev/null +++ b/Services/MessageService.cs @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore; +using SimpleLIS.Models; + +namespace SimpleLIS.Services; + +public class MessageService +{ + private readonly HL7DbContext _context; + + public MessageService(HL7DbContext context) + { + _context = context; + } + + public async Task CreateMessageAsync(Message message) + { + _context.Messages.Add(message); + await _context.SaveChangesAsync(); + return message; + } + + public async Task GetMessageByIdAsync(int id) + { +#pragma warning disable CS8603 + return await _context.Messages.Include(m => m.Observations).FirstOrDefaultAsync(m => m.MessageId == id); +#pragma warning restore CS8603 + } + + public async Task> ListMessagesAsync() + { + return await _context.Messages.Include(m => m.Observations).ToListAsync(); + } + + public async Task UpdateMessageAsync(Message message) + { + _context.Messages.Update(message); + await _context.SaveChangesAsync(); + return message; + } + + public async Task DeleteMessageAsync(int id) + { + var message = await GetMessageByIdAsync(id); + if (message == null) return false; + + _context.Messages.Remove(message); + await _context.SaveChangesAsync(); + return true; + } + + public async Task MessageExistsAsync(int id) + { + return await _context.Messages.AnyAsync(m => m.MessageId == id); + } +} diff --git a/Services/ObservationService.cs b/Services/ObservationService.cs new file mode 100644 index 0000000..8dbc7d9 --- /dev/null +++ b/Services/ObservationService.cs @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore; +using SimpleLIS.Models; + +namespace SimpleLIS.Services; + +public class ObservationService +{ + private readonly HL7DbContext _context; + + public ObservationService(HL7DbContext context) + { + _context = context; + } + + public async Task CreateObservationAsync(Observation observation) + { + _context.Observations.Add(observation); + await _context.SaveChangesAsync(); + return observation; + } + + public async Task GetObservationByIdAsync(int id) + { +#pragma warning disable CS8603 + return await _context.Observations.FirstOrDefaultAsync(o => o.ObservationId == id); +#pragma warning restore CS8603 + } + + public async Task> ListObservationsAsync() + { + return await _context.Observations.ToListAsync(); + } + + public async Task UpdateObservationAsync(Observation observation) + { + _context.Observations.Update(observation); + await _context.SaveChangesAsync(); + return observation; + } + + public async Task DeleteObservationAsync(int id) + { + var observation = await GetObservationByIdAsync(id); + if (observation == null) return false; + + _context.Observations.Remove(observation); + await _context.SaveChangesAsync(); + return true; + } + + public async Task ObservationExistsAsync(int id) + { + return await _context.Observations.AnyAsync(o => o.ObservationId == id); + } +} diff --git a/Services/PatientService.cs b/Services/PatientService.cs new file mode 100644 index 0000000..34e6ff1 --- /dev/null +++ b/Services/PatientService.cs @@ -0,0 +1,56 @@ +using Microsoft.EntityFrameworkCore; +using SimpleLIS.Models; + +namespace SimpleLIS.Services; + +public class PatientService +{ + private readonly HL7DbContext _context; + + public PatientService(HL7DbContext context) + { + _context = context; + } + + + public async Task CreatePatientAsync(Patient patient) + { + _context.Patients.Add(patient); + await _context.SaveChangesAsync(); + return patient; + } + + public async Task GetPatientByIdAsync(int id) + { +#pragma warning disable CS8603 + return await _context.Patients.FirstOrDefaultAsync(p => p.PatientId == id); +#pragma warning restore CS8603 + } + + public async Task> ListPatientsAsync() + { + return await _context.Patients.ToListAsync(); + } + + public async Task UpdatePatientAsync(Patient patient) + { + _context.Patients.Update(patient); + await _context.SaveChangesAsync(); + return patient; + } + + public async Task DeletePatientAsync(int id) + { + var patient = await GetPatientByIdAsync(id); + if (patient == null) return false; + + _context.Patients.Remove(patient); + await _context.SaveChangesAsync(); + return true; + } + + public async Task PatientExistsAsync(int id) + { + return await _context.Patients.AnyAsync(p => p.PatientId == id); + } +} diff --git a/SimpleLIS.csproj b/SimpleLIS.csproj index 591008c..da70958 100644 --- a/SimpleLIS.csproj +++ b/SimpleLIS.csproj @@ -7,6 +7,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Views/Message/Index.cshtml b/Views/Message/Index.cshtml deleted file mode 100644 index 142bc28..0000000 --- a/Views/Message/Index.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -
- Hello, World -