Compare commits

..

No commits in common. "433723bf80f29d634812db1c0c2ec7b7f6985d51" and "fa45623f6e6f561752d9491cc93335c8dd37d4d4" have entirely different histories.

18 changed files with 386 additions and 209 deletions

View File

@ -1,97 +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 _messageService;
private readonly PatientService _patientService;
private readonly IMapper _mapper;
public HL7Controller(
MessageService messageService,
PatientService patientService,
IMapper mapper)
{
_messageService = messageService;
_patientService = patientService;
_mapper = mapper;
}
[HttpPost("process")]
public async Task<IActionResult> ProcessHL7Message([FromBody] JsonElement payload)
{
try
{
// Create Patient
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>()
};
// Check for existing patient
var existingPatient = await _patientService.GetPatientByNameAndDOB(
patient.FirstName!,
patient.LastName!,
patient.DateOfBirth
);
patient = existingPatient ?? await _patientService.CreatePatientAsync(patient);
// Create Message
var message = new Message
{
ControlId = payload.GetProperty("controlId").GetString(),
MessageType = payload.GetProperty("messageType").GetString(),
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>()
};
// Create Observations
var observationsArray = payload.GetProperty("observations");
foreach (var obsElement in observationsArray.EnumerateArray())
{
var observation = new Observation
{
ObservationCode = obsElement.GetProperty("ObservationCode").GetString(),
ObservationValue = obsElement.GetProperty("ObservationValue").GetString(),
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 _messageService.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 ?? "") });
}
}
}

View File

