use of org.hl7.fhir.r5.formats.RdfParser in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method executeJson.
public String executeJson(String[] args) throws IOException, FHIRException {
FileInputStream in;
File source = new CSFile(args[1]);
File dest = new CSFile(args[2]);
File destc = new CSFile(Utilities.changeFileExt(args[2], ".canonical.json"));
File destt = new CSFile(args[2] + ".tmp");
File destr = new CSFile(Utilities.changeFileExt(args[2], ".ttl"));
if (!source.exists())
throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
in = new CSFileInputStream(source);
XmlParser p = new XmlParser();
Resource rf = p.parse(in);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
FileOutputStream s = new FileOutputStream(dest);
json.compose(s, rf);
s.close();
json.setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(destc);
json.compose(s, rf);
s.close();
json.setSuppressXhtml("Snipped for Brevity");
json.setOutputStyle(OutputStyle.PRETTY);
s = new FileOutputStream(destt);
json.compose(s, rf);
s.close();
RdfParserBase rdf = new RdfParser();
s = new FileOutputStream(destr);
rdf.compose(s, rf);
s.close();
return TextFile.fileToString(destt.getAbsolutePath());
}
use of org.hl7.fhir.r5.formats.RdfParser in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method processExamples.
public void processExamples(String rootDir, Collection<String> list) throws FHIRException {
for (String n : list) {
try {
String filename = rootDir + n + ".xml";
// 1. produce canonical XML
CSFileInputStream source = new CSFileInputStream(filename);
FileOutputStream dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.xml"));
XmlParser p = new XmlParser();
Resource r = p.parse(source);
XmlParser cxml = new XmlParser();
cxml.setOutputStyle(OutputStyle.CANONICAL);
cxml.compose(dest, r);
// 2. produce JSON
source = new CSFileInputStream(filename);
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".json"));
r = p.parse(source);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
json.compose(dest, r);
json = new JsonParser();
json.setOutputStyle(OutputStyle.CANONICAL);
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.json"));
json.compose(dest, r);
// 2. produce JSON
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".ttl"));
RdfParserBase rdf = new RdfParser();
rdf.compose(dest, r);
} catch (Exception e) {
e.printStackTrace();
throw new FHIRException("Error Processing " + n + ".xml: " + e.getMessage(), e);
}
}
}
use of org.hl7.fhir.r5.formats.RdfParser in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method executeJson.
public String executeJson(String[] args) throws IOException, FHIRException {
FileInputStream in;
File source = new CSFile(args[1]);
File dest = new CSFile(args[2]);
File destc = new CSFile(Utilities.changeFileExt(args[2], ".canonical.json"));
File destt = new CSFile(args[2] + ".tmp");
File destr = new CSFile(Utilities.changeFileExt(args[2], ".ttl"));
if (!source.exists())
throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
in = new CSFileInputStream(source);
XmlParser p = new XmlParser();
Resource rf = p.parse(in);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
FileOutputStream s = new FileOutputStream(dest);
json.compose(s, rf);
s.close();
json.setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(destc);
json.compose(s, rf);
s.close();
json.setSuppressXhtml("Snipped for Brevity");
json.setOutputStyle(OutputStyle.PRETTY);
s = new FileOutputStream(destt);
json.compose(s, rf);
s.close();
RdfParserBase rdf = new RdfParser();
s = new FileOutputStream(destr);
rdf.compose(s, rf);
s.close();
return TextFile.fileToString(destt.getAbsolutePath());
}
use of org.hl7.fhir.r5.formats.RdfParser in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method processExamples.
public void processExamples(String rootDir, Collection<String> list) throws FHIRException {
for (String n : list) {
try {
String filename = rootDir + n + ".xml";
// 1. produce canonical XML
CSFileInputStream source = new CSFileInputStream(filename);
FileOutputStream dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.xml"));
XmlParser p = new XmlParser();
Resource r = p.parse(source);
XmlParser cxml = new XmlParser();
cxml.setOutputStyle(OutputStyle.CANONICAL);
cxml.compose(dest, r);
// 2. produce JSON
source = new CSFileInputStream(filename);
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".json"));
r = p.parse(source);
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
json.compose(dest, r);
json = new JsonParser();
json.setOutputStyle(OutputStyle.CANONICAL);
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".canonical.json"));
json.compose(dest, r);
// 2. produce JSON
dest = new FileOutputStream(Utilities.changeFileExt(filename, ".ttl"));
RdfParserBase rdf = new RdfParser();
rdf.compose(dest, r);
} catch (Exception e) {
e.printStackTrace();
throw new FHIRException("Error Processing " + n + ".xml: " + e.getMessage(), e);
}
}
}
use of org.hl7.fhir.r5.formats.RdfParser in project kindling by HL7.
the class Publisher method generateCompartmentDefinition.
private void generateCompartmentDefinition(Compartment c) throws Exception {
CompartmentDefinition cpd = new CompartmentDefinition();
cpd.setId(c.getName());
cpd.setUrl("http://hl7.org/fhir/CompartmentDefinition/" + c.getName());
cpd.setName("Base FHIR compartment definition for " + c.getTitle());
cpd.setStatus(PublicationStatus.DRAFT);
cpd.setDescription(c.getIdentity() + ". " + c.getDescription());
cpd.setExperimental(true);
cpd.setVersion(page.getVersion().toCode());
cpd.setDate(page.getGenDate().getTime());
cpd.setPublisher("FHIR Project Team");
cpd.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
cpd.setCode(CompartmentType.fromCode(c.getTitle()));
cpd.setSearch(true);
for (String rn : page.getDefinitions().sortedResourceNames()) {
ResourceDefn rd = page.getDefinitions().getResourceByName(rn);
String rules = c.getResources().get(rd);
CompartmentDefinitionResourceComponent cc = cpd.addResource().setCode(rd.getName());
if (!Utilities.noString(rules)) {
for (String p : rules.split("\\|")) cc.addParam(p.trim());
}
}
RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
RendererFactory.factory(cpd, lrc).render(cpd);
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpd);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".canonical.xml");
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpd);
s.close();
cloneToXhtml("compartmentdefinition-" + c.getName().toLowerCase(), "Compartment Definition for " + c.getName(), true, "resource-instance:CompartmentDefinition", "Compartment Definition for " + c.getName(), null, wg("fhir"));
s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpd);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".canonical.json");
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpd);
s.close();
jsonToXhtml("compartmentdefinition-" + c.getName().toLowerCase(), "Compartment Definition for " + c.getName(), resource2Json(cpd), "resource-instance:CompartmentDefinition", "Compartment Definition for " + c.getName(), null, wg("fhir"));
s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".ttl");
new RdfParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpd);
s.close();
ttlToXhtml("compartmentdefinition-" + c.getName().toLowerCase(), "Compartment Definition for " + c.getName(), resource2Ttl(cpd), "resource-instance:CompartmentDefinition", "Compartment Definition for " + c.getName(), null, wg("fhir"));
Utilities.copyFile(new CSFile(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + "compartmentdefinition-" + c.getName().toLowerCase() + ".xml"));
addToResourceFeed(cpd, page.getResourceBundle());
}
Aggregations