Compare commits
No commits in common. "dev" and "main" have entirely different histories.
@ -1,92 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using SimpleLIS.DTO;
|
|
||||||
using SimpleLIS.Services;
|
|
||||||
using SimpleLIS.Models;
|
|
||||||
using AutoMapper;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace SimpleLIS.Controllers;
|
|
||||||
|
|
||||||
[ApiController]
|
|
||||||
[Route("api/hl7")]
|
|
||||||
public class HL7Controller : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly MessageService msgService;
|
|
||||||
private readonly PatientService ptService;
|
|
||||||
private readonly IMapper _mapper;
|
|
||||||
|
|
||||||
public HL7Controller(
|
|
||||||
MessageService messageService,
|
|
||||||
PatientService patientService,
|
|
||||||
IMapper mapper)
|
|
||||||
{
|
|
||||||
msgService = messageService;
|
|
||||||
ptService = patientService;
|
|
||||||
_mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("process")]
|
|
||||||
public async Task<IActionResult> ProcessHL7Message([FromBody] JsonElement payload)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var patient = new Patient
|
|
||||||
{
|
|
||||||
HL7PatientId = payload.GetProperty("hl7PatientId").GetString(),
|
|
||||||
LastName = payload.GetProperty("lastName").GetString(),
|
|
||||||
FirstName = payload.GetProperty("firstName").GetString(),
|
|
||||||
DateOfBirth = payload.GetProperty("dateOfBirth").GetDateTime(),
|
|
||||||
Gender = payload.GetProperty("gender").GetString(),
|
|
||||||
Messages = new List<Message>()
|
|
||||||
};
|
|
||||||
|
|
||||||
var existingPatient = await ptService.GetPatientByNameAndDOB(
|
|
||||||
patient.FirstName!,
|
|
||||||
patient.LastName!,
|
|
||||||
patient.DateOfBirth
|
|
||||||
);
|
|
||||||
|
|
||||||
patient = existingPatient ?? await ptService.CreatePatientAsync(patient);
|
|
||||||
var message = new Message
|
|
||||||
{
|
|
||||||
ControlId = payload.GetProperty("controlId").GetString() ?? string.Empty,
|
|
||||||
MessageType = payload.GetProperty("messageType").GetString()?? string.Empty,
|
|
||||||
SendingApp = payload.GetProperty("sendingApp").GetString(),
|
|
||||||
SendingFacility = payload.GetProperty("sendingFacility").GetString(),
|
|
||||||
ReceivingApp = payload.GetProperty("receivingApp").GetString(),
|
|
||||||
ReceivingFacility = payload.GetProperty("receivingFacility").GetString(),
|
|
||||||
Timestamp = payload.GetProperty("timestamp").GetDateTime(),
|
|
||||||
Version = payload.GetProperty("version").GetString(),
|
|
||||||
PatientId = patient.PatientId,
|
|
||||||
Patient = patient,
|
|
||||||
Observations = new List<Observation>()
|
|
||||||
};
|
|
||||||
|
|
||||||
var observationsArray = payload.GetProperty("observations");
|
|
||||||
foreach (var obsElement in observationsArray.EnumerateArray())
|
|
||||||
{
|
|
||||||
var observation = new Observation
|
|
||||||
{
|
|
||||||
ObservationCode = obsElement.GetProperty("ObservationCode").GetString()?? string.Empty,
|
|
||||||
ObservationValue = obsElement.GetProperty("ObservationValue").GetString()?? string.Empty,
|
|
||||||
Units = obsElement.GetProperty("Units").GetString(),
|
|
||||||
AbnormalFlag = obsElement.GetProperty("AbnormalFlag").GetString(),
|
|
||||||
ResultStatus = obsElement.GetProperty("ResultStatus").GetString() ?? "F",
|
|
||||||
Message = message
|
|
||||||
};
|
|
||||||
message.Observations.Add(observation);
|
|
||||||
}
|
|
||||||
|
|
||||||
var createdMessage = await msgService.CreateMessageAsync(message);
|
|
||||||
|
|
||||||
return Ok(new {
|
|
||||||
message = _mapper.Map<MessageDTO>(createdMessage),
|
|
||||||
patient = _mapper.Map<PatientDTO>(patient)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest(new { error = ex.Message + (ex.InnerException?.Message ?? "") });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SimpleLIS.DTO;
|
|
||||||
using SimpleLIS.Models;
|
using SimpleLIS.Models;
|
||||||
using SimpleLIS.Services;
|
using SimpleLIS.Services;
|
||||||
|
|
||||||
@ -42,16 +41,6 @@ public class PatientsController : ControllerBase
|
|||||||
return Ok(patientDto);
|
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]
|
[HttpGet]
|
||||||
public async Task<IActionResult> ListPatients()
|
public async Task<IActionResult> ListPatients()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -26,16 +26,6 @@ public class PatientService
|
|||||||
.FirstOrDefaultAsync(p => p.PatientId == id);
|
.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()
|
public async Task<IEnumerable<Patient>> ListPatientsAsync()
|
||||||
{
|
{
|
||||||
return await _context.Patients.ToListAsync();
|
return await _context.Patients.ToListAsync();
|
||||||
@ -62,14 +52,4 @@ public class PatientService
|
|||||||
{
|
{
|
||||||
return await _context.Patients.AnyAsync(p => p.PatientId == id);
|
return await _context.Patients.AnyAsync(p => p.PatientId == id);
|
||||||
}
|
}
|
||||||
public async Task<Patient?> GetPatientByNameAndDOB(string firstName, string lastName, DateTime dateOfBirth)
|
|
||||||
{
|
|
||||||
return await _context.Patients
|
|
||||||
.FirstOrDefaultAsync(p =>
|
|
||||||
p.FirstName == firstName &&
|
|
||||||
p.LastName == lastName &&
|
|
||||||
p.DateOfBirth == dateOfBirth);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
hl7.db-shm
BIN
hl7.db-shm
Binary file not shown.
BIN
hl7.db-wal
BIN
hl7.db-wal
Binary file not shown.
Loading…
Reference in New Issue
Block a user