use of org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities in project kindling by HL7.
the class Publisher method produceMap.
private void produceMap(String name, SectionTracker st, ResourceDefn res) throws Exception {
File f = new File(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R4toR3", name + ".map"));
if (!f.exists())
return;
String n = name.toLowerCase();
Map<String, String> values = new HashMap<String, String>();
values.put("conv-status", page.r3r4StatusForResource(name));
String fwds = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R3toR4", page.r3nameForResource(name) + ".map"));
String bcks = TextFile.fileToString(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R4toR3", name + ".map"));
values.put("fwds", Utilities.escapeXml(fwds));
values.put("bcks", Utilities.escapeXml(bcks));
values.put("fwds-status", "");
values.put("bcks-status", "");
values.put("r3errs", Utilities.escapeXml(page.getR3R4ValidationErrors(name)));
try {
new StructureMapUtilities(page.getWorkerContext()).parse(fwds, page.r3nameForResource(name) + ".map");
} catch (FHIRException e) {
values.put("fwds-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
}
try {
new StructureMapUtilities(page.getWorkerContext()).parse(bcks, name + ".map");
} catch (FHIRException e) {
values.put("bcks-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
} catch (IllegalArgumentException e) {
values.put("bcks-status", "<p style=\"background-color: #ffb3b3; border:1px solid maroon; padding: 5px;\">This script does not compile: " + e.getMessage() + "</p>\r\n");
}
if (page.getDefinitions().hasResource(name) || (page.getDefinitions().getBaseResources().containsKey(name) && !name.equals("Parameters"))) {
String src = TextFile.fileToString(page.getFolders().templateDir + "template-version-maps.html");
TextFile.stringToFile(insertSectionNumbers(page.processResourceIncludes(n, page.getDefinitions().getResourceByName(name), null, null, null, null, null, src, null, null, "res-R3/R4 Conversions", n + "-version-maps.html", null, values, res.getWg(), null), st, n + "-version-maps.html", 0, null), page.getFolders().dstDir + n + "-version-maps.html");
page.getHTMLChecker().registerFile(n + "-version-maps.html", "Version Maps for " + name, HTMLLinkChecker.XHTML_TYPE, true);
}
}
use of org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class R2R3ConversionManager method setMappingLibrary.
public void setMappingLibrary(InputStream stream) throws IOException, FHIRException {
needPrepare = true;
Map<String, InputStream> files = readInputStream(stream);
for (InputStream s : files.values()) {
StructureMap sm = new StructureMapUtilities(contextR3).parse(TextFile.streamToString(s));
library.put(sm.getUrl(), sm);
}
}
use of org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class Convertor_Factory_40_50Test method testBidirectionalStructureMapConversion.
@Test
public void testBidirectionalStructureMapConversion() {
StructureMapUtilities smu5 = new StructureMapUtilities(context, mock(org.hl7.fhir.r5.utils.structuremap.ITransformerServices.class));
org.hl7.fhir.r5.model.StructureMap mapR5 = smu5.parse(CONTENT, "map");
assertEquals("tgt", mapR5.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
assertEquals("item.answer.valueString", mapR5.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
assertEquals("item", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getValueIdType().getValueAsString());
assertEquals("patient", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getValueIdType().getValueAsString());
org.hl7.fhir.r4.model.StructureMap mapR4 = (org.hl7.fhir.r4.model.StructureMap) VersionConvertorFactory_40_50.convertResource(mapR5);
assertEquals("tgt", mapR4.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
assertEquals("item.answer.valueString", mapR4.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
assertEquals("item", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getValueAsString());
assertEquals("patient", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getValueAsString());
assertEquals("url", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue().fhirType());
assertEquals("url", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue().fhirType());
assertEquals("id", ((org.hl7.fhir.r4.model.UrlType) mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue()).getValueAsString());
assertEquals("id", ((org.hl7.fhir.r4.model.UrlType) mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue()).getValueAsString());
StructureMap mapR5Back = (StructureMap) VersionConvertorFactory_40_50.convertResource(mapR4);
assertEquals("tgt", mapR5Back.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
assertEquals("item.answer.valueString", mapR5Back.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
assertEquals("item", mapR5Back.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getValueIdType().getValueAsString());
assertEquals("patient", mapR5Back.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getValueIdType().getValueAsString());
}
use of org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class StructureMapTests method testParse.
private void testParse(String path) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir.2016May\\build\\publish\\validation-min.xml.zip");
StructureMapUtilities scm = new StructureMapUtilities(TestingUtilities.context, null, null);
StructureMap map = scm.parse(TextFile.fileToString(Utilities.path("C:\\work\\org.hl7.fhir.2016May\\build", path)));
TextFile.stringToFile(scm.render(map), Utilities.path("C:\\work\\org.hl7.fhir.2016May\\build", path + ".out"));
}
use of org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities in project org.hl7.fhir.core by hapifhir.
the class StructureMapTests method testParse.
private void testParse(String path) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack(Utilities.path(TestingUtilities.home(), "publish", "definitions.xml.zip"));
StructureMapUtilities scm = new StructureMapUtilities(TestingUtilities.context, null, null);
StructureMap map = scm.parse(TextFile.fileToString(Utilities.path(TestingUtilities.home(), path)));
TextFile.stringToFile(scm.render(map), Utilities.path(TestingUtilities.home(), path + ".out"));
}
Aggregations