feature: Backend as Single Source of Truth for Batch-Type Field Requirements

This commit is contained in:
voltsrage
2026-06-27 23:47:56 +08:00
parent 4c28bffcc9
commit 5039dbb979
10 changed files with 245 additions and 44 deletions
@@ -7,6 +7,7 @@ public record BatchDetailResponse(
string Status,
string BatchType,
string Track,
BatchTypeFieldRequirements FieldRequirements,
Guid? PatientId,
string DocumentRef,
string? DocumentUrl,
@@ -34,6 +35,7 @@ public record BatchDetailResponse(
batch.Status.ToDbString(),
batch.BatchType.ToDbString(),
batch.Track.ToDbString(),
BatchTypeFieldRequirements.ForBatchType(batch.BatchType),
batch.PatientId,
batch.DocumentRef,
documentUrl,
@@ -0,0 +1,70 @@
public record BatchTypeFieldRequirements(
bool ShowPatientDemographics,
bool ShowEncounterContext,
bool ShowEncounterSummaryFields,
bool ShowObservations,
bool ShowAllergies,
bool ShowMedications
)
{
public static BatchTypeFieldRequirements ForBatchType(BatchType batchType) => batchType switch
{
BatchType.PatientRegistration => new(
ShowPatientDemographics: true,
ShowEncounterContext: false,
ShowEncounterSummaryFields: false,
ShowObservations: false,
ShowAllergies: false,
ShowMedications: false),
BatchType.VitalsSheet => new(
ShowPatientDemographics: true,
ShowEncounterContext: true,
ShowEncounterSummaryFields: false,
ShowObservations: true,
ShowAllergies: false,
ShowMedications: false),
BatchType.LabResults => new(
ShowPatientDemographics: true,
ShowEncounterContext: true,
ShowEncounterSummaryFields: false,
ShowObservations: true,
ShowAllergies: false,
ShowMedications: false),
BatchType.AllergyUpdate => new(
ShowPatientDemographics: true,
ShowEncounterContext: false,
ShowEncounterSummaryFields: false,
ShowObservations: false,
ShowAllergies: true,
ShowMedications: false),
BatchType.EncounterSummary => new(
ShowPatientDemographics: true,
ShowEncounterContext: true,
ShowEncounterSummaryFields: true,
ShowObservations: false,
ShowAllergies: false,
ShowMedications: false),
BatchType.MedicationList => new(
ShowPatientDemographics: true,
ShowEncounterContext: false,
ShowEncounterSummaryFields: false,
ShowObservations: false,
ShowAllergies: false,
ShowMedications: true),
BatchType.Mixed => new(
ShowPatientDemographics: true,
ShowEncounterContext: true,
ShowEncounterSummaryFields: true,
ShowObservations: true,
ShowAllergies: true,
ShowMedications: true),
_ => throw new ArgumentOutOfRangeException(nameof(batchType))
};
}
@@ -2,6 +2,7 @@ public record DraftPayloadResponse(
Guid BatchId,
string Status,
string BatchType,
BatchTypeFieldRequirements FieldRequirements,
DraftPatientDto? Patient,
DraftEncounterDto? Encounter,
List<DraftObservationDto> Observations
@@ -35,6 +35,7 @@ public class DraftService : IDraftService
batch.Id,
batch.Status.ToDbString(),
batch.BatchType.ToDbString(),
BatchTypeFieldRequirements.ForBatchType(batch.BatchType),
batch.DraftPatient is not null ? MapPatient(batch.DraftPatient) : null,
batch.DraftEncounter is not null ? MapEncounter(batch.DraftEncounter) : null,
batch.DraftObservations.Select(MapObservation).OrderBy(o => o.RecordedAt).ToList()