Merge pull request #747 from hapifhir/gg-202202-rendering

Gg 202202 rendering
This commit is contained in:
Grahame Grieve 2022-02-19 22:43:29 +11:00 committed by GitHub
commit 356dadd7d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 136 additions and 16 deletions

View File

@ -0,0 +1,105 @@
package org.hl7.fhir.convertors.misc.utg;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r4.formats.IParser;
import org.hl7.fhir.r4.formats.IParser.OutputStyle;
import org.hl7.fhir.r4.formats.JsonParser;
import org.hl7.fhir.r4.formats.XmlParser;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode;
import org.hl7.fhir.r4.model.Period;
import org.hl7.fhir.r4.model.Provenance;
import org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.utilities.Utilities;
public class UTGCaseSensitivePopulator {
public static void main(String[] args) throws FileNotFoundException, IOException {
new UTGCaseSensitivePopulator().process(new File(args[0]));
}
private void process(File root) throws FileNotFoundException, IOException {
Bundle bundle = new Bundle();
bundle.setType(BundleType.COLLECTION);
bundle.setId("hxutg1-1-0-12");
scanFolders(root, bundle);
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(root.getAbsolutePath(), "input", "sourceOfTruth", "history", "utgrel1hx-1-0-12.json")), bundle);
System.out.println("Done");
}
private void scanFolders(File folder, Bundle bundle) throws FileNotFoundException, IOException {
Calendar today = Calendar.getInstance();
Date dt = today.getTime();
today.set(Calendar.HOUR_OF_DAY, 0);
Date d = today.getTime();
System.out.println("Scan "+folder.getAbsolutePath());
for (File f : folder.listFiles()) {
if (f.isDirectory() && !f.getName().equals("retired")) {
scanFolders(f, bundle);
} else if (f.getName().endsWith(".xml")) {
processFile(f, bundle, new XmlParser(), d, dt);
} else if (f.getName().endsWith(".json")) {
processFile(f, bundle, new JsonParser(), d, dt);
}
}
}
private void processFile(File f, Bundle bundle, IParser parser, Date d, Date dt) {
try {
Resource r = parser.parse(new FileInputStream(f));
if (r instanceof CodeSystem) {
if (processCodeSystem((CodeSystem) r, bundle, d, dt)) {
parser.setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f), r);
}
}
} catch (Exception e) {
}
}
private boolean processCodeSystem(CodeSystem cs, Bundle bundle, Date d, Date dt) {
if (cs.hasCaseSensitive()) {
return false;
}
if (!cs.getUrl().startsWith("http://terminology.hl7.org") || cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
return false;
}
cs.setCaseSensitive(true);
Provenance p = new Provenance();
p.setId("cs-286-"+cs.getId());
p.addTarget().setReference("CodeSystem/"+cs.getId());
p.setOccurred(new Period());
p.getOccurredPeriod().setEnd(d);
p.setRecorded(dt);
p.addReason().setText("Populate Missing caseSensitive property;UP-286").addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-ActReason").setCode("METAMGT");
p.getActivity().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-DataOperation").setCode("UPDATE");
ProvenanceAgentComponent agent = p.addAgent();
agent.getType().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/provenance-participant-type").setCode("author");
agent.getWho().setDisplay("Grahame Grieve");
agent = p.addAgent();
agent.getType().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/provenance-participant-type").setCode("custodian");
agent.getWho().setDisplay("Vocabulary WG");
bundle.addEntry().setFullUrl("http://terminology.hl7.org/fhir/Provenance/cs-286-"+cs.getId()).setResource(p);
return true;
}
}

View File