@ -3,14 +3,31 @@ namespace SimpleLIS.DTO;
public class MessageDTO public class MessageDTO
{ {
public int MessageId { get; set; } public int MessageId { get; set; }
public required string ControlId { 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 required string MessageType { get; set; } public string ControlId { get; set; } // Unique identifier for the HL7 message
public string? SendingApp { 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.
public string? SendingFacility { 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? ReceivingApp { get; set; } public string MessageType { get; set; } // Type of HL7 message (e.g., ORU^R01)
public string? ReceivingFacility { 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.
public DateTime Timestamp { 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? Version { get; set; } public string SendingApp { get; set; } // Sending application
public int PatientId { 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.
public required List<ObservationDTO> Observations { 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 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.
} }

View File

@ -2,11 +2,20 @@ namespace SimpleLIS.DTO;
public class ObservationDTO public class ObservationDTO
{ {
public required string ObservationCode { 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 required string ObservationValue { get; set; } public string ObservationCode { get; set; } // Code identifying the observation (e.g., WBC, HGB)
public string? Units { 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.
public string? AbnormalFlag { 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? ResultStatus { get; set; } 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; } public int ObservationId { get; internal set; }
public int MessageId { 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.
} }

View File

@ -1,8 +1,14 @@
public class PatientDTO public class PatientDTO
{ {
public int PatientId { get; set; } public int PatientId { get; set; }
public string? LastName { get; set; } #pragma warning disable CS8618
public string? FirstName { get; set; } 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; } public DateTime DateOfBirth { get; set; }
public string? Gender { get; set; } #pragma warning disable CS8618
public string Gender { get; set; }
#pragma warning restore CS8618
} }

View File

@ -8,15 +8,11 @@ public class MappingProfile : Profile
{ {
public MappingProfile() public MappingProfile()
{ {
CreateMap<Message, MessageDTO>() CreateMap<MessageDTO, Message>();
.ForMember(dest => dest.Observations, opt => opt.MapFrom(src => src.Observations)); CreateMap<Message, MessageDTO>();
CreateMap<MessageDTO, Message>() CreateMap<ObservationDTO, Observation>();
.ForMember(dest => dest.Patient, opt => opt.Ignore());
CreateMap<Observation, ObservationDTO>(); CreateMap<Observation, ObservationDTO>();
CreateMap<ObservationDTO, Observation>() CreateMap<PatientDTO, Patient>();
.ForMember(dest => dest.Message, opt => opt.Ignore());
CreateMap<Patient, PatientDTO>(); CreateMap<Patient, PatientDTO>();
CreateMap<PatientDTO, Patient>()
.ForMember(dest => dest.Messages, opt => opt.Ignore());
} }
} }

View File

@ -0,0 +1,149 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SimpleLIS;
#nullable disable
namespace SimpleLIS.Migrations
{
[DbContext(typeof(HL7DbContext))]
[Migration("20241212113523_Initial migrations")]
partial class Initialmigrations
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.11");
modelBuilder.Entity("SimpleLIS.Models.Message", b =>
{
b.Property<int>("MessageId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ControlId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("MessageType")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ReceivingApp")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ReceivingFacility")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SendingApp")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SendingFacility")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("MessageId");
b.ToTable("Messages");
});
modelBuilder.Entity("SimpleLIS.Models.Observation", b =>
{
b.Property<int>("ObservationId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AbnormalFlag")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("MessageId")
.HasColumnType("INTEGER");
b.Property<string>("ObservationCode")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ObservationValue")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ResultStatus")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Units")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ObservationId");
b.HasIndex("MessageId");
b.ToTable("Observations");
});
modelBuilder.Entity("SimpleLIS.Models.Patient", b =>
{
b.Property<int>("PatientId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("DateOfBirth")
.HasColumnType("TEXT");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Gender")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HL7PatientId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PatientId");
b.ToTable("Patients");
});
modelBuilder.Entity("SimpleLIS.Models.Observation", b =>
{
b.HasOne("SimpleLIS.Models.Message", "Message")
.WithMany("Observations")
.HasForeignKey("MessageId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Message");
});
modelBuilder.Entity("SimpleLIS.Models.Message", b =>
{
b.Navigation("Observations");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -6,28 +6,11 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace SimpleLIS.Migrations namespace SimpleLIS.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialMigrations : Migration public partial class Initialmigrations : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable(
name: "Patients",
columns: table => new
{
PatientId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
HL7PatientId = table.Column<string>(type: "TEXT", nullable: true),
LastName = table.Column<string>(type: "TEXT", nullable: true),
FirstName = table.Column<string>(type: "TEXT", nullable: true),
DateOfBirth = table.Column<DateTime>(type: "TEXT", nullable: false),
Gender = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Patients", x => x.PatientId);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Messages", name: "Messages",
columns: table => new columns: table => new
@ -36,23 +19,33 @@ namespace SimpleLIS.Migrations
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
ControlId = table.Column<string>(type: "TEXT", nullable: false), ControlId = table.Column<string>(type: "TEXT", nullable: false),
MessageType = table.Column<string>(type: "TEXT", nullable: false), MessageType = table.Column<string>(type: "TEXT", nullable: false),
SendingApp = table.Column<string>(type: "TEXT", nullable: true), SendingApp = table.Column<string>(type: "TEXT", nullable: false),
SendingFacility = table.Column<string>(type: "TEXT", nullable: true), SendingFacility = table.Column<string>(type: "TEXT", nullable: false),
ReceivingApp = table.Column<string>(type: "TEXT", nullable: true), ReceivingApp = table.Column<string>(type: "TEXT", nullable: false),
ReceivingFacility = table.Column<string>(type: "TEXT", nullable: true), ReceivingFacility = table.Column<string>(type: "TEXT", nullable: false),
Timestamp = table.Column<DateTime>(type: "TEXT", nullable: false), Timestamp = table.Column<DateTime>(type: "TEXT", nullable: false),
Version = table.Column<string>(type: "TEXT", nullable: true), Version = table.Column<string>(type: "TEXT", nullable: false)
PatientId = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Messages", x => x.MessageId); table.PrimaryKey("PK_Messages", x => x.MessageId);
table.ForeignKey( });
name: "FK_Messages_Patients_PatientId",
column: x => x.PatientId, migrationBuilder.CreateTable(
principalTable: "Patients", name: "Patients",
principalColumn: "PatientId", columns: table => new
onDelete: ReferentialAction.Cascade); {
PatientId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
HL7PatientId = table.Column<string>(type: "TEXT", nullable: false),
LastName = table.Column<string>(type: "TEXT", nullable: false),
FirstName = table.Column<string>(type: "TEXT", nullable: false),
DateOfBirth = table.Column<DateTime>(type: "TEXT", nullable: false),
Gender = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Patients", x => x.PatientId);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -64,8 +57,8 @@ namespace SimpleLIS.Migrations
MessageId = table.Column<int>(type: "INTEGER", nullable: false), MessageId = table.Column<int>(type: "INTEGER", nullable: false),
ObservationCode = table.Column<string>(type: "TEXT", nullable: false), ObservationCode = table.Column<string>(type: "TEXT", nullable: false),
ObservationValue = table.Column<string>(type: "TEXT", nullable: false), ObservationValue = table.Column<string>(type: "TEXT", nullable: false),
Units = table.Column<string>(type: "TEXT", nullable: true), Units = table.Column<string>(type: "TEXT", nullable: false),
AbnormalFlag = table.Column<string>(type: "TEXT", nullable: true), AbnormalFlag = table.Column<string>(type: "TEXT", nullable: false),
ResultStatus = table.Column<string>(type: "TEXT", nullable: false) ResultStatus = table.Column<string>(type: "TEXT", nullable: false)
}, },
constraints: table => constraints: table =>
@ -79,11 +72,6 @@ namespace SimpleLIS.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateIndex(
name: "IX_Messages_PatientId",
table: "Messages",
column: "PatientId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Observations_MessageId", name: "IX_Observations_MessageId",
table: "Observations", table: "Observations",
@ -97,10 +85,10 @@ namespace SimpleLIS.Migrations
name: "Observations"); name: "Observations");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Messages"); name: "Patients");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Patients"); name: "Messages");
} }
} }
} }

