diff --git a/Controllers/PatientsController.cs b/Controllers/PatientsController.cs index 561a1dc..b966829 100644 --- a/Controllers/PatientsController.cs +++ b/Controllers/PatientsController.cs @@ -1,5 +1,6 @@ using AutoMapper; using Microsoft.AspNetCore.Mvc; +using SimpleLIS.DTO; using SimpleLIS.Models; using SimpleLIS.Services; @@ -41,6 +42,16 @@ public class PatientsController : ControllerBase return Ok(patientDto); } + [HttpGet("{id}/observations")] + public async Task GetPatientObservationById(string id){ + List observations; + if(int.TryParse(id, out int patientId)) + observations = await _patientService.GetPatientObservationById(patientId); + else + observations = await _patientService.GetPatientObservationByHL7PatientId(id); + return Ok(_mapper.Map>(observations)); + } + [HttpGet] public async Task ListPatients() { diff --git a/Services/PatientService.cs b/Services/PatientService.cs index 23df81b..bdff4ce 100644 --- a/Services/PatientService.cs +++ b/Services/PatientService.cs @@ -26,6 +26,16 @@ public class PatientService .FirstOrDefaultAsync(p => p.PatientId == id); } + public async Task> GetPatientObservationById(int id){ + return await _context.Observations.Include(observation=>observation.Message) + .Where(observation=>observation.Message.PatientId==id).ToListAsync(); + } + + public async Task> GetPatientObservationByHL7PatientId(string id){ + return await _context.Observations.Include(observation => observation.Message) + .Where(observation => observation.Message.Patient.HL7PatientId == id).ToListAsync(); + } + public async Task> ListPatientsAsync() { return await _context.Patients.ToListAsync(); diff --git a/hl7.db-shm b/hl7.db-shm index 499e34d..e5e6b3d 100644 Binary files a/hl7.db-shm and b/hl7.db-shm differ diff --git a/hl7.db-wal b/hl7.db-wal index 231643f..879eec8 100644 Binary files a/hl7.db-wal and b/hl7.db-wal differ