Added endpoints
This commit is contained in:
parent
74ef778585
commit
cbee21dae7
400
.gitignore
vendored
400
.gitignore
vendored
@ -1,3 +1,403 @@
|
|||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
*.db
|
*.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
|
||||||
@ -1,13 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace SimpleLIS.Controllers;
|
|
||||||
|
|
||||||
[ApiController]
|
|
||||||
[Route("messages")]
|
|
||||||
public class MessageController : Controller
|
|
||||||
{
|
|
||||||
public IActionResult Index()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
82
Controllers/MessagesController.cs
Normal file
82
Controllers/MessagesController.cs
Normal file
@ -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<IActionResult> CreateMessage([FromBody] MessageDTO messageDto)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
var message = _mapper.Map<Message>(messageDto);
|
||||||
|
var createdMessage = await _messageService.CreateMessageAsync(message);
|
||||||
|
|
||||||
|
var createdMessageDto = _mapper.Map<MessageDTO>(createdMessage);
|
||||||
|
return Ok(createdMessageDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetMessage(int id)
|
||||||
|
{
|
||||||
|
var message = await _messageService.GetMessageByIdAsync(id);
|
||||||
|
if (message == null) return NotFound();
|
||||||
|
|
||||||
|
var messageDto = _mapper.Map<MessageDTO>(message);
|
||||||
|
return Ok(messageDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> ListMessages()
|
||||||
|
{
|
||||||
|
var messages = await _messageService.ListMessagesAsync();
|
||||||
|
var messagesDto = _mapper.Map<IEnumerable<MessageDTO>>(messages);
|
||||||
|
|
||||||
|
return Ok(messagesDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT: api/Messages/{id}
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<IActionResult> UpdateMessage(int id, [FromBody] MessageDTO messageDto)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
if (!await _messageService.MessageExistsAsync(id))
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = _mapper.Map<Message>(messageDto);
|
||||||
|
message.MessageId = id; // Ensure the correct ID is used
|
||||||
|
|
||||||
|
var updatedMessage = await _messageService.UpdateMessageAsync(message);
|
||||||
|
var updatedMessageDto = _mapper.Map<MessageDTO>(updatedMessage);
|
||||||
|
|
||||||
|
return Ok(updatedMessageDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE: api/Messages/{id}
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeleteMessage(int id)
|
||||||
|
{
|
||||||
|
var deleted = await _messageService.DeleteMessageAsync(id);
|
||||||
|
if (!deleted) return NotFound();
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
80
Controllers/ObservationsController.cs
Normal file
80
Controllers/ObservationsController.cs
Normal file
@ -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<IActionResult> CreateObservation([FromBody] ObservationDTO observationDto)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
var observation = _mapper.Map<Observation>(observationDto);
|
||||||
|
var createdObservation = await _observationService.CreateObservationAsync(observation);
|
||||||
|
|
||||||
|
var createdObservationDto = _mapper.Map<ObservationDTO>(createdObservation);
|
||||||
|
return Ok(createdObservationDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetObservation(int id)
|
||||||
|
{
|
||||||
|
var observation = await _observationService.GetObservationByIdAsync(id);
|
||||||
|
if (observation == null) return NotFound();
|
||||||
|
|
||||||
|
var observationDto = _mapper.Map<ObservationDTO>(observation);
|
||||||
|
return Ok(observationDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> ListObservations()
|
||||||
|
{
|
||||||
|
var observations = await _observationService.ListObservationsAsync();
|
||||||
|
var observationsDto = _mapper.Map<IEnumerable<ObservationDTO>>(observations);
|
||||||
|
|
||||||
|
return Ok(observationsDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<IActionResult> UpdateObservation(int id, [FromBody] ObservationDTO observationDto)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
if (!await _observationService.ObservationExistsAsync(id))
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var observation = _mapper.Map<Observation>(observationDto);
|
||||||
|
observation.ObservationId = id;
|
||||||
|
|
||||||
|
var updatedObservation = await _observationService.UpdateObservationAsync(observation);
|
||||||
|
var updatedObservationDto = _mapper.Map<ObservationDTO>(updatedObservation);
|
||||||
|
|
||||||
|
return Ok(updatedObservationDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeleteObservation(int id)
|
||||||
|
{
|
||||||
|
var deleted = await _observationService.DeleteObservationAsync(id);
|
||||||
|
if (!deleted) return NotFound();
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
80
Controllers/PatientsController.cs
Normal file
80
Controllers/PatientsController.cs
Normal file
@ -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<IActionResult> CreatePatient([FromBody] PatientDTO patientDto)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
var patient = _mapper.Map<Patient>(patientDto);
|
||||||
|
var createdPatient = await _patientService.CreatePatientAsync(patient);
|
||||||
|
|
||||||
|
var createdPatientDto = _mapper.Map<PatientDTO>(createdPatient);
|
||||||
|
return Ok(createdPatientDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetPatient(int id)
|
||||||
|
{
|
||||||
|
var patient = await _patientService.GetPatientByIdAsync(id);
|
||||||
|
if (patient == null) return NotFound();
|
||||||
|
|
||||||
|
var patientDto = _mapper.Map<PatientDTO>(patient);
|
||||||
|
return Ok(patientDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> ListPatients()
|
||||||
|
{
|
||||||
|
var patients = await _patientService.ListPatientsAsync();
|
||||||
|
var patientsDto = _mapper.Map<IEnumerable<PatientDTO>>(patients);
|
||||||
|
|
||||||
|
return Ok(patientsDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public async Task<IActionResult> UpdatePatient(int id, [FromBody] PatientDTO patientDto)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
|
|
||||||
|
if (!await _patientService.PatientExistsAsync(id))
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var patient = _mapper.Map<Patient>(patientDto);
|
||||||
|
patient.PatientId = id;
|
||||||
|
|
||||||
|
var updatedPatient = await _patientService.UpdatePatientAsync(patient);
|
||||||
|
var updatedPatientDto = _mapper.Map<PatientDTO>(updatedPatient);
|
||||||
|
|
||||||
|
return Ok(updatedPatientDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeletePatient(int id)
|
||||||
|
{
|
||||||
|
var deleted = await _patientService.DeletePatientAsync(id);
|
||||||
|
if (!deleted) return NotFound();
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
33
DTO/MessageDTO.cs
Normal file
33
DTO/MessageDTO.cs
Normal file
@ -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<ObservationDTO> 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.
|
||||||
|
}
|
||||||
21
DTO/ObservationDTO.cs
Normal file
21
DTO/ObservationDTO.cs
Normal file
@ -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.
|
||||||
|
}
|
||||||
14
DTO/PatientDTO.cs
Normal file
14
DTO/PatientDTO.cs
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -5,9 +5,15 @@ using SimpleLIS.Models;
|
|||||||
|
|
||||||
public class HL7DbContext : DbContext
|
public class HL7DbContext : DbContext
|
||||||
{
|
{
|
||||||
|
#pragma warning disable CS8618
|
||||||
public DbSet<Message> Messages { get; set; }
|
public DbSet<Message> Messages { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public DbSet<Patient> Patients { get; set; }
|
public DbSet<Patient> Patients { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public DbSet<Observation> Observations { get; set; }
|
public DbSet<Observation> Observations { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
@ -29,5 +35,17 @@ public class HL7DbContext : DbContext
|
|||||||
.HasMany(m => m.Observations)
|
.HasMany(m => m.Observations)
|
||||||
.WithOne(o => o.Message)
|
.WithOne(o => o.Message)
|
||||||
.HasForeignKey(o => o.MessageId);
|
.HasForeignKey(o => o.MessageId);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Message>()
|
||||||
|
.HasOne(m => m.Patient)
|
||||||
|
.WithMany(p => p.Messages)
|
||||||
|
.HasForeignKey(m => m.PatientId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Observation>()
|
||||||
|
.HasOne(o => o.Message)
|
||||||
|
.WithMany(m => m.Observations)
|
||||||
|
.HasForeignKey(o => o.MessageId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
MessageProfile.cs
Normal file
18
MessageProfile.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using SimpleLIS.DTO;
|
||||||
|
using SimpleLIS.Models;
|
||||||
|
|
||||||
|
namespace SimpleLIS;
|
||||||
|
|
||||||
|
public class MappingProfile : Profile
|
||||||
|
{
|
||||||
|
public MappingProfile()
|
||||||
|
{
|
||||||
|
CreateMap<MessageDTO, Message>();
|
||||||
|
CreateMap<Message, MessageDTO>();
|
||||||
|
CreateMap<ObservationDTO, Observation>();
|
||||||
|
CreateMap<Observation, ObservationDTO>();
|
||||||
|
CreateMap<PatientDTO, Patient>();
|
||||||
|
CreateMap<Patient, PatientDTO>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,15 +3,36 @@ namespace SimpleLIS.Models;
|
|||||||
public class Message
|
public class Message
|
||||||
{
|
{
|
||||||
public int MessageId { get; set; }
|
public int MessageId { get; set; }
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string ControlId { get; set; }
|
public string ControlId { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string MessageType { get; set; }
|
public string MessageType { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string SendingApp { get; set; }
|
public string SendingApp { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string SendingFacility { get; set; }
|
public string SendingFacility { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string ReceivingApp { get; set; }
|
public string ReceivingApp { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string ReceivingFacility { get; set; }
|
public string ReceivingFacility { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
public DateTime Timestamp { get; set; }
|
public DateTime Timestamp { get; set; }
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string Version { get; set; }
|
public string Version { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
|
||||||
// Navigation Property
|
// Navigation Property for Observations
|
||||||
|
#pragma warning disable CS8618
|
||||||
public ICollection<Observation> Observations { get; set; }
|
public ICollection<Observation> 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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,24 @@ public class Observation
|
|||||||
{
|
{
|
||||||
public int ObservationId { get; set; }
|
public int ObservationId { get; set; }
|
||||||
public int MessageId { get; set; } // Foreign Key
|
public int MessageId { get; set; } // Foreign Key
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string ObservationCode { get; set; }
|
public string ObservationCode { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string ObservationValue { get; set; }
|
public string ObservationValue { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string Units { get; set; }
|
public string Units { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string AbnormalFlag { get; set; }
|
public string AbnormalFlag { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string ResultStatus { get; set; }
|
public string ResultStatus { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
|
||||||
// Navigation Property
|
// Navigation Property
|
||||||
|
#pragma warning disable CS8618
|
||||||
public Message Message { get; set; }
|
public Message Message { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,9 +3,21 @@ namespace SimpleLIS.Models;
|
|||||||
public class Patient
|
public class Patient
|
||||||
{
|
{
|
||||||
public int PatientId { get; set; }
|
public int PatientId { get; set; }
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string HL7PatientId { get; set; }
|
public string HL7PatientId { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string FirstName { get; set; }
|
public string FirstName { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
public DateTime DateOfBirth { get; set; }
|
public DateTime DateOfBirth { get; set; }
|
||||||
|
#pragma warning disable CS8618
|
||||||
public string Gender { get; set; }
|
public string Gender { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
|
|
||||||
|
#pragma warning disable CS8618
|
||||||
|
public ICollection<Message> Messages { get; set; }
|
||||||
|
#pragma warning restore CS8618
|
||||||
}
|
}
|
||||||
|
|||||||
23
Program.cs
23
Program.cs
@ -1,16 +1,29 @@
|
|||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using SimpleLIS;
|
||||||
|
using SimpleLIS.Services;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
builder.Services.AddAutoMapper(typeof(Program));
|
||||||
|
|
||||||
|
builder.Services.AddScoped<MessageService>();
|
||||||
|
builder.Services.AddScoped<ObservationService>();
|
||||||
|
builder.Services.AddScoped<PatientService>();
|
||||||
|
builder.Services.AddDbContext<HL7DbContext>();
|
||||||
|
|
||||||
|
builder.Services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "SimpleLIS", Version = "v1" });
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
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();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,4 +38,10 @@ app.MapControllerRoute(
|
|||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||||
|
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "SimpleLIS V1");
|
||||||
|
});
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
55
Services/MessageService.cs
Normal file
55
Services/MessageService.cs
Normal file
@ -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<Message> CreateMessageAsync(Message message)
|
||||||
|
{
|
||||||
|
_context.Messages.Add(message);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Message> 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<IEnumerable<Message>> ListMessagesAsync()
|
||||||
|
{
|
||||||
|
return await _context.Messages.Include(m => m.Observations).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Message> UpdateMessageAsync(Message message)
|
||||||
|
{
|
||||||
|
_context.Messages.Update(message);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> 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<bool> MessageExistsAsync(int id)
|
||||||
|
{
|
||||||
|
return await _context.Messages.AnyAsync(m => m.MessageId == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
55
Services/ObservationService.cs
Normal file
55
Services/ObservationService.cs
Normal file
@ -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<Observation> CreateObservationAsync(Observation observation)
|
||||||
|
{
|
||||||
|
_context.Observations.Add(observation);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return observation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Observation> GetObservationByIdAsync(int id)
|
||||||
|
{
|
||||||
|
#pragma warning disable CS8603
|
||||||
|
return await _context.Observations.FirstOrDefaultAsync(o => o.ObservationId == id);
|
||||||
|
#pragma warning restore CS8603
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Observation>> ListObservationsAsync()
|
||||||
|
{
|
||||||
|
return await _context.Observations.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Observation> UpdateObservationAsync(Observation observation)
|
||||||
|
{
|
||||||
|
_context.Observations.Update(observation);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return observation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> 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<bool> ObservationExistsAsync(int id)
|
||||||
|
{
|
||||||
|
return await _context.Observations.AnyAsync(o => o.ObservationId == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
56
Services/PatientService.cs
Normal file
56
Services/PatientService.cs
Normal file
@ -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<Patient> CreatePatientAsync(Patient patient)
|
||||||
|
{
|
||||||
|
_context.Patients.Add(patient);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Patient> GetPatientByIdAsync(int id)
|
||||||
|
{
|
||||||
|
#pragma warning disable CS8603
|
||||||
|
return await _context.Patients.FirstOrDefaultAsync(p => p.PatientId == id);
|
||||||
|
#pragma warning restore CS8603
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Patient>> ListPatientsAsync()
|
||||||
|
{
|
||||||
|
return await _context.Patients.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Patient> UpdatePatientAsync(Patient patient)
|
||||||
|
{
|
||||||
|
_context.Patients.Update(patient);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> 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<bool> PatientExistsAsync(int id)
|
||||||
|
{
|
||||||
|
return await _context.Patients.AnyAsync(p => p.PatientId == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.11">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.11">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
<div>
|
|
||||||
Hello, World
|
|
||||||
</div>
|
|
||||||
Loading…
Reference in New Issue
Block a user