Search in sources :

Example 31 with IWorkerContext

use of org.hl7.fhir.r5.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class Transformer method process.

public boolean process() {
    try {
        System.out.println("  .. load definitions from " + definitions);
        IWorkerContext context = SimpleWorkerContext.fromPack(definitions);
        scu = new StructureMapUtilities(context, new HashMap<String, StructureMap>(), null);
        for (String folder : folders) {
            System.out.println("  .. load additional definitions from " + folder);
            ((SimpleWorkerContext) context).loadFromFolder(folder);
            loadMaps(folder);
        }
        System.out.println("  .. load source from " + source);
        Element e = Manager.parse(context, new FileInputStream(source), FhirFormat.XML);
        Bundle bundle = new Bundle();
        StructureMap map = scu.getLibrary().get(mapUri);
        if (map == null)
            throw new Error("Unable to find map " + mapUri + " (Known Maps = " + Utilities.listCanonicalUrls(scu.getLibrary().keySet()) + ")");
        scu.transform(null, e, map, bundle);
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(output), bundle);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        message = e.getMessage();
        return false;
    }
}
Also used : XmlParser(org.hl7.fhir.dstu2016may.formats.XmlParser) HashMap(java.util.HashMap) Bundle(org.hl7.fhir.dstu2016may.model.Bundle) Element(org.hl7.fhir.dstu2016may.metamodel.Element) FileInputStream(java.io.FileInputStream) StructureMap(org.hl7.fhir.dstu2016may.model.StructureMap) FileOutputStream(java.io.FileOutputStream)

Example 32 with IWorkerContext

use of org.hl7.fhir.r5.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.

the class ResourceUtilities method representDataElementCollection.

public static String representDataElementCollection(IWorkerContext context, Bundle bundle, boolean profileLink, String linkBase) {
    StringBuilder b = new StringBuilder();
    DataElement common = showDECHeader(b, bundle);
    b.append("<table class=\"grid\">\r\n");
    List<String> cols = chooseColumns(bundle, common, b, profileLink);
    for (BundleEntryComponent e : bundle.getEntry()) {
        DataElement de = (DataElement) e.getResource();
        renderDE(de, cols, b, profileLink, linkBase);
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : DataElement(org.hl7.fhir.dstu2016may.model.DataElement) BundleEntryComponent(org.hl7.fhir.dstu2016may.model.Bundle.BundleEntryComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Aggregations

FileInputStream (java.io.FileInputStream)6 FileOutputStream (java.io.FileOutputStream)6 JsonElement (com.google.gson.JsonElement)5 File (java.io.File)5 IWorkerContext (org.hl7.fhir.r5.context.IWorkerContext)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 UcumEssenceService (org.fhir.ucum.UcumEssenceService)4 TextFile (org.hl7.fhir.utilities.TextFile)4 IWorkerContext (org.hl7.fhir.r4b.context.IWorkerContext)3 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)3 Row (org.apache.poi.ss.usermodel.Row)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 ElementDefinitionMappingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionMappingComponent)2 StructureDefinitionMappingComponent (org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionMappingComponent)2 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)2 ElementDefinitionMappingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionMappingComponent)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2