Search in sources :

Example 1 with SimpleWorkerContext

use of org.hl7.fhir.dstu2.utils.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class R2R3ConversionManager method setR3Definitions.

public void setR3Definitions(InputStream stream) throws IOException, FHIRException {
    needPrepare = true;
    Map<String, InputStream> files = readInputStream(stream);
    contextR3 = new SimpleWorkerContext();
    contextR2.setAllowLoadingDuplicates(true);
    contextR3.loadFromFile(files.get("profiles-types.xml"), "profiles-types.xml", null);
    contextR3.loadFromFile(files.get("profiles-resources.xml"), "profiles-resources.xml", null);
    contextR3.loadFromFile(files.get("extension-definitions.xml"), "extension-definitions.xml", null);
    contextR3.loadFromFile(files.get("valuesets.xml"), "valuesets.xml", null);
    contextR3.setCanRunWithoutTerminology(true);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) SimpleWorkerContext(org.hl7.fhir.dstu3.context.SimpleWorkerContext)

Example 2 with SimpleWorkerContext

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

Example 3 with SimpleWorkerContext

use of org.hl7.fhir.dstu2.utils.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.dstu2016may.utils.SimpleWorkerContext)

Example 4 with SimpleWorkerContext

use of org.hl7.fhir.dstu2.utils.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method fromClassPath.

public static SimpleWorkerContext fromClassPath(String name, boolean allowDuplicates) throws IOException, FHIRException {
    InputStream s = SimpleWorkerContext.class.getResourceAsStream("/" + name);
    SimpleWorkerContext res = new SimpleWorkerContext();
    res.setAllowLoadingDuplicates(allowDuplicates);
    res.loadFromStream(s, null);
    return res;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 5 with SimpleWorkerContext

use of org.hl7.fhir.dstu2.utils.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.

the class ValidationTestConvertor method main.

/**
 * @param args
 * @throws FHIRException
 * @throws IOException
 * @throws FileNotFoundException
 */
public static void main(String[] args) throws FileNotFoundException, IOException, FHIRException {
    SimpleWorkerContext context = new SimpleWorkerContext.SimpleWorkerContextBuilder().fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
    for (File f : new File("C:\\work\\org.hl7.fhir\\build\\tests\\validation-examples").listFiles()) {
        if (f.getAbsolutePath().endsWith(".xml")) {
            File t = new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl"));
            if (!t.exists()) {
                try {
                    System.out.print("Process " + f.getAbsolutePath());
                    Element e = Manager.parseSingle(context, new FileInputStream(f), FhirFormat.XML);
                    Manager.compose(context, e, new FileOutputStream(t), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
                    System.out.println("   .... success");
                } catch (Exception e) {
                    System.out.println("   .... fail: " + e.getMessage());
                }
            }
        }
        if (f.getAbsolutePath().endsWith(".json")) {
            if (!new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl")).exists()) {
                File t = new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl"));
                if (!t.exists()) {
                    try {
                        System.out.print("Process " + f.getAbsolutePath());
                        Element e = Manager.parseSingle(context, new FileInputStream(f), FhirFormat.JSON);
                        Manager.compose(context, e, new FileOutputStream(t), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
                        System.out.println("   .... success");
                    } catch (Exception e) {
                        System.out.println("   .... fail: " + e.getMessage());
                    }
                }
            }
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) FileOutputStream(java.io.FileOutputStream) SimpleWorkerContext(org.hl7.fhir.r5.context.SimpleWorkerContext) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException)

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