use of org.hl7.fhir.r4b.renderers.utils.RenderingContext in project org.hl7.fhir.core by hapifhir.
the class SnapShotGenerationTests method testGen.
private void testGen(boolean fail, TestDetails test, SnapShotGenerationTestsContext context) throws Exception {
if (!Utilities.noString(test.register)) {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages, null);
pu.setNewSlicingProcessing(true);
for (StructureDefinition sd : test.included) {
pu.setIds(sd, false);
}
for (StructureDefinition sd : test.included) {
if (!TestingUtilities.context().hasResource(StructureDefinition.class, sd.getUrl())) {
TestingUtilities.context().cacheResource(sd);
}
}
StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, test.included.get(0).getBaseDefinition());
if (base != null) {
pu.generateSnapshot(base, test.included.get(0), test.included.get(0).getUrl(), "http://test.org/profile", test.included.get(0).getName());
}
int ec = 0;
for (ValidationMessage vm : messages) {
if (vm.getLevel() == IssueSeverity.ERROR) {
System.out.println(vm.summary());
ec++;
}
}
if (ec > 0)
throw new FHIRException("register gen failed: " + messages.toString());
}
StructureDefinition base = getSD(test.getSource().getBaseDefinition(), context);
if (!base.getUrl().equals(test.getSource().getBaseDefinition()))
throw new Exception("URL mismatch on base: " + base.getUrl() + " wanting " + test.getSource().getBaseDefinition());
StructureDefinition output = test.getSource().copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages, new TestPKP());
pu.setNewSlicingProcessing(test.isNewSliceProcessing());
pu.setThrowException(false);
pu.setDebug(test.isDebug());
pu.setIds(test.getSource(), false);
if (!TestingUtilities.context().hasPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER)) {
NpmPackage npm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
TestingUtilities.context().loadFromPackage(npm, new TestLoader(new String[] { "StructureDefinition" }), new String[] { "StructureDefinition" });
}
pu.setXver(new XVerExtensionManager(TestingUtilities.context()));
if (test.isSort()) {
List<String> errors = new ArrayList<String>();
int lastCount = output.getDifferential().getElement().size();
pu.sortDifferential(base, output, test.getSource().getName(), errors, false);
if (errors.size() > 0)
throw new FHIRException("Sort failed: " + errors.toString());
}
try {
messages.clear();
pu.generateSnapshot(base, output, test.getSource().getUrl(), "http://test.org/profile", test.getSource().getName());
List<ValidationMessage> ml = new ArrayList<>();
for (ValidationMessage vm : messages) {
if (vm.getLevel() == IssueSeverity.ERROR) {
ml.add(vm);
}
}
if (ml.size() > 0) {
throw new FHIRException("Snapshot Generation failed: " + ml.toString());
}
} catch (Throwable e) {
System.out.println("\r\nException: " + e.getMessage());
throw e;
}
if (output.getDifferential().hasElement()) {
RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER);
rc.setDestDir(Utilities.path("[tmp]", "snapshot"));
rc.setProfileUtilities(new ProfileUtilities(TestingUtilities.context(), null, new TestPKP()));
RendererFactory.factory(output, rc).render(output);
}
if (!fail) {
test.output = output;
TestingUtilities.context().cacheResource(output);
File dst = new File(TestingUtilities.tempFile("snapshot", test.getId() + "-expected.xml"));
if (dst.exists())
dst.delete();
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("snapshot", test.getId() + "-actual.xml")), output);
StructureDefinition t1 = test.expected.copy();
t1.setText(null);
StructureDefinition t2 = test.output.copy();
t2.setText(null);
Assertions.assertTrue(t1.equalsDeep(t2), "Output does not match expected");
}
}
use of org.hl7.fhir.r4b.renderers.utils.RenderingContext in project org.hl7.fhir.core by hapifhir.
the class ResourceRoundTripTests method test.
@Test
public void test() throws IOException, FHIRException, EOperationOutcome {
DomainResource res = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"));
RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER);
RendererFactory.factory(res, rc).render(res);
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"), new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.xml")));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.out.xml")), res);
}
use of org.hl7.fhir.r4b.renderers.utils.RenderingContext in project org.hl7.fhir.core by hapifhir.
the class SnapShotGenerationXTests method testGen.
private void testGen(boolean fail, TestDetails test) throws Exception {
if (!Utilities.noString(test.register)) {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
ProfileUtilities pu = new ProfileUtilities(UtilitiesXTests.context(version), messages, null);
pu.setNewSlicingProcessing(true);
pu.setIds(test.included, false);
StructureDefinition base = UtilitiesXTests.context(version).fetchResource(StructureDefinition.class, test.included.getBaseDefinition());
if (base != null) {
pu.generateSnapshot(base, test.included, test.included.getUrl(), "http://test.org/profile", test.included.getName());
}
if (!UtilitiesXTests.context(version).hasResource(StructureDefinition.class, test.included.getUrl()))
UtilitiesXTests.context(version).cacheResource(test.included);
int ec = 0;
for (ValidationMessage vm : messages) {
if (vm.getLevel() == IssueSeverity.ERROR) {
System.out.println(vm.summary());
ec++;
}
}
if (ec > 0)
throw new FHIRException("register gen failed: " + messages.toString());
}
StructureDefinition base = getSD(test.getSource().getBaseDefinition());
if (!base.getUrl().equals(test.getSource().getBaseDefinition()))
throw new Exception("URL mismatch on base: " + base.getUrl() + " wanting " + test.getSource().getBaseDefinition());
StructureDefinition output = test.getSource().copy();
ProfileUtilities pu = new ProfileUtilities(UtilitiesXTests.context(version), messages, new TestPKP());
pu.setNewSlicingProcessing(test.isNewSliceProcessing());
pu.setThrowException(false);
pu.setDebug(test.isDebug());
pu.setIds(test.getSource(), false);
if (test.isSort()) {
List<String> errors = new ArrayList<String>();
int lastCount = output.getDifferential().getElement().size();
pu.sortDifferential(base, output, test.getSource().getName(), errors, false);
if (errors.size() > 0)
throw new FHIRException("Sort failed: " + errors.toString());
}
try {
messages.clear();
pu.generateSnapshot(base, output, test.getSource().getUrl(), "http://test.org/profile", test.getSource().getName());
List<ValidationMessage> ml = new ArrayList<>();
for (ValidationMessage vm : messages) {
if (vm.getLevel() == IssueSeverity.ERROR) {
ml.add(vm);
}
}
if (ml.size() > 0) {
throw new FHIRException("Snapshot Generation failed: " + ml.toString());
}
} catch (Throwable e) {
System.out.println("\r\nException: " + e.getMessage());
throw e;
}
if (output.getDifferential().hasElement()) {
RenderingContext rc = new RenderingContext(TestingUtilities.getSharedWorkerContext(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER);
rc.setDestDir(makeTempDir());
rc.setProfileUtilities(new ProfileUtilities(TestingUtilities.getSharedWorkerContext(), null, new TestPKP()));
RendererFactory.factory(output, rc).render(output);
}
if (!fail) {
test.output = output;
UtilitiesXTests.context(version).cacheResource(output);
File dst = new File(UtilitiesXTests.tempFile("snapshot", test.getId() + "-expected.xml"));
if (dst.exists())
dst.delete();
IOUtils.copy(UtilitiesXTests.loadTestResourceStream("rX", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(UtilitiesXTests.tempFile("snapshot", test.getId() + "-actual.xml")), output);
StructureDefinition t1 = test.expected.copy();
t1.setText(null);
StructureDefinition t2 = test.output.copy();
t2.setText(null);
Assertions.assertTrue(t1.equalsDeep(t2), "Output does not match expected");
}
}
use of org.hl7.fhir.r4b.renderers.utils.RenderingContext in project kindling by HL7.
the class PageProcessor method renderCodeSystemWithLangs.
private String renderCodeSystemWithLangs(Set<String> langs, CodeSystem cs, String prefix) throws Exception {
Narrative n = cs.getText();
StringBuilder b = new StringBuilder();
b.append("<div id=\"tabs\" style=\"border-right-style: none;\">\r\n");
b.append("<ul>\r\n");
b.append("<li><a href=\"#tabs-all\">All Languages</a></li>\r\n");
b.append("<li><a href=\"#tabs-en\">English</a></li>\r\n");
for (String l : sorted(langs)) b.append("<li><a href=\"#tabs-" + l + "\">" + langDisplay(l) + "</a></li>\r\n");
b.append("</ul>\r\n");
b.append("<div id=\"tabs-all\">\r\n");
cs.setText(null);
RenderingContext lrc = rc.copy().setLang("*");
RendererFactory.factory(cs, lrc).render(cs);
b.append(new XhtmlComposer(XhtmlComposer.HTML).compose(cs.getText().getDiv()));
b.append("</div>\r\n");
b.append("<div id=\"tabs-en\">\r\n");
cs.setText(null);
lrc = rc.copy().setLang("en");
RendererFactory.factory(cs, lrc).render(cs);
b.append(new XhtmlComposer(XhtmlComposer.HTML).compose(cs.getText().getDiv()));
b.append("</div>\r\n");
for (String l : sorted(langs)) {
b.append("<div id=\"tabs-" + l + "\">\r\n");
String desc = cs.getDescriptionElement().getTranslation(l);
if (!Utilities.noString(desc))
b.append(processMarkdown("RenderingCodeSystem", workerContext.translator().translate("render-cs", "Definition", l) + ": " + desc, prefix));
cs.setText(null);
lrc = rc.copy().setLang(l);
RendererFactory.factory(cs, lrc).render(cs);
b.append(new XhtmlComposer(XhtmlComposer.HTML).compose(cs.getText().getDiv()));
b.append("</div>\r\n");
}
b.append("</div>\r\n");
cs.setText(n);
return b.toString();
}
use of org.hl7.fhir.r4b.renderers.utils.RenderingContext in project kindling by HL7.
the class PageProcessor method makeRenderingContext.
public void makeRenderingContext() {
rc = new RenderingContext(workerContext, processor, ValidationOptions.defaults(), "", "", null, ResourceRendererMode.IG);
rc.setParser(this);
rc.setResolver(this);
}
Aggregations