View File

@ -11,8 +11,8 @@ using SimpleLIS;
namespace SimpleLIS.Migrations namespace SimpleLIS.Migrations
{ {
[DbContext(typeof(HL7DbContext))] [DbContext(typeof(HL7DbContext))]
[Migration("20241214065908_Initial Migrations")] [Migration("20241213124817_Patients got messages")]
partial class InitialMigrations partial class Patientsgotmessages
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -38,21 +38,26 @@ namespace SimpleLIS.Migrations
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("ReceivingApp") b.Property<string>("ReceivingApp")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("ReceivingFacility") b.Property<string>("ReceivingFacility")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("SendingApp") b.Property<string>("SendingApp")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("SendingFacility") b.Property<string>("SendingFacility")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<DateTime>("Timestamp") b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Version") b.Property<string>("Version")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.HasKey("MessageId"); b.HasKey("MessageId");
@ -69,6 +74,7 @@ namespace SimpleLIS.Migrations
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("AbnormalFlag") b.Property<string>("AbnormalFlag")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("MessageId") b.Property<int>("MessageId")
@ -87,6 +93,7 @@ namespace SimpleLIS.Migrations
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Units") b.Property<string>("Units")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.HasKey("ObservationId"); b.HasKey("ObservationId");
@ -106,15 +113,19 @@ namespace SimpleLIS.Migrations
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("FirstName") b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Gender") b.Property<string>("Gender")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("HL7PatientId") b.Property<string>("HL7PatientId")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("LastName") b.Property<string>("LastName")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.HasKey("PatientId"); b.HasKey("PatientId");

View File

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SimpleLIS.Migrations
{
/// <inheritdoc />
public partial class Patientsgotmessages : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "PatientId",
table: "Messages",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateIndex(
name: "IX_Messages_PatientId",
table: "Messages",
column: "PatientId");
migrationBuilder.AddForeignKey(
name: "FK_Messages_Patients_PatientId",
table: "Messages",
column: "PatientId",
principalTable: "Patients",
principalColumn: "PatientId",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Messages_Patients_PatientId",
table: "Messages");
migrationBuilder.DropIndex(
name: "IX_Messages_PatientId",
table: "Messages");
migrationBuilder.DropColumn(
name: "PatientId",
table: "Messages");
}
}
}

View File

@ -35,21 +35,26 @@ namespace SimpleLIS.Migrations
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("ReceivingApp") b.Property<string>("ReceivingApp")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("ReceivingFacility") b.Property<string>("ReceivingFacility")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("SendingApp") b.Property<string>("SendingApp")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("SendingFacility") b.Property<string>("SendingFacility")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<DateTime>("Timestamp") b.Property<DateTime>("Timestamp")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Version") b.Property<string>("Version")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.HasKey("MessageId"); b.HasKey("MessageId");
@ -66,6 +71,7 @@ namespace SimpleLIS.Migrations
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("AbnormalFlag") b.Property<string>("AbnormalFlag")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("MessageId") b.Property<int>("MessageId")
@ -84,6 +90,7 @@ namespace SimpleLIS.Migrations
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Units") b.Property<string>("Units")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.HasKey("ObservationId"); b.HasKey("ObservationId");
@ -103,15 +110,19 @@ namespace SimpleLIS.Migrations
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("FirstName") b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Gender") b.Property<string>("Gender")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("HL7PatientId") b.Property<string>("HL7PatientId")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("LastName") b.Property<string>("LastName")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.HasKey("PatientId"); b.HasKey("PatientId");

View File

