Search in sources :

Example 1 with StructureMapUtilities

use of org.hl7.fhir.dstu2016may.utils.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);
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapUtilities(org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities)

Example 2 with StructureMapUtilities

use of org.hl7.fhir.dstu2016may.utils.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);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) StructureMapUtilities(org.hl7.fhir.dstu3.utils.StructureMapUtilities)

Example 3 with StructureMapUtilities

use of org.hl7.fhir.dstu2016may.utils.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());
}
Also used : org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) StructureMapUtilities(org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities) Test(org.junit.jupiter.api.Test)

Example 4 with StructureMapUtilities

use of org.hl7.fhir.dstu2016may.utils.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"));
}
Also used : StructureMap(org.hl7.fhir.dstu2016may.model.StructureMap) StructureMapUtilities(org.hl7.fhir.dstu2016may.utils.StructureMapUtilities)

Example 5 with StructureMapUtilities

use of org.hl7.fhir.dstu2016may.utils.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"));
}
Also used : StructureMap(org.hl7.fhir.dstu3.model.StructureMap) StructureMapUtilities(org.hl7.fhir.dstu3.utils.StructureMapUtilities)

Aggregations

StructureMapUtilities (org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 Test (org.junit.jupiter.api.Test)6 File (java.io.File)5 TextFile (org.hl7.fhir.utilities.TextFile)5 IniFile (org.hl7.fhir.utilities.IniFile)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 StructureMap (org.hl7.fhir.dstu2016may.model.StructureMap)3 StructureMapUtilities (org.hl7.fhir.dstu3.utils.StructureMapUtilities)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 XmlParser (org.hl7.fhir.dstu2016may.formats.XmlParser)2 Element (org.hl7.fhir.dstu2016may.metamodel.Element)2 Bundle (org.hl7.fhir.dstu2016may.model.Bundle)2 StructureMapUtilities (org.hl7.fhir.dstu2016may.utils.StructureMapUtilities)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 MetadataResource (org.hl7.fhir.r4.model.MetadataResource)2