Skip to content

Commit

Permalink
Support inline value sets in UP Sender Transform schema
Browse files Browse the repository at this point in the history
- Require that the value FHIR expression evaluate prior to performing a valueset transform
- Change the valueset value to be parsed as a string rather than a FHIRPath expression
- Ensure the original untransformed value is preserved if a valueset key is not matched
- Added unit testing for valueset
- Reorganized unit tests and adjusted existing tests to match expected behavior
- ktLint formatting updates unrelated to this story
  • Loading branch information
jack-h-wang committed Mar 30, 2023
1 parent 8a3f79a commit 3320f2c
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import gov.cdc.prime.router.fhirengine.translation.hl7.utils.FhirPathUtils
import org.apache.logging.log4j.kotlin.Logging
import org.hl7.fhir.r4.model.Base
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.StringType

abstract class ConfigSchemaProcessor : Logging {

Expand Down Expand Up @@ -40,7 +41,7 @@ abstract class ConfigSchemaProcessor : Logging {

// when valueSet is available, use the matching value else just pass the value as is
// does a lowerCase comparison
if (element.valueSet.isNotEmpty()) {
if (retVal.isNotBlank() && element.valueSet.isNotEmpty()) {
val lowerSet = element.valueSet.mapKeys { it.key.lowercase() }
retVal = lowerSet.getOrDefault(retVal.lowercase(), retVal)
}
Expand Down Expand Up @@ -71,15 +72,15 @@ abstract class ConfigSchemaProcessor : Logging {
}
}

// when valueSet is available, use the matching value else just pass the value as is
// when valueSet is available, return mapped value or null if match isn't found
// does a lowerCase comparison
if (element.valueSet.isNotEmpty()) {
if (retVal != null && element.valueSet.isNotEmpty()) {
val lowerSet = element.valueSet.mapKeys { it.key.lowercase() }
val valStr = lowerSet[retVal?.primitiveValue()?.lowercase() ?: ""]
if (valStr != null) {
val value = FhirPathUtils.evaluate(context, focusResource, bundle, valStr)
if (value.isNotEmpty())
retVal = value[0]
retVal = if (valStr != null) {
StringType(valStr)
} else {
null
}
}
return retVal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ abstract class ConfigSchemaElement(
addError("Value property is required when using a value set")
}

// value set keys and values cannot be null
if (valueSet.keys.any { it == null } || valueSet.values.any { it == null }) {
addError("Value sets cannot contain null values")
}

if (!schema.isNullOrBlank() && schemaRef == null) {
addError("Missing schema reference for '$schema'")
}
Expand Down

This file was deleted.

0 comments on commit 3320f2c

Please sign in to comment.