From 6f4c038f48f66211b5c767f4490c47bdc839f864 Mon Sep 17 00:00:00 2001 From: JessicaWNava <119880261+JessicaWNava@users.noreply.github.com> Date: Tue, 10 Sep 2024 17:18:26 -0400 Subject: [PATCH] Engagement/jessica/15541 cli add code to condition (#15803) * Added code to condition to the fhirdata cli tool --- .../main/kotlin/cli/ProcessFhirCommands.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/prime-router/src/main/kotlin/cli/ProcessFhirCommands.kt b/prime-router/src/main/kotlin/cli/ProcessFhirCommands.kt index 790e4303c74..bcb35b27903 100644 --- a/prime-router/src/main/kotlin/cli/ProcessFhirCommands.kt +++ b/prime-router/src/main/kotlin/cli/ProcessFhirCommands.kt @@ -18,8 +18,11 @@ import fhirengine.engine.CustomFhirPathFunctions import fhirengine.engine.CustomTranslationFunctions import gov.cdc.prime.router.ActionLogger import gov.cdc.prime.router.Hl7Configuration +import gov.cdc.prime.router.Metadata import gov.cdc.prime.router.MimeFormat import gov.cdc.prime.router.azure.BlobAccess +import gov.cdc.prime.router.azure.ConditionStamper +import gov.cdc.prime.router.azure.LookupTableConditionMapper import gov.cdc.prime.router.cli.helpers.HL7DiffHelper import gov.cdc.prime.router.common.Environment import gov.cdc.prime.router.common.JacksonMapperUtilities @@ -33,6 +36,7 @@ import gov.cdc.prime.router.fhirengine.translation.hl7.utils.CustomContext import gov.cdc.prime.router.fhirengine.translation.hl7.utils.FhirPathUtils import gov.cdc.prime.router.fhirengine.utils.FhirTranscoder import gov.cdc.prime.router.fhirengine.utils.HL7Reader +import gov.cdc.prime.router.fhirengine.utils.getObservations import org.hl7.fhir.r4.model.Base import org.hl7.fhir.r4.model.Bundle import org.hl7.fhir.r4.model.Extension @@ -155,6 +159,10 @@ class ProcessFhirCommands : CliktCommand( else -> { val bundle = applySenderTransforms(fhirMessage) + val stamper = ConditionStamper(LookupTableConditionMapper(Metadata.getInstance())) + fhirMessage.getObservations().forEach { observation -> + stamper.stampObservation(observation) + } FhirToHl7Converter( receiverSchema!!, BlobAccess.BlobContainerMetadata.build("metadata", Environment.get().storageEnvVar), @@ -183,6 +191,10 @@ class ProcessFhirCommands : CliktCommand( */ private fun convertFhirToFhir(jsonString: String): Bundle { var fhirMessage = FhirTranscoder.decode(jsonString) + val stamper = ConditionStamper(LookupTableConditionMapper(Metadata.getInstance())) + fhirMessage.getObservations().forEach { observation -> + stamper.stampObservation(observation) + } fhirMessage = applyEnrichmentSchemas(fhirMessage) if (receiverSchema == null && senderSchema == null) { // Must have at least one schema or else why are you doing this @@ -220,10 +232,17 @@ class ProcessFhirCommands : CliktCommand( } val hl7profile = HL7Reader.getMessageProfile(hl7message.toString()) // search hl7 profile map and create translator with config path if found - return when (val configPath = HL7Reader.profileDirectoryMap[hl7profile]) { - null -> Pair(HL7toFhirTranslator(inputSchema).translate(hl7message), hl7message) - else -> Pair(HL7toFhirTranslator(configPath).translate(hl7message), hl7message) + val fhirMessage = when (val configPath = HL7Reader.profileDirectoryMap[hl7profile]) { + null -> HL7toFhirTranslator(inputSchema).translate(hl7message) + else -> HL7toFhirTranslator(configPath).translate(hl7message) } + + val stamper = ConditionStamper(LookupTableConditionMapper(Metadata.getInstance())) + fhirMessage.getObservations().forEach { observation -> + stamper.stampObservation(observation) + } + + return Pair(fhirMessage, hl7message) } /**