Search in sources :

Example 21 with SimpleWorkerContext

use of org.hl7.fhir.dstu3.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class R2R3ConversionManager method setR2Definitions.

// set up ------------------------------------------------------------------
public void setR2Definitions(InputStream stream) throws IOException, FHIRException {
    needPrepare = true;
    R2ToR3Loader ldr = new R2ToR3Loader();
    ldr.setPatchUrls(true).setKillPrimitives(true);
    Map<String, InputStream> files = readInputStream(stream);
    contextR2 = new SimpleWorkerContext();
    contextR2.setAllowLoadingDuplicates(true);
    contextR2.loadFromFile(files.get("profiles-types.xml"), "profiles-types.xml", ldr);
    contextR2.loadFromFile(files.get("profiles-resources.xml"), "profiles-resources.xml", ldr);
    contextR2.loadFromFile(files.get("valuesets.xml"), "valuesets.xml", ldr);
}
Also used : R2ToR3Loader(org.hl7.fhir.convertors.loaders.loaderR3.R2ToR3Loader) ZipInputStream(java.util.zip.ZipInputStream) SimpleWorkerContext(org.hl7.fhir.dstu3.context.SimpleWorkerContext)

Example 22 with SimpleWorkerContext

use of org.hl7.fhir.dstu3.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class TestingUtilities method getWorkerContext.

public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage) throws Exception {
    SimpleWorkerContext swc = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(TestConstants.TX_CACHE).fromPackage(npmPackage);
    TerminologyCache.setCacheErrors(true);
    return swc;
}
Also used : SimpleWorkerContext(org.hl7.fhir.r5.context.SimpleWorkerContext)

Example 23 with SimpleWorkerContext

use of org.hl7.fhir.dstu3.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class ToolsHelper method generateSnapshots.

private void generateSnapshots(String[] args) throws IOException, FHIRException {
    if (args.length == 1) {
        System.out.println("tools.jar snapshot-maker [source] -defn [definitions]");
        System.out.println("");
        System.out.println("Generates a snapshot from a differential. The nominated profile must have a single struture that has a differential");
        System.out.println("");
        System.out.println("source - the profile to generate the snapshot for. Maybe a file name, or a URL reference to a server running FHIR RESTful API");
        System.out.println("definitions - filename for local copy of the validation.zip file");
    }
    String address = args[1];
    String definitions = args[3];
    SimpleWorkerContext context = SimpleWorkerContext.fromDefinitions(getDefinitions(definitions));
    // } else {
    throw new NotImplementedException("generating snapshots not done yet (address = " + address + ")");
// }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) SimpleWorkerContext(org.hl7.fhir.dstu3.context.SimpleWorkerContext)

Example 24 with SimpleWorkerContext

use of org.hl7.fhir.dstu3.context.SimpleWorkerContext 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)

Aggregations

FileInputStream (java.io.FileInputStream)7 IOException (java.io.IOException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 ZipInputStream (java.util.zip.ZipInputStream)5 SimpleWorkerContext (org.hl7.fhir.r4.context.SimpleWorkerContext)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 FileOutputStream (java.io.FileOutputStream)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 SimpleWorkerContext (org.hl7.fhir.r5.context.SimpleWorkerContext)4 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)4 File (java.io.File)3 InputStream (java.io.InputStream)3 SimpleWorkerContext (org.hl7.fhir.dstu3.context.SimpleWorkerContext)3 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)3 HashMap (java.util.HashMap)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 StructureMap (org.hl7.fhir.dstu2016may.model.StructureMap)2