diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java index 7120e1cd7..7db44a8bb 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java @@ -372,4 +372,48 @@ public class CodeSystemUtilities { return false; } + public static boolean hasCode(CodeSystem cs, String code) { + for (ConceptDefinitionComponent cc : cs.getConcept()) { + if (hasCode(cc, code)) { + return true; + } + } + return false; + } + + private static boolean hasCode(ConceptDefinitionComponent cc, String code) { + if (code.equals(cc.getCode())) { + return true; + } + for (ConceptDefinitionComponent c : cc.getConcept()) { + if (hasCode(c, code)) { + return true; + } + } + return false; + } + + public static ConceptDefinitionComponent getCode(CodeSystem cs, String code) { + for (ConceptDefinitionComponent cc : cs.getConcept()) { + ConceptDefinitionComponent cd = getCode(cc, code); + if (cd != null) { + return cd; + } + } + return null; + } + + private static ConceptDefinitionComponent getCode(ConceptDefinitionComponent cc, String code) { + if (code.equals(cc.getCode())) { + return cc; + } + for (ConceptDefinitionComponent c : cc.getConcept()) { + ConceptDefinitionComponent cd = getCode(c, code); + if (cd != null) { + return cd; + } + } + return null; + } + } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NarrativeGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NarrativeGenerator.java index 93e2f0a44..61f29a595 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NarrativeGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NarrativeGenerator.java @@ -2935,19 +2935,44 @@ public class NarrativeGenerator implements INarrativeGenerator { return true; } String uri = cp.getUri(); + String code = null; if (Utilities.noString(uri)){ return false; } if (uri.contains("#")) { + code = uri.substring(uri.indexOf("#")+1); uri = uri.substring(0, uri.indexOf("#")); } - return - Utilities.existsInList(uri, "http://hl7.org/fhir/concept-properties") || - codeSystemPropList.contains(uri); + if (Utilities.existsInList(uri, "http://hl7.org/fhir/concept-properties") || codeSystemPropList.contains(uri)) { + return true; + }; + CodeSystem cs = context.fetchCodeSystem(uri); + if (cs == null) { + return false; + } + return CodeSystemUtilities.hasCode(cs, code); } return false; } + private String getDisplayForProperty(String uri) { + if (Utilities.noString(uri)){ + return null; + } + String code = null; + if (uri.contains("#")) { + code = uri.substring(uri.indexOf("#")+1); + uri = uri.substring(0, uri.indexOf("#")); + } + CodeSystem cs = context.fetchCodeSystem(uri); + if (cs == null) { + return null; + } + ConceptDefinitionComponent cc = CodeSystemUtilities.getCode(cs, code); + return cc == null ? null : cc.getDisplay(); + } + + private int countConcepts(List list) { int count = list.size(); for (ConceptDefinitionComponent c : list) @@ -3475,7 +3500,14 @@ public class NarrativeGenerator implements INarrativeGenerator { tr.td().b().tx(context.translator().translate("xhtml-gen-cs", "Version", lang)); if (properties != null) { for (PropertyComponent pc : properties) { - tr.td().b().tx(context.translator().translate("xhtml-gen-cs", ToolingExtensions.getPresentation(pc, pc.getCodeElement()), lang)); + String display = ToolingExtensions.getPresentation(pc, pc.getCodeElement()); + if (display == null || display.equals(pc.getCode()) && pc.hasUri()) { + display = getDisplayForProperty(pc.getUri()); + if (display == null) { + display = pc.getCode(); + } + } + tr.td().b().tx(context.translator().translate("xhtml-gen-cs", display, lang)); } } return tr;