Added new controller for getting observation by patient id and hl7 id

This commit is contained in:
Aswin B. S 2024-12-15 11:57:22 +05:30
parent c14a26f020
commit 0b596cdc37
4 changed files with 21 additions and 0 deletions

View File

@ -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<IActionResult> GetPatientObservationById(string id){
List<Observation> observations;
if(int.TryParse(id, out int patientId))
observations = await _patientService.GetPatientObservationById(patientId);
else
observations = await _patientService.GetPatientObservationByHL7PatientId(id);
return Ok(_mapper.Map<List<ObservationDTO>>(observations));
}
[HttpGet]
public async Task<IActionResult> ListPatients()
{

View File

@ -26,6 +26,16 @@ public class PatientService
.FirstOrDefaultAsync(p => p.PatientId == id);
}
public async Task<List<Observation>> GetPatientObservationById(int id){
return await _context.Observations.Include(observation=>observation.Message)
.Where(observation=>observation.Message.PatientId==id).ToListAsync();
}
public async Task<List<Observation>> GetPatientObservationByHL7PatientId(string id){
return await _context.Observations.Include(observation => observation.Message)
.Where(observation => observation.Message.Patient.HL7PatientId == id).ToListAsync();
}
public async Task<IEnumerable<Patient>> ListPatientsAsync()
{
return await _context.Patients.ToListAsync();

Binary file not shown.

Binary file not shown.