Search in sources :

Example 51 with Source

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);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 52 with Source

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");
}
Also used : NPMPackageGenerator(org.hl7.fhir.r4.utils.NPMPackageGenerator) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ValueSet(org.hl7.fhir.r4.model.ValueSet) File(java.io.File) FileInputStream(java.io.FileInputStream) JsonParser(org.hl7.fhir.r4.formats.JsonParser) HashSet(java.util.HashSet)

Example 53 with Source

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;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Identifier(org.hl7.fhir.r4.model.Identifier) ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) FileInputStream(java.io.FileInputStream) Date(java.util.Date)

Example 54 with Source

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();
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.dstu2.model.Resource) FileInputStream(java.io.FileInputStream) IParser(org.hl7.fhir.dstu2.formats.IParser) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 55 with Source

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;
    }
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.dstu2.model.Resource) FileInputStream(java.io.FileInputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)125 FileInputStream (java.io.FileInputStream)59 FileOutputStream (java.io.FileOutputStream)55 IOException (java.io.IOException)55 ArrayList (java.util.ArrayList)48 File (java.io.File)45 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)45 TextFile (org.hl7.fhir.utilities.TextFile)41 CSFile (org.hl7.fhir.utilities.CSFile)35 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)35 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)30 XmlParser (org.hl7.fhir.r5.formats.XmlParser)28 Date (java.util.Date)27 HashMap (java.util.HashMap)26 Reference (org.hl7.fhir.r4.model.Reference)26 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)24 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)24 Coding (org.hl7.fhir.r4.model.Coding)24 JsonObject (com.google.gson.JsonObject)22 NotImplementedException (org.apache.commons.lang3.NotImplementedException)22