Skip to content

Commit

Permalink
adding back the unmapped codes
Browse files Browse the repository at this point in the history
  • Loading branch information
kant committed Jan 13, 2025
1 parent 2ae5856 commit c6460a1
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions prime-router/src/main/kotlin/azure/ConditionMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,51 @@ class ConditionStamper(private val conditionMapper: IConditionMapper) {
val memberOidMap = conditionMapper.lookupMemberOid(codeSourcesMap.values.flatten())

var mappedSomething = false
val failures = mutableListOf<ObservationMappingFailure>()

codeSourcesMap.forEach { (key, codings) ->
// keep track of codes that have no mapped conditions
val unmappedCodings = mutableListOf<Coding>()

codeSourcesMap.forEach { (_, codings) ->
codings.forEach { originalCoding ->
val mappedConditions = conditionsToCode[originalCoding].orEmpty()
mappedConditions.forEach { conditionCoding ->
val snomedCoding = Coding().apply {
system = conditionCoding.system
code = conditionCoding.code
display = conditionCoding.display
}
// If we have an OID, add it as a sub-extension on this SNOMED coding
memberOidMap[conditionCoding.code]?.let { memberOid ->
val memberOidExtension = Extension(MEMBER_OID_EXTENSION_URL).apply {
setValue(StringType(memberOid))
if (mappedConditions.isEmpty()) {
// No mapped conditions => unmapped
unmappedCodings.add(originalCoding)
} else {
// We do have mapped conditions => build all the SNOMED codings
mappedConditions.forEach { conditionCoding ->
val snomedCoding = Coding().apply {
system = conditionCoding.system
code = conditionCoding.code
display = conditionCoding.display
}

// If we have an OID for this code, add as sub-extension
memberOidMap[conditionCoding.code]?.let { memberOid ->
val memberOidExtension = Extension(MEMBER_OID_EXTENSION_URL).apply {
setValue(StringType(memberOid))
}
snomedCoding.addExtension(memberOidExtension)
}
snomedCoding.addExtension(memberOidExtension)
}
// Create the top-level condition-code extension
val conditionExtension = Extension(CONDITION_CODE_EXTENSION_URL, snomedCoding)
observation.code.coding
.firstOrNull()
?.addExtension(conditionExtension)

mappedSomething = true
// Create the top-level condition-code extension
val conditionExtension = Extension(CONDITION_CODE_EXTENSION_URL, snomedCoding)
observation.code
.coding
.firstOrNull()
?.addExtension(conditionExtension)

mappedSomething = true
}
}
}
}

return ObservationStampingResult(mappedSomething)
// If there's any unmapped codes for this key, record them
if (unmappedCodings.isNotEmpty()) {
failures.add(ObservationMappingFailure(key, unmappedCodings))
}
}
return ObservationStampingResult(mappedSomething, failures)
}
}

0 comments on commit c6460a1

Please sign in to comment.