Skip to content

Commit

Permalink
Fix ConceptMap issue caused by NON NULL requirement in combination
Browse files Browse the repository at this point in the history
with intended behavior in FHIR 4.0.1

database:
  - TerminologyDatabase:
     - Remove general non-null constraint from column target_code
       in conceptmaps table
     - Add constraint to conceptmaps table to allow for null values
       in target_code column only if equivalence is 'unmatched'
     - Remove translations with equivalence of 'unmatched' from
       query result when calling $translate
  • Loading branch information
pbehrend committed Aug 26, 2024
1 parent 80836b0 commit 6a8704f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ logging.log
!/database/.gitkeep

/.commit
/.kotlin/
/index/
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ class TerminologyDatabase constructor(private val ctx: FhirContext, url: String)
logger.debug("Creating Translation table ...")
super.execute("CREATE TABLE IF NOT EXISTS Translation (CM_ID BIGINT REFERENCES ConceptMaps, " +
"CODE TEXT NOT NULL, DISPLAY TEXT NOT NULL, SOURCE_URL TEXT NOT NULL, SOURCE_VERSION TEXT, " +
"TARGET_URL TEXT NOT NULL, TARGET_VERSION TEXT, TARGET_CODE TEXT NOT NULL, TARGET_DISPLAY TEXT, " +
"EQUIVALENCE TEXT NOT NULL, COMMENT TEXT, DEPENDS_ON JSONB)")
"TARGET_URL TEXT NOT NULL, TARGET_VERSION TEXT, TARGET_CODE TEXT, TARGET_DISPLAY TEXT, " +
"EQUIVALENCE TEXT NOT NULL, COMMENT TEXT, DEPENDS_ON JSONB, " +
"CONSTRAINT unmatched CHECK ((EQUIVALENCE = 'unmatched') != (TARGET_CODE IS NOT NULL)))")
logger.debug("Creating Translation index ...")
super.execute("CREATE INDEX IF NOT EXISTS Idx_Translation ON Translation(CM_ID, CODE, SOURCE_URL, CODE, " +
"SOURCE_VERSION, TARGET_URL, TARGET_VERSION, TARGET_CODE, EQUIVALENCE)")
Expand Down Expand Up @@ -662,8 +663,9 @@ class TerminologyDatabase constructor(private val ctx: FhirContext, url: String)
val rs = super.executeQuery(query, params)
val results = mutableListOf<Pair<ConceptMapEquivalence, Coding>>()
while (rs.next()) {
val targetCoding = Coding(targetSystem, rs.getString(1), rs.getString(2))
val equivalence = ConceptMapEquivalence.fromCode(rs.getString(3))
if (equivalence == ConceptMapEquivalence.UNMATCHED) continue
val targetCoding = Coding(targetSystem, rs.getString(1), rs.getString(2))
results.add(Pair(equivalence, targetCoding))
}
return results
Expand Down

0 comments on commit 6a8704f

Please sign in to comment.