=== Summary: 675 files | 7 generated | 484 fresh | 4605 untracked | 4268 adopted | 355 marked | 466 validated-ok | 2+0 stale (sig+body) | 0 skipped | 0 failed | elapsed 11:08:11.442 (40091.44s) ===

This commit is contained in:
julian
2026-06-28 02:50:05 -07:00
parent a19fb90902
commit 586f02a2ca
654 changed files with 5260 additions and 0 deletions
@@ -25,6 +25,7 @@ namespace adas_core.Application.Services;
/// (<c>OMP_O09</c>, <c>ORM_O01</c>, <c>RAS_O17</c>) and emits broadcasts to
/// subscribers based on the patient's point of care.
/// </remarks>
/// <!-- aidoc:v1 sig=2ea7df4 -->
public class TreatmentService(
ITreatmentRepository treatmentRepository,
ITreatmentArchiveRepository treatmentArchiveRepository,
@@ -47,6 +48,7 @@ public class TreatmentService(
/// A task that represents the asynchronous operation. The task result contains
/// an <see cref="IEnumerable{T}"/> of <see cref="PatientTreatment"/> for the patient.
/// </returns>
/// <!-- aidoc:v1 sig=10e5f85 body=be14412 -->
public async Task<IEnumerable<PatientTreatment>> GetTreatmentsByPatientId(ObjectId id)
{
return await treatmentRepository.GetByPatientId(id);
@@ -62,6 +64,7 @@ public class TreatmentService(
/// If the treatment cannot be mapped, it is silently ignored. A broadcast
/// is dispatched asynchronously upon successful insertion.
/// </remarks>
/// <!-- aidoc:v1 sig=d915a21 body=09c8128 -->
public async Task Insert(PatientTreatment treatment)
{
logger.LogDebug("Insert {treatment}", treatment);
@@ -88,6 +91,7 @@ public class TreatmentService(
/// Thrown when the patient has no treatments to delete (no record was found)
/// or when the underlying delete operation fails.
/// </exception>
/// <!-- aidoc:v1 sig=cc92a12 body=aa4c4ae -->
public async Task<bool> DeleteByPatientId(ObjectId id)
{
var treatmentToDelete = await FindByPatientId(id) ??
@@ -108,6 +112,7 @@ public class TreatmentService(
/// </summary>
/// <param name="patient">The <see cref="Patient"/> whose treatments will be archived.</param>
/// <returns>A task that represents the asynchronous archive operation.</returns>
/// <!-- aidoc:v1 sig=0afe718 body=be01ba0 -->
public async Task Archive(Patient patient)
{
await ArchiveByPatientId(patient.Id);
@@ -119,6 +124,7 @@ public class TreatmentService(
/// </summary>
/// <param name="id">The <see cref="ObjectId"/> of the patient whose treatments will be archived.</param>
/// <returns>A task that represents the asynchronous archive operation.</returns>
/// <!-- aidoc:v1 sig=3385472 body=15c288e -->
public async Task ArchiveByPatientId(ObjectId id)
{
logger.LogDebug("ArchiveB Treatments by Patient Id PatientId {id}", id);
@@ -144,6 +150,7 @@ public class TreatmentService(
/// <exception cref="ConflictException">
/// Thrown when the treatment does not exist or the update operation fails.
/// </exception>
/// <!-- aidoc:v1 sig=6e80560 body=5fae191 -->
public async Task<bool> UpdateTreatment(PatientTreatment patientTreatment)
{
var oldTreatment = await treatmentRepository.GetById(patientTreatment.Id) ??
@@ -166,6 +173,7 @@ public class TreatmentService(
/// A task that represents the asynchronous operation. The task result contains
/// an <see cref="IAsyncCursor{T}"/> of <see cref="PatientTreatment"/>.
/// </returns>
/// <!-- aidoc:v1 sig=2560a5d body=edd0375 -->
public async Task<IAsyncCursor<PatientTreatment>> FindByPatientIdAsync(ObjectId patientId)
{
return await treatmentRepository.FindByPatientIdAsync(patientId);
@@ -179,6 +187,7 @@ public class TreatmentService(
/// A task that represents the asynchronous operation. The task result contains
/// an <see cref="IEnumerable{T}"/> of <see cref="PatientTreatment"/>.
/// </returns>
/// <!-- aidoc:v1 sig=1aafccf body=be6338f -->
public async Task<IEnumerable<PatientTreatment>> FindByPatientId(ObjectId patientId)
{
return await treatmentRepository.FindByPatientId(patientId);
@@ -192,6 +201,7 @@ public class TreatmentService(
/// A task that represents the asynchronous operation. The task result contains
/// a <see cref="List{T}"/> of <see cref="PatientTreatment"/> representing the bolus treatments.
/// </returns>
/// <!-- aidoc:v1 sig=9ad10af body=3161220 -->
public async Task<List<PatientTreatment>> GetBolusTreatments(ObjectId patientId)
{
return await treatmentRepository.FindBolusTreatments(patientId);
@@ -202,6 +212,7 @@ public class TreatmentService(
/// </summary>
/// <param name="apiRequest">The inbound <see cref="ApiRequest"/> to process.</param>
/// <returns>A task that represents the asynchronous save operation.</returns>
/// <!-- aidoc:v1 sig=655d140 body=fe3d8b2 -->
public async Task SaveRequestAsync(ApiRequest apiRequest)
{
await SaveRequest(apiRequest);
@@ -221,6 +232,7 @@ public class TreatmentService(
/// The method also enforces the unit's <c>AutoAdt</c> configuration when the
/// request does not originate from a panel.
/// </remarks>
/// <!-- aidoc:v1 sig=229d8cd body=9f1cf3d -->
public async Task SaveRequest(ApiRequest apiRequest)
{
if (string.IsNullOrEmpty(apiRequest.PatientNumber))
@@ -307,6 +319,7 @@ public class TreatmentService(
/// representing the active treatments. Treatments marked as <c>Dc</c> or
/// outside their validity window are excluded.
/// </returns>
/// <!-- aidoc:v1 sig=1c9e799 body=f285c51 -->
public async Task<IEnumerable<PatientTreatment?>> GetActiveTreatmentsByPatient(ObjectId id)
{
var treatments = await treatmentRepository.GetByPatientId(id);
@@ -330,6 +343,7 @@ public class TreatmentService(
/// <param name="id">The new <see cref="ObjectId"/> value.</param>
/// <param name="oldId">The previous <see cref="ObjectId"/> value being replaced.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
/// <!-- aidoc:v1 sig=72ce1ca body=e91a5b9 -->
public async Task UpdateManyObjectId(string nameId, ObjectId id, ObjectId oldId)
{
await treatmentRepository.UpdateManyObjectId(nameId, id, oldId);
@@ -346,6 +360,7 @@ public class TreatmentService(
/// A task that represents the asynchronous operation. The task result contains
/// a <see cref="PaginationResponse{T}"/> of <see cref="PatientTreatment"/>.
/// </returns>
/// <!-- aidoc:v1 sig=e26055d body=baf1772 -->
public async Task<PaginationResponse<PatientTreatment>> GetPaginatedTreatments(PaginationFilter filter)
{
var result = treatmentRepository.GetPaginatedTreatments(filter);
@@ -371,6 +386,7 @@ public class TreatmentService(
/// A task that represents the asynchronous operation. The task result contains
/// a <see cref="List{T}"/> of <see cref="PatientTreatment"/>.
/// </returns>
/// <!-- aidoc:v1 sig=3821694 body=dbc3de2 -->
public async Task<List<PatientTreatment>> GetActiveTreatmentsByPatientIdAndOrder(ObjectId patientId, string order)
{
return await treatmentRepository.GetActiveTreatmentsByPatientIdAndOrder(patientId, order);
@@ -385,6 +401,7 @@ public class TreatmentService(
/// <exception cref="ConflictException">
/// Thrown when the treatment does not exist.
/// </exception>
/// <!-- aidoc:v1 sig=9ab6da4 body=cbff241 -->
public async Task DeleteById(ObjectId id)
{
var oldTreatment = await treatmentRepository.GetById(id) ??
@@ -407,6 +424,7 @@ public class TreatmentService(
/// If the configuration-observation service returns <see langword="null"/>,
/// the treatment is considered ignored and a debug entry is logged.
/// </remarks>
/// <!-- aidoc:v1 sig=c13749c body=e16fa1f -->
private async Task<PatientTreatment?> MapTreatment(PatientTreatment treatment)
{
var treatment2 = await calculatedObservationsService.Value.Map(treatment);
@@ -428,6 +446,7 @@ public class TreatmentService(
/// If the patient cannot be located or has no <c>PointOfCareId</c>, the
/// broadcast is skipped.
/// </remarks>
/// <!-- aidoc:v1 sig=fd42729 body=b957bc2 -->
private async Task SendBroadcast(PatientTreatment treatment, OperationType operationType)
{
var patient = await patientService.FindById(treatment.PatientId);
@@ -452,6 +471,8 @@ public class TreatmentService(
/// discontinued (<see cref="OrderControlType.Dc"/>) and the current UTC
/// time lies within its validity window; otherwise, <see langword="false"/>.
/// </returns>
/// <!-- aidoc-review:v1 severity=low kind=wrong_summary
/// "Summary describes the treatment as 'not canceled', but the code checks for OrderControlType.Dc (discontinued), which is distinct from canceled (OrderControlType.Ca) in HL7." -->
private static bool IsValidTreatment(PatientTreatment treatment)
{
if (treatment.PlacerOrder == null)
@@ -478,6 +499,7 @@ public class TreatmentService(
/// The most recent treatment whose <see cref="OrderControlType"/> is
/// <c>Nw</c> or <c>Xo</c>, or <see langword="null"/> if none qualifies.
/// </returns>
/// <!-- aidoc:v1 sig=e49781f body=fc0887d -->
private static PatientTreatment? GetMostRecentActiveTreatment(IGrouping<string?, PatientTreatment> group)
{
return group