use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeDocumentManifest.
protected void composeDocumentManifest(Complex parent, String parentType, String name, DocumentManifest element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeDomainResource(t, "DocumentManifest", name, element, index);
if (element.hasMasterIdentifier())
composeIdentifier(t, "DocumentManifest", "masterIdentifier", element.getMasterIdentifier(), -1);
for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "DocumentManifest", "identifier", element.getIdentifier().get(i), i);
if (element.hasStatusElement())
composeEnum(t, "DocumentManifest", "status", element.getStatusElement(), -1);
if (element.hasType())
composeCodeableConcept(t, "DocumentManifest", "type", element.getType(), -1);
if (element.hasSubject())
composeReference(t, "DocumentManifest", "subject", element.getSubject(), -1);
if (element.hasCreatedElement())
composeDateTime(t, "DocumentManifest", "created", element.getCreatedElement(), -1);
for (int i = 0; i < element.getAuthor().size(); i++) composeReference(t, "DocumentManifest", "author", element.getAuthor().get(i), i);
for (int i = 0; i < element.getRecipient().size(); i++) composeReference(t, "DocumentManifest", "recipient", element.getRecipient().get(i), i);
if (element.hasSourceElement())
composeUri(t, "DocumentManifest", "source", element.getSourceElement(), -1);
if (element.hasDescriptionElement())
composeString(t, "DocumentManifest", "description", element.getDescriptionElement(), -1);
for (int i = 0; i < element.getContent().size(); i++) composeDocumentManifestDocumentManifestContentComponent(t, "DocumentManifest", "content", element.getContent().get(i), i);
for (int i = 0; i < element.getRelated().size(); i++) composeDocumentManifestDocumentManifestRelatedComponent(t, "DocumentManifest", "related", element.getRelated().get(i), i);
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class DicomPackageBuilder method execute.
public void execute() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
CodeSystem cs = buildCodeSystem();
String fn = Utilities.path(dest, pattern.replace("{version}", version));
Utilities.createDirectory(Utilities.getDirectoryForFile(fn));
NPMPackageGenerator gen = new NPMPackageGenerator(fn, buildPackage());
int i = 2;
gen.addFile(Category.RESOURCE, "CodeSystem-" + cs.getId() + ".json", new JsonParser().setOutputStyle(OutputStyle.NORMAL).composeBytes(cs));
ValueSet vs = buildAllValueSet();
gen.addFile(Category.RESOURCE, "ValueSet-" + vs.getId() + ".json", new JsonParser().setOutputStyle(OutputStyle.NORMAL).composeBytes(vs));
Set<String> ids = new HashSet<>();
ids.add(vs.getId());
for (File f : new File(Utilities.path(source, "Resources", "valuesets", "fhir", "json")).listFiles()) {
vs = (ValueSet) JsonParser.loadFile(new FileInputStream(f));
vs.setVersion(version);
if (vs.getId().length() > 64) {
vs.setId(vs.getId().substring(0, 64));
}
if (ids.contains(vs.getId())) {
throw new Error("Duplicate Id (note Ids cut off at 64 char): " + vs.getId());
}
ids.add(vs.getId());
gen.addFile(Category.RESOURCE, "ValueSet-" + vs.getId() + ".json", new JsonParser().setOutputStyle(OutputStyle.NORMAL).composeBytes(vs));
i++;
}
gen.finish();
System.out.println("Finished - " + i + " resources");
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class DicomPackageBuilder method buildCodeSystem.
private CodeSystem buildCodeSystem() throws ParserConfigurationException, FileNotFoundException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new FileInputStream(Utilities.path(source, "Resources", "Ontology", "DCM", "dcm.owl")));
Element rdf = doc.getDocumentElement();
Element d = XMLUtil.getFirstChild(rdf);
version = processVersion(XMLUtil.getNamedChildText(d, "versionInfo"));
CodeSystem cs = new CodeSystem();
cs.setId("DCM");
cs.setUrl("http://dicom.nema.org/resources/ontology/DCM");
cs.setVersion(version);
cs.setName("DICOMTerminologyDefinitions");
cs.setTitle("DICOM Controlled Terminology Definitions");
cs.getIdentifier().add(new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:oid:1.2.840.10008.2.16.4"));
cs.setStatus(PublicationStatus.ACTIVE);
cs.setExperimental(false);
cs.setPublisher("FHIR Project on behalf of DICOM");
cs.setDate(new Date());
cs.setDescription("DICOM Code Definitions (Coding Scheme Designator \"DCM\" Coding Scheme Version " + version);
cs.setPurpose("This code system is published as part of FHIR in order to make the codes available to FHIR terminology services and so implementers can easily leverage the codes");
cs.setCopyright("These codes are excerpted from Digital Imaging and Communications in Medicine (DICOM) Standard, Part 16: Content Mapping Resource, Copyright © 2011 by the National Electrical Manufacturers Association.");
cs.setCaseSensitive(true);
cs.setValueSet("http://dicom.nema.org/resources/ValueSet/all");
cs.setContent(CodeSystemContentMode.COMPLETE);
d = XMLUtil.getNextSibling(d);
while (d != null) {
String code = XMLUtil.getNamedChildText(d, "notation");
String display = XMLUtil.getNamedChildText(d, "prefLabel");
String definition = XMLUtil.getNamedChildText(d, "definition");
ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
cs.getConcept().add(cc);
cc.setCode(code);
cc.setDisplay(display);
cc.setDefinition(definition);
d = XMLUtil.getNextSibling(d);
}
return cs;
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ResourceTest method test.
public void test() throws FHIRFormatError, FileNotFoundException, IOException {
IParser p;
if (isJson())
p = new JsonParser();
else
p = new XmlParser(false);
Resource rf = p.parse(new FileInputStream(source));
FileOutputStream out = new FileOutputStream(source.getAbsoluteFile() + ".out.json");
JsonParser json1 = new JsonParser();
json1.setOutputStyle(OutputStyle.PRETTY);
json1.compose(out, rf);
out.close();
JsonParser json = new JsonParser();
rf = json.parse(new FileInputStream(source.getAbsoluteFile() + ".out.json"));
out = new FileOutputStream(source.getAbsoluteFile() + ".out.xml");
XmlParser atom = new XmlParser();
atom.setOutputStyle(OutputStyle.PRETTY);
atom.compose(out, rf, true);
out.close();
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method testRoundTrip.
public void testRoundTrip(String rootDir, String tmpDir, Collection<String> names) throws Throwable {
try {
System.err.println("Round trip from " + rootDir + " to " + tmpDir + ":" + Integer.toString(names.size()) + " files");
for (String n : names) {
System.err.print(" " + n);
String source = rootDir + n + ".xml";
// String tmpJson = tmpDir + n + ".json";
String tmp = tmpDir + n.replace(File.separator, "-") + ".tmp";
String dest = tmpDir + n.replace(File.separator, "-") + ".java.xml";
FileInputStream in = new FileInputStream(source);
XmlParser xp = new XmlParser();
Resource r = xp.parse(in);
System.err.print(".");
JsonParser jp = new JsonParser();
FileOutputStream out = new FileOutputStream(tmp);
jp.setOutputStyle(OutputStyle.PRETTY);
jp.compose(out, r);
out.close();
r = null;
System.err.print(".");
in = new FileInputStream(tmp);
System.err.print(",");
r = jp.parse(in);
System.err.print(".");
out = new FileOutputStream(dest);
new XmlParser().compose(out, r, true);
System.err.println("!");
out.close();
r = null;
System.gc();
}
} catch (Throwable e) {
System.err.println("Error: " + e.getMessage());
throw e;
}
}
Aggregations