Skip to content

Commit

Permalink
Merge pull request #1434 from synthetichealth/code_versions
Browse files Browse the repository at this point in the history
Add support for code system versions
  • Loading branch information
jawalonoski authored Mar 21, 2024
2 parents 6fa1b4b + b9f8395 commit 94ca67d
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/mitre/synthea/export/FhirDstu2.java
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,7 @@ private static CodeableConceptDt mapCodeToCodeableConcept(Code from, String syst
} else {
coding.setSystem(from.system);
}
coding.setVersion(from.version); // may be null

to.addCoding(coding);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/mitre/synthea/export/FhirR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,7 @@ private static CodeableConcept mapCodeToCodeableConcept(Code from, String system
} else {
coding.setSystem(from.system);
}
coding.setVersion(from.version); // may be null

to.addCoding(coding);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/mitre/synthea/export/FhirStu3.java
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,7 @@ private static CodeableConcept mapCodeToCodeableConcept(Code from, String system
} else {
coding.setSystem(from.system);
}
coding.setVersion(from.version); // may be null

to.addCoding(coding);

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/mitre/synthea/world/concepts/HealthRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public boolean equals(Object obj) {
public String code;
/** The human-readable description of the code. */
public String display;
/** An identifier for the version of the code system that this code is part of. */
public String version;
/**
* A ValueSet URI that defines a set of possible codes, one of which should be selected at
* random.
Expand Down Expand Up @@ -116,9 +118,13 @@ public Code(JsonObject definition) {
this.display = definition.get("display").getAsString();
}

/**
* {@inheritDoc}
*/
public String toString() {
return String
.format("system=%s, code=%s, display=%s, valueSet=%s", system, code, display, valueSet);
return String.format(
"system=%s, code=%s, display=%s, version=%s, valueSet=%s",
system, code, display, version, valueSet);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/main/javascript/update_code_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function inventoryCode(codeObj) {

function buildDictionary() {
for (const codeObj of allCodes) {
let { system, code, display } = codeObj;
let { system, code, display, version } = codeObj;
code = code.toString();
if (!codeDictionary[system]) {
codeDictionary[system] = {};
Expand All @@ -163,8 +163,10 @@ function buildDictionary() {
console.log(`Unexpected code system ${system} may not be supported by tx.fhir.org`);
}
// http://hl7.org/fhir/R4/terminology-service.html#validation
const requestUrl = `http://tx.fhir.org/r4/CodeSystem/$validate-code?system=${systemUri}&code=${code}&display=${display}`

let requestUrl = `http://tx.fhir.org/r4/CodeSystem/$validate-code?system=${systemUri}&code=${code}&display=${display}`
if (version) {
requestUrl += `&version=${version}`
}
const res = fetch(requestUrl, { headers: { "Accept": "application/fhir+json" } }).json();

const displayParam = res.parameter.find(p => p.name === 'display');
Expand Down Expand Up @@ -195,7 +197,7 @@ function selectBestCode(system, inventory, aPreferredDisplay, currentDisplay) {
for (const option of inventory) {
// if we already use the preferred display with a snomed semantic tag, use that.
// some codes aren't regex safe
const regexSafeDisplay = display.replaceAll('+', '\\+').replaceAll('(', '\\(').replaceAll(')', '\\)');
const regexSafeDisplay = aPreferredDisplay.replaceAll('+', '\\+').replaceAll('(', '\\(').replaceAll(')', '\\)');
if (option.match(new RegExp(`^${regexSafeDisplay} \\([a-z\\+/ ]+\\)$`, 'i'))) {
return option;
}
Expand Down Expand Up @@ -255,7 +257,7 @@ function handleErrorOrExit(requestUrl, res) {
const message = messageParam.valueString;

if (message.startsWith("Unable to find code ")
|| message.startsWith("Unknown Code '")) {
|| message.startsWith("Unknown code '")) {
console.log(message);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
{
"system": "SNOMED-CT",
"code": 454711000124102,
"display": "Depression screening using Patient Health Questionnaire Two-Item score (procedure)"
"display": "Depression screening using Patient Health Questionnaire Two-Item score (procedure)",
"version": "http://snomed.info/sct/731000124108"
}
],
"distribution": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/modules/encounter/sdoh_hrsn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@
"system": "SNOMED-CT",
"code": 5251000175109,
"display": "Received certificate of high school equivalency (finding)",
"value_set": ""
"version": "http://snomed.info/sct/731000124108"
}
],
"direct_transition": "Q11",
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/modules/heart/avrr/outcomes.json
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@
"codes": [
{
"system": "SNOMED-CT",
"code": 457551000124104,
"display": "Acute cerebrovascular accident (disorder)"
"code": "230690007",
"display": "Cerebrovascular accident (disorder)"
}
],
"direct_transition": "End Stroke"
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/modules/heart/avrr/sequence.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
{
"system": "SNOMED-CT",
"code": 452331000124102,
"display": "Review of imaging finding (procedure)"
"display": "Review of imaging finding (procedure)",
"version": "http://snomed.info/sct/731000124108"
}
],
"distribution": {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/modules/heart/cabg/outcomes.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,8 @@
"codes": [
{
"system": "SNOMED-CT",
"code": 457551000124104,
"display": "Acute cerebrovascular accident (disorder)"
"code": "230690007",
"display": "Cerebrovascular accident (disorder)"
}
],
"target_encounter": "CABG_Postop",
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/modules/heart/tavr/outcomes.json
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@
"codes": [
{
"system": "SNOMED-CT",
"code": 457551000124104,
"display": "Acute cerebrovascular accident (disorder)"
"code": "230690007",
"display": "Cerebrovascular accident (disorder)"
}
],
"direct_transition": "End Stroke"
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/modules/injuries.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,6 @@
}
],
"activities": [
{
"system": "SNOMED-CT",
"code": "231181000000100",
"display": "Delivery of rehabilitation for spinal cord injury"
},
{
"system": "SNOMED-CT",
"code": "77476009",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/modules/self_harm.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
"activities": [
{
"system": "SNOMED-CT",
"code": "784051000000106",
"code": "768835002",
"display": "Depression care management"
},
{
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/modules/snf/skilled_nursing_facility.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
{
"system": "SNOMED-CT",
"code": "449411000124106",
"display": "Admission to skilled nursing facility (procedure)"
"display": "Admission to skilled nursing facility (procedure)",
"version": "http://snomed.info/sct/731000124108"
}
],
"conditional_transition": [
Expand Down Expand Up @@ -298,7 +299,8 @@
{
"system": "SNOMED-CT",
"code": "449381000124108",
"display": "Discharge from skilled nursing facility (procedure)"
"display": "Discharge from skilled nursing facility (procedure)",
"version": "http://snomed.info/sct/731000124108"
}
],
"direct_transition": "Return_Wheelchair"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/modules/veteran_self_harm.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"activities": [
{
"system": "SNOMED-CT",
"code": "784051000000106",
"code": "768835002",
"display": "Depression care management"
},
{
Expand Down

0 comments on commit 94ca67d

Please sign in to comment.