Search in sources :

Example 16 with SimpleWorkerContext

use of org.hl7.fhir.r4.context.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 = SimpleWorkerContext.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.r4b.elementmodel.Element) FileOutputStream(java.io.FileOutputStream) SimpleWorkerContext(org.hl7.fhir.r4b.context.SimpleWorkerContext) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException)

Example 17 with SimpleWorkerContext

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

the class OIDBasedValueSetImporter method init.

protected void init() throws FHIRException, IOException {
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    NpmPackage npm = pcm.loadPackage("hl7.fhir.r5.core", "current");
    SimpleWorkerContext context = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).fromPackage(npm);
    context.loadFromPackage(pcm.loadPackage("hl7.terminology"), null);
    this.context = context;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) SimpleWorkerContext(org.hl7.fhir.r5.context.SimpleWorkerContext)

Example 18 with SimpleWorkerContext

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

the class SimpleWorkerContext method fromClassPath.

public static SimpleWorkerContext fromClassPath(String name) throws IOException, FHIRException {
    InputStream s = SimpleWorkerContext.class.getResourceAsStream("/" + name);
    SimpleWorkerContext res = new SimpleWorkerContext();
    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 19 with SimpleWorkerContext

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

the class StructureMapTests method testLoadCDA.

@Test
public void testLoadCDA() throws FileNotFoundException, Exception {
    Map<String, StructureMap> maps = new HashMap<String, StructureMap>();
    if (TestingUtilities.context == null)
        TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
    StructureMapUtilities scu = new StructureMapUtilities(TestingUtilities.context, maps, null);
    for (String f : new File("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\CDA").list()) {
        try {
            StructureDefinition sd = (StructureDefinition) new XmlParser().parse(new FileInputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\CDA\\" + f));
            ((SimpleWorkerContext) TestingUtilities.context).seeResource(sd.getUrl(), sd);
        } catch (Exception e) {
        }
    }
    for (String f : new File("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\maps").list()) {
        try {
            StructureMap map = scu.parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\maps\\" + f));
            maps.put(map.getUrl(), map);
        } catch (Exception e) {
        }
    }
    Element cda = Manager.parse(TestingUtilities.context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\Example\\ccd.xml"), FhirFormat.XML);
    Manager.compose(TestingUtilities.context, cda, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\Example\\ccd.out.json"), FhirFormat.JSON, OutputStyle.PRETTY, null);
    Manager.compose(TestingUtilities.context, cda, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\guides\\ccda\\Example\\ccd.out.xml"), FhirFormat.XML, OutputStyle.PRETTY, null);
    Bundle bundle = new Bundle();
    scu.transform(null, cda, maps.get("http://hl7.org/fhir/StructureMap/cda"), bundle);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "bundle.xml")), bundle);
}
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) SimpleWorkerContext(org.hl7.fhir.dstu2016may.utils.SimpleWorkerContext) StructureMapUtilities(org.hl7.fhir.dstu2016may.utils.StructureMapUtilities) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMap(org.hl7.fhir.dstu2016may.model.StructureMap) StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) Test(org.junit.jupiter.api.Test)

Example 20 with SimpleWorkerContext

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

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