@ -3,15 +3,36 @@ namespace SimpleLIS.Models;
public class Message public class Message
{ {
public int MessageId { get; set; } public int MessageId { get; set; }
public required string ControlId { get; set; } #pragma warning disable CS8618
public required string MessageType { get; set; } public string ControlId { get; set; }
public string? SendingApp { get; set; } #pragma warning restore CS8618
public string? SendingFacility { get; set; } #pragma warning disable CS8618
public string? ReceivingApp { get; set; } public string MessageType { get; set; }
public string? ReceivingFacility { 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; } public DateTime Timestamp { get; set; }
public string? Version { get; set; } #pragma warning disable CS8618
public required ICollection<Observation> Observations { get; set; } public string Version { get; set; }
#pragma warning restore CS8618
// Navigation Property for Observations
#pragma warning disable CS8618
public ICollection<Observation> Observations { get; set; }
#pragma warning restore CS8618
public int PatientId { get; set; } public int PatientId { get; set; }
public required Patient Patient { get; set; } #pragma warning disable CS8618
public Patient Patient { get; set; }
#pragma warning restore CS8618
} }

View File

@ -3,11 +3,25 @@ namespace SimpleLIS.Models;
public class Observation public class Observation
{ {
public int ObservationId { get; set; } public int ObservationId { get; set; }
public int MessageId { get; set; } public int MessageId { get; set; } // Foreign Key
public required string ObservationCode { get; set; } #pragma warning disable CS8618
public required string ObservationValue { get; set; } public string ObservationCode { get; set; }
public string? Units { get; set; } #pragma warning restore CS8618
public string? AbnormalFlag { get; set; } #pragma warning disable CS8618
public required string ResultStatus { get; set; } public string ObservationValue { get; set; }
public required Message Message { 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
} }

View File

@ -3,10 +3,21 @@ namespace SimpleLIS.Models;
public class Patient public class Patient
{ {
public int PatientId { get; set; } public int PatientId { get; set; }
public string? HL7PatientId { get; set; } #pragma warning disable CS8618
public string? LastName { get; set; } public string HL7PatientId { get; set; }
public string? FirstName { 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; } public DateTime DateOfBirth { get; set; }
public string? Gender { get; set; } #pragma warning disable CS8618
public required ICollection<Message> Messages { 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
} }

View File

@ -19,11 +19,11 @@ public class MessageService
return message; return message;
} }
public async Task<Message?> GetMessageByIdAsync(int id) public async Task<Message> GetMessageByIdAsync(int id)
{ {
return await _context.Messages #pragma warning disable CS8603
.Include(m => m.Observations) return await _context.Messages.Include(m => m.Observations).FirstOrDefaultAsync(m => m.MessageId == id);
.FirstOrDefaultAsync(m => m.MessageId == id); #pragma warning restore CS8603
} }
public async Task<IEnumerable<Message>> ListMessagesAsync() public async Task<IEnumerable<Message>> ListMessagesAsync()

View File

@ -19,16 +19,16 @@ public class ObservationService
return observation; return observation;
} }
public async Task<Observation?> GetObservationByIdAsync(int id) public async Task<Observation> GetObservationByIdAsync(int id)
{ {
return await _context.Observations #pragma warning disable CS8603
.Include(o => o.Message) return await _context.Observations.FirstOrDefaultAsync(o => o.ObservationId == id);
.FirstOrDefaultAsync(o => o.ObservationId == id); #pragma warning restore CS8603
} }
public async Task<IEnumerable<Observation>> ListObservationsAsync() public async Task<IEnumerable<Observation>> ListObservationsAsync()
{ {
return await _context.Observations.Include(o => o.Message).ToListAsync(); return await _context.Observations.ToListAsync();
} }
public async Task<Observation> UpdateObservationAsync(Observation observation) public async Task<Observation> UpdateObservationAsync(Observation observation)

View File

@ -12,6 +12,7 @@ public class PatientService
_context = context; _context = context;
} }
public async Task<Patient> CreatePatientAsync(Patient patient) public async Task<Patient> CreatePatientAsync(Patient patient)
{ {
_context.Patients.Add(patient); _context.Patients.Add(patient);
@ -19,11 +20,11 @@ public class PatientService
return patient; return patient;
} }
public async Task<Patient?> GetPatientByIdAsync(int id) public async Task<Patient> GetPatientByIdAsync(int id)
{ {
return await _context.Patients #pragma warning disable CS8603
.Include(p => p.Messages) return await _context.Patients.FirstOrDefaultAsync(p => p.PatientId == id);
.FirstOrDefaultAsync(p => p.PatientId == id); #pragma warning restore CS8603
} }
public async Task<IEnumerable<Patient>> ListPatientsAsync() public async Task<IEnumerable<Patient>> ListPatientsAsync()
@ -52,14 +53,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);
}
} }

Binary file not shown.

Binary file not shown.