From aec4a6c58ae5cd4c7ba1b11057913d4b772d39dd Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 11 Dec 2019 21:39:21 +1100 Subject: [PATCH] fix code system rendering --- .../java/org/hl7/fhir/r5/model/CodeSystem.java | 4 ++++ .../r5/terminologies/CodeSystemUtilities.java | 18 +++++++++++------- .../hl7/fhir/r5/utils/NarrativeGenerator.java | 2 +- .../fhir/r5/test/NarrativeGenerationTests.java | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CodeSystem.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CodeSystem.java index 039ffb8d0..5c1854484 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CodeSystem.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CodeSystem.java @@ -2080,6 +2080,10 @@ public class CodeSystem extends MetadataResource { } + @Override + public String toString() { + return getCode()+": "+getDisplay(); + } } @Block() 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 e675fdc7e..2c28ac37d 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 @@ -66,7 +66,7 @@ public class CodeSystemUtilities { private boolean hasExtraRelationships(List concept) { for (ConceptDefinitionComponent cd : concept) { - if (getSubsumedBy(cd) != null) { + if (!getSubsumedBy(cd).isEmpty()) { return true; } for (ConceptDefinitionComponent cdc : cd.getConcept()) { @@ -83,11 +83,12 @@ public class CodeSystemUtilities { if (restructure) { List res = new ArrayList<>(); for (ConceptDefinitionComponent cd : cs.getConcept()) { - if (getSubsumedBy(cd) == null) { + if (getSubsumedBy(cd).isEmpty()) { res.add(cd); processed.add(cd.getCode()); } } + System.out.println("children of (root): "+res); return res; } else { return cs.getConcept(); @@ -100,11 +101,12 @@ public class CodeSystemUtilities { processed.add(cd.getCode()); } for (ConceptDefinitionComponent cd : cs.getConcept()) { - if (context.getCode().equals(getSubsumedBy(cd)) && !processed.contains(cd.getCode())) { + if (getSubsumedBy(cd).contains(context.getCode()) && !processed.contains(cd.getCode())) { res.add(cd); processed.add(cd.getCode()); } } + System.out.println("children of "+context+": "+res); return res; } else { return context.getConcept(); @@ -112,22 +114,24 @@ public class CodeSystemUtilities { } } - private String getSubsumedBy(ConceptDefinitionComponent cd) { + private List getSubsumedBy(ConceptDefinitionComponent cd) { + List codes = new ArrayList<>(); for (ConceptPropertyComponent cp : cd.getProperty()) { if (cp.getCode().equals("subsumedBy")) { - return cp.getValue().primitiveValue(); + codes.add(cp.getValue().primitiveValue()); } } - return null; + return codes; } public List getOtherChildren(ConceptDefinitionComponent context) { List res = new ArrayList<>(); for (ConceptDefinitionComponent cd : cs.getConcept()) { - if (context.getCode().equals(getSubsumedBy(cd)) && processed.contains(cd.getCode())) { + if (getSubsumedBy(cd).contains(context.getCode()) && processed.contains(cd.getCode())) { res.add(cd); } } + System.out.println("non-children of "+context+": "+res); return res; } } 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 e9d20433f..c6b65ac51 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 @@ -2671,7 +2671,7 @@ public class NarrativeGenerator implements INarrativeGenerator { if (header) { XhtmlNode h = x.h2(); h.addText(cs.hasTitle() ? cs.getTitle() : cs.getName()); - // .... addMarkdown(x, cs.getDescription()); + addMarkdown(x, cs.getDescription()); if (cs.hasCopyright()) generateCopyright(x, cs, lang); } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java index 5f0bd4d46..9b1de5c3d 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java @@ -123,6 +123,7 @@ public class NarrativeGenerationTests { DomainResource target = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId()+"-expected.xml")); gen.generate(source); new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("narrative", test.getId()+"-actual.xml")), source); + source = (DomainResource) new XmlParser().parse(new FileInputStream(TestingUtilities.tempFile("narrative", test.getId()+"-actual.xml"))); Assert.assertTrue("Output does not match expected", source.equalsDeep(target)); }