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 = 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());
}
}
}
}
}
}
use of org.hl7.fhir.dstu2.utils.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;
}
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) throws IOException, FHIRException {
InputStream s = SimpleWorkerContext.class.getResourceAsStream("/" + name);
SimpleWorkerContext res = new SimpleWorkerContext();
res.loadFromStream(s, null);
return res;
}
use of org.hl7.fhir.dstu2.utils.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);
}
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 + ")");
// }
}
Aggregations