Skip to content

Commit

Permalink
Merge pull request #174 from LinuxForHealth/Issue#173-Version-and-Alt…
Browse files Browse the repository at this point in the history
…ernate-coding-support

Issue #173 CWE Version & Alternate Coding support
  • Loading branch information
cragun47 authored Aug 23, 2021
2 parents 9facbb2 + 9955088 commit 93a6594
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@ public class SimpleCode {
private String system;
private String code;
private String display;
private String version;

/**
* Returns simple representation of Code.
*
* @param code
* @param system
* @param display
* @param version
*/

public SimpleCode(String code, String system, String display) {
this.code = code;
this.system = system;
this.display = display;
this.version = null;
}

public SimpleCode(String code, String system, String display, String version) {
this.code = code;
this.system = system;
this.display = display;
this.version = version;
}

public String getSystem() {
Expand All @@ -36,12 +46,18 @@ public String getCode() {
return code;
}



public String getDisplay() {
return display;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String toString() {
return ReflectionToStringBuilder.toString(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ public static String getOriginalDisplayText(Object obj) {
return null;
}

public static String getVersion(Object obj) {
if (obj instanceof CWE) {
CWE id = (CWE) obj;
ST st = id.getCodingSystemVersionID();
if (st != null) {
String str = st.getValue();
if (str != null) {
return str.trim();
}
return null;
}
return null;
}
return null;
}

private static String getAssociatedtable(CWE id) {
ID val = id.getCwe3_NameOfCodingSystem();
if (val != null && StringUtils.startsWith(val.getValue(), "HL7")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum SimpleDataTypeMapper {
NAMED_UUID(SimpleDataValueResolver.NAMED_UUID),
OBJECT(SimpleDataValueResolver.OBJECT),
CODING_SYSTEM_V2(SimpleDataValueResolver.CODING_SYSTEM_V2),
CODING_SYSTEM_V2_ALTERNATE(SimpleDataValueResolver.CODING_SYSTEM_V2_ALTERNATE),
SYSTEM_URL(SimpleDataValueResolver.SYSTEM_URL),
SYSTEM_ID(SimpleDataValueResolver.SYSTEM_ID),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,28 @@ public class SimpleDataValueResolver {
return value;
};

public static final ValueExtractor<Object, SimpleCode> CODING_SYSTEM_V2_ALTERNATE = (Object value) -> {
// ensure we have a CWE
if (value instanceof CWE) {
CWE cwe = (CWE) value;
String table = Hl7DataHandlerUtil.getStringValue(cwe.getCwe6_NameOfAlternateCodingSystem());
String code = Hl7DataHandlerUtil.getStringValue(cwe.getCwe4_AlternateIdentifier());
String text = Hl7DataHandlerUtil.getStringValue(cwe.getCwe5_AlternateText());
String version = Hl7DataHandlerUtil.getStringValue(cwe.getCwe8_AlternateCodingSystemVersionID());
return commonCodingSystemV2(table, code, text, version);
}
return null;
};

public static final ValueExtractor<Object, SimpleCode> CODING_SYSTEM_V2 = (Object value) -> {
String table = Hl7DataHandlerUtil.getTableNumber(value);
String code = Hl7DataHandlerUtil.getStringValue(value);
String text = Hl7DataHandlerUtil.getOriginalDisplayText(value);
String version = Hl7DataHandlerUtil.getVersion(value);
return commonCodingSystemV2(table, code, text, version);
};

private static final SimpleCode commonCodingSystemV2 (String table, String code, String text, String version) {
if (table != null && code != null) {
// Found table and a code. Try looking it up.
SimpleCode coding = TerminologyLookup.lookup(table, code);
Expand All @@ -265,8 +283,9 @@ public class SimpleDataValueResolver {

if (display.isEmpty()) {
// We have a table, code, but unknown display, so we can't tell if it's good, use the original display text
coding = new SimpleCode(coding.getCode(), coding.getSystem(), text);
coding = new SimpleCode(coding.getCode(), coding.getSystem(), text, version);
}
coding.setVersion(version);
// We have a table, code, and display, so code was valid
return coding;
} else {
Expand All @@ -276,15 +295,15 @@ public class SimpleDataValueResolver {
}
} else {
// No success looking up the code, build our own fall-back system using table name
return new SimpleCode(code, "urn:id:"+table, text) ;
return new SimpleCode(code, "urn:id:"+table, text, version) ;
}
} else if (code != null) {
// A code but no system: build a simple systemless code
return new SimpleCode(code, null, null);
} else {
return null;
}
};
}

public static final ValueExtractor<Object, String> BUILD_IDENTIFIER_FROM_CWE = (Object value) -> {
CWE newValue = ((CWE) value);
Expand Down
15 changes: 6 additions & 9 deletions src/main/resources/hl7/datatype/CodeableConcept.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ coding_2:
vars:
code: ID |IS |TX

# Generalized CWE for alternate codes handles mismatched systems and codes
coding_3:
valueOf: datatype/Coding
valueOf: $coding
generateList: true
expressionType: resource
condition: $code NOT_NULL && $coding NULL
condition: $coding NOT_NULL
specs: CWE
vars:
code: CWE.4
system: CWE.6
display: CWE.5
version: CWE.8
coding: CODING_SYSTEM_V2_ALTERNATE, CWE

# Generalized CWE through CODING_SYSTEM_V2 handles mismatched systems and codes
coding_4:
Expand All @@ -52,6 +49,8 @@ coding_5:
condition: $coding NOT_NULL
generateList: true

# If hideText is not passed by parent, the value is NULL, making it backward compatible with all other uses of CodeableConcept
# Any value in hideText will cause the text to be hidden. Used by Identifier_SystemID.
text:
condition: $hideText NULL && $displayText NOT_NULL
type: STRING
Expand All @@ -62,5 +61,3 @@ text:
# ----------------
# Orphan comments:
# ----------------
# Was at begin of line:56 :# If hideText is not passed by parent, the value is NULL, making it backward compatible with all other uses of CodeableConcept
# Was at begin of line:57 :# Any value in hideText will cause the text to be hidden. Used by Identifier_SystemID.
4 changes: 1 addition & 3 deletions src/main/resources/hl7/resource/Patient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ extension:
valueCodeableConcept:
valueOf: datatype/CodeableConcept
expressionType: resource
condition: $coding NOT_NULL
vars:
coding: CODING_SYSTEM_V2, CWE
specs: CWE

communication:
condition: $language NOT_NULL
Expand Down
Loading

0 comments on commit 93a6594

Please sign in to comment.