@ -553,8 +553,18 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
public List<ElementDefinition> getChildList(StructureDefinition structure, ElementDefinition element) { public List<ElementDefinition> getChildList(StructureDefinition structure, ElementDefinition element) {
if (element.hasContentReference()) {
ElementDefinition target = element;
for (ElementDefinition t : structure.getSnapshot().getElement()) {
if (t.getId().equals(element.getContentReference().substring(1))) {
target = t;
}
}
return getChildList(structure, target.getPath(), target.getId(), false);
} else {
return getChildList(structure, element.getPath(), element.getId(), false); return getChildList(structure, element.getPath(), element.getId(), false);
} }
}
public void updateMaps(StructureDefinition base, StructureDefinition derived) throws DefinitionException { public void updateMaps(StructureDefinition base, StructureDefinition derived) throws DefinitionException {
if (base == null) if (base == null)
@ -2524,10 +2534,10 @@ public class ProfileUtilities extends TranslatingUtilities {
// re-enabled 11-Feb 2022 GDG - we do want to do this. At least, $assemble in davinci-dtr, where the markdown comes from the SDC IG, and an SDC local reference must be changed to point to SDC. in this case, it's called when generating snapshots // re-enabled 11-Feb 2022 GDG - we do want to do this. At least, $assemble in davinci-dtr, where the markdown comes from the SDC IG, and an SDC local reference must be changed to point to SDC. in this case, it's called when generating snapshots
// added processRelatives parameter to deal with this (well, to try) // added processRelatives parameter to deal with this (well, to try)
if (processRelatives && webUrl != null) { if (processRelatives && webUrl != null) {
System.out.println("Making "+url+" relative to '"+webUrl+"'"); // System.out.println("Making "+url+" relative to '"+webUrl+"'");
b.append(webUrl); b.append(webUrl);
} else { } else {
System.out.println("Not making "+url+" relative to '"+webUrl+"'"); // System.out.println("Not making "+url+" relative to '"+webUrl+"'");
} }
i = i + 1; i = i + 1;
} }
@ -3680,7 +3690,7 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
private String codeForAggregation(AggregationMode a) { public static String codeForAggregation(AggregationMode a) {
switch (a) { switch (a) {
case BUNDLED : return "b"; case BUNDLED : return "b";
case CONTAINED : return "c"; case CONTAINED : return "c";
@ -3689,7 +3699,7 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
} }
private String hintForAggregation(AggregationMode a) { public static String hintForAggregation(AggregationMode a) {
if (a != null) if (a != null)
return a.getDefinition(); return a.getDefinition();
else else

View File

@ -104,7 +104,7 @@ public class BundleRenderer extends ResourceRenderer {
xn.para().b().tx("Exception generating narrative: "+e.getMessage()); xn.para().b().tx("Exception generating narrative: "+e.getMessage());
} }
} }
root.blockquote().addChildren(xn); root.blockquote().para().addChildren(xn);
} }
} }
} }
@ -156,7 +156,7 @@ public class BundleRenderer extends ResourceRenderer {
List<BaseWrapper> sections = section.children("section"); List<BaseWrapper> sections = section.children("section");
for (BaseWrapper child : sections) { for (BaseWrapper child : sections) {
if (nested) { if (nested) {
addSection(x.blockquote(), child, level+1, true); addSection(x.blockquote().para(), child, level+1, true);
} else { } else {
addSection(x, child, level+1, true); addSection(x, child, level+1, true);
} }
@ -241,7 +241,7 @@ public class BundleRenderer extends ResourceRenderer {
List<SectionComponent> sections = section.getSection(); List<SectionComponent> sections = section.getSection();
for (SectionComponent child : sections) { for (SectionComponent child : sections) {
if (nested) { if (nested) {
addSection(x.blockquote(), child, level+1, true); addSection(x.blockquote().para(), child, level+1, true);
} else { } else {
addSection(x, child, level+1, true); addSection(x, child, level+1, true);
} }
@ -300,7 +300,7 @@ public class BundleRenderer extends ResourceRenderer {
xn = makeExceptionXhtml(e, "generating narrative"); xn = makeExceptionXhtml(e, "generating narrative");
} }
} }
root.blockquote().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes())); root.blockquote().para().getChildNodes().addAll(checkInternalLinks(b, xn.getChildNodes()));
} }
} }
} }

View File

@ -51,7 +51,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
h.addText(cs.hasTitle() ? cs.getTitle() : cs.getName()); h.addText(cs.hasTitle() ? cs.getTitle() : cs.getName());
addMarkdown(x, cs.getDescription()); addMarkdown(x, cs.getDescription());
if (cs.hasCopyright()) if (cs.hasCopyright())
generateCopyright(x, cs); generateCopyright(x, cs );
} }
generateProperties(x, cs); generateProperties(x, cs);
@ -245,7 +245,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
if (cs == null) { if (cs == null) {
return false; return false;
} }
return CodeSystemUtilities.hasCode(cs, code); return code == null ? false : CodeSystemUtilities.hasCode(cs, code);
} }
return false; return false;
} }

View File

@ -223,7 +223,7 @@ public class PatientRenderer extends ResourceRenderer {
@Override @Override
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException { public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
describe(x, r); describe(x.para(), r);
return false; return false;
} }
} }

View File

@ -168,11 +168,13 @@ public class QuestionnaireResponseRenderer extends ResourceRenderer {
r.getCells().add(gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget()+"#item."+linkId, linkId, null, null)); r.getCells().add(gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget()+"#item."+linkId, linkId, null, null));
r.getCells().add(gen.new Cell(null, null, text, null, null)); r.getCells().add(gen.new Cell(null, null, text, null, null));
r.getCells().add(gen.new Cell(null, null, null, null, null)); r.getCells().add(gen.new Cell(null, null, null, null, null));
if (answers.size() == 0) { if (answers == null || answers.size() == 0) {
r.getCells().add(gen.new Cell(null, null, null, null, null)); r.getCells().add(gen.new Cell(null, null, null, null, null));
if (items != null) {
for (BaseWrapper si : items) { for (BaseWrapper si : items) {
renderTreeItem(gen, r.getSubRows(), q, si); renderTreeItem(gen, r.getSubRows(), q, si);
} }
}
} else if (answers.size() == 1) { } else if (answers.size() == 1) {
BaseWrapper ans = answers.get(0); BaseWrapper ans = answers.get(0);
renderAnswer(gen, q, r, ans); renderAnswer(gen, q, r, ans);

View File

@ -314,6 +314,9 @@ public class XhtmlComposer {
else if (node.getNodeType() == NodeType.Element) { else if (node.getNodeType() == NodeType.Element) {
Element child = e.getOwnerDocument().createElementNS(XHTML_NS, node.getName()); Element child = e.getOwnerDocument().createElementNS(XHTML_NS, node.getName());
e.appendChild(child); e.appendChild(child);
for (String n : node.getAttributes().keySet()) {
child.setAttribute(n, node.getAttribute(n));
}
for (XhtmlNode c : node.getChildNodes()) { for (XhtmlNode c : node.getChildNodes()) {
appendChild(child, c); appendChild(child, c);
} }