Skip to content

Commit

Permalink
Engagement/jessica/15541 cli add code to condition (#15803)
Browse files Browse the repository at this point in the history
* Added code to condition to the fhirdata cli tool
  • Loading branch information
JessicaWNava authored Sep 10, 2024
1 parent 93c0b4f commit 6f4c038
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions prime-router/src/main/kotlin/cli/ProcessFhirCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit 6f4c038

Please sign in to comment.