Search in sources :

Example 1 with Example

use of org.hl7.fhir.definitions.model.Example in project bunsen by cerner.

the class TestData method newObservation.

/**
 * Returns a FHIR Observation for testing purposes.
 */
public static Observation newObservation() {
    // Observation based on https://www.hl7.org/FHIR/observation-example-bloodpressure.json.html
    Observation observation = new Observation();
    observation.setId("blood-pressure");
    Identifier identifier = observation.addIdentifier();
    identifier.setSystem("urn:ietf:rfc:3986");
    identifier.setValue("urn:uuid:187e0c12-8dd2-67e2-99b2-bf273c878281");
    observation.setStatus(Observation.ObservationStatus.FINAL);
    Quantity quantity = new Quantity();
    quantity.setValue(new java.math.BigDecimal("123.45"));
    quantity.setUnit("mm[Hg]");
    observation.setValue(quantity);
    return observation;
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) Observation(org.hl7.fhir.dstu3.model.Observation) Quantity(org.hl7.fhir.dstu3.model.Quantity)

Example 2 with Example

use of org.hl7.fhir.definitions.model.Example in project bunsen by cerner.

the class TestData method newCondition.

/**
 * Returns a FHIR Condition for testing purposes.
 */
public static Condition newCondition() {
    Condition condition = new Condition();
    // Condition based on example from FHIR:
    // https://www.hl7.org/fhir/condition-example.json.html
    condition.setId("Condition/example");
    condition.setLanguage("en_US");
    // Narrative text
    Narrative narrative = new Narrative();
    narrative.setStatusAsString("generated");
    narrative.setDivAsString("This data was generated for test purposes.");
    XhtmlNode node = new XhtmlNode();
    node.setNodeType(NodeType.Text);
    node.setValue("Severe burn of left ear (Date: 24-May 2012)");
    condition.setText(narrative);
    condition.setSubject(new Reference("Patient/example").setDisplay("Here is a display for you."));
    condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);
    // Condition code
    CodeableConcept code = new CodeableConcept();
    code.addCoding().setSystem("http://snomed.info/sct").setCode("39065001").setDisplay("Severe");
    condition.setSeverity(code);
    // Severity code
    CodeableConcept severity = new CodeableConcept();
    severity.addCoding().setSystem("http://snomed.info/sct").setCode("24484000").setDisplay("Burn of ear").setUserSelected(true);
    condition.setSeverity(severity);
    // Onset date time
    DateTimeType onset = new DateTimeType();
    onset.setValueAsString("2012-05-24");
    condition.setOnset(onset);
    return condition;
}
Also used : Condition(org.hl7.fhir.dstu3.model.Condition) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Narrative(org.hl7.fhir.dstu3.model.Narrative) Reference(org.hl7.fhir.dstu3.model.Reference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 3 with Example

use of org.hl7.fhir.definitions.model.Example in project bunsen by cerner.

the class TestData method newMedRequest.

/**
 * Returns a FHIR medication request for testing purposes.
 */
public static MedicationRequest newMedRequest() {
    MedicationRequest medReq = new MedicationRequest();
    medReq.setId("test-med");
    // Medication code
    CodeableConcept med = new CodeableConcept();
    med.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("582620").setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");
    med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");
    medReq.setMedication(med);
    Annotation annotation = new Annotation();
    annotation.setText("Test medication note.");
    annotation.setAuthor(new Reference("Provider/example").setDisplay("Example provider."));
    medReq.addNote(annotation);
    return medReq;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) Reference(org.hl7.fhir.dstu3.model.Reference) Annotation(org.hl7.fhir.dstu3.model.Annotation) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 4 with Example

use of org.hl7.fhir.definitions.model.Example in project kindling by HL7.

the class Publisher method produceSpecMap.

private void produceSpecMap() throws IOException {
    SpecMapManager spm = new SpecMapManager("hl7.fhir.core", page.getVersion().toCode(), page.getVersion().toCode(), page.getBuildId(), page.getGenDate(), CANONICAL_BASE);
    for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
        if (sd.hasUserData("path")) {
            spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
            spm.target(sd.getUserString("path").replace("\\", "/"));
        }
    }
    for (StructureDefinition sd : page.getWorkerContext().getExtensionDefinitions()) {
        if (sd.hasUserData("path")) {
            spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
            spm.target(sd.getUserString("path").replace("\\", "/"));
        }
    }
    for (String s : page.getCodeSystems().keys()) {
        CodeSystem cs = page.getCodeSystems().get(s);
        if (cs == null && !Utilities.existsInList(s, "http://unitsofmeasure.org", "http://loinc.org", "http://fdasis.nlm.nih.gov", "http://www.nlm.nih.gov/research/umls/rxnorm", "urn:oid:1.2.36.1.2001.1005.17") && !SIDUtilities.isknownCodeSystem(s))
            System.out.println("No code system resource found for " + s);
    }
    for (CodeSystem cs : page.getCodeSystems().getList()) {
        if (cs != null && cs.hasUserData("path")) {
            spm.path(cs.getUrl(), cs.getUserString("path").replace("\\", "/"));
            spm.target(cs.getUserString("path").replace("\\", "/"));
        }
    }
    for (ValueSet vs : page.getValueSets().getList()) {
        if (vs.hasUserData("path")) {
            spm.path(vs.getUrl(), vs.getUserString("path").replace("\\", "/"));
            spm.target(vs.getUserString("path").replace("\\", "/"));
        }
    }
    for (ConceptMap cm : page.getConceptMaps().getList()) {
        if (cm.hasUserData("path")) {
            spm.path(cm.getUrl(), cm.getUserString("path").replace("\\", "/"));
            spm.target(cm.getUserString("path").replace("\\", "/"));
        }
    }
    for (String s : page.getDefinitions().getPageTitles().keySet()) {
        spm.page(s, page.getDefinitions().getPageTitles().get(s));
    }
    for (String n : page.getIni().getPropertyNames("pages")) {
        spm.target(n);
    }
    for (ResourceDefn rd : page.getDefinitions().getResources().values()) {
        spm.target(rd.getName().toLowerCase() + ".html");
        spm.target(rd.getName().toLowerCase() + "-definitions.html");
        spm.target(rd.getName().toLowerCase() + "-mappings.html");
        spm.target(rd.getName().toLowerCase() + "-examples.html");
        spm.target(rd.getName().toLowerCase() + "-profiles.html");
        if (!rd.getOperations().isEmpty())
            spm.target(rd.getName().toLowerCase() + "-operations.html");
        for (Example ex : rd.getExamples()) {
            ImplementationGuideDefn ig = ex.getIg() == null ? null : page.getDefinitions().getIgs().get(ex.getIg());
            String prefix = (ig == null || ig.isCore()) ? "" : ig.getCode() + "/";
            spm.target(prefix + ex.getTitle() + ".html");
        }
    }
    for (Profile p : page.getDefinitions().getPackList()) {
        spm.target(p.getId() + ".html");
    }
    // for (String url : page.getDefinitions().getMapTypes().keySet()) {
    // spm.map(url, page.getDefinitions().getMapTypes().get(url).getPreamble());
    // }
    scanForImages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
    scanForPages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
    for (String url : page.getDefinitions().getRedirectList().keySet()) {
        // http://hl7.org/fhir/ = 20 chars
        spm.target(url.substring(20));
    }
    spm.save(page.getFolders().dstDir + "spec.internals");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSet(org.hl7.fhir.r5.model.ValueSet) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Profile(org.hl7.fhir.definitions.model.Profile)

Example 5 with Example

use of org.hl7.fhir.definitions.model.Example in project kindling by HL7.

the class Publisher method generateCodeSystemRegistry.

private void generateCodeSystemRegistry() throws FileNotFoundException, IOException, Exception {
    XmlParser xml = new XmlParser();
    xml.setOutputStyle(OutputStyle.PRETTY);
    Bundle bnd = (Bundle) xml.parse(new CSFileInputStream(Utilities.path(page.getFolders().srcDir, "namingsystem", "namingsystem-terminologies.xml")));
    for (BundleEntryComponent entry : bnd.getEntry()) {
        NamingSystem ns = (NamingSystem) entry.getResource();
        entry.setFullUrl("http://hl7.org/fhir/NamingSystem/" + ns.getId());
        String url = null;
        for (NamingSystemUniqueIdComponent t : ns.getUniqueId()) {
            if (t.getType() == NamingSystemIdentifierType.URI)
                url = t.getValue();
        }
        if (url != null) {
            if (url.startsWith("http://hl7.org/fhir"))
                page.getDefinitions().addNs(url, "System " + ns.getName(), "terminologies-systems.html#" + url);
            page.getDefinitions().addNs(entry.getFullUrl(), ns.getId(), "terminologies-systems.html#" + url);
        }
    }
    List<String> names = new ArrayList<String>();
    Set<String> urls = new HashSet<>();
    names.addAll(page.getCodeSystems().keys());
    Collections.sort(names);
    for (String n : names) {
        CodeSystem cs = page.getCodeSystems().get(n);
        if (cs != null && !urls.contains(cs.getUrl()) && cs.hasUrl() && !cs.getUrl().startsWith("http://terminology.hl7.org")) {
            urls.add(cs.getUrl());
            if (cs.hasName()) {
                NamingSystem ns = new NamingSystem();
                ns.setId(cs.getId());
                ns.setName(cs.getName());
                ns.setStatus(cs.getStatus());
                if (!ns.hasStatus())
                    ns.setStatus(PublicationStatus.DRAFT);
                ns.setKind(NamingSystemType.CODESYSTEM);
                ns.setPublisher(cs.getPublisher());
                for (ContactDetail c : cs.getContact()) {
                    ContactDetail nc = ns.addContact();
                    nc.setName(c.getName());
                    for (ContactPoint cc : c.getTelecom()) {
                        nc.getTelecom().add(cc);
                    }
                }
                ns.setDate(cs.getDate());
                if (!ns.hasDate())
                    ns.setDate(page.getGenDate().getTime());
                ns.setDescription(cs.getDescription());
                ns.addUniqueId().setType(NamingSystemIdentifierType.URI).setValue(cs.getUrl()).setPreferred(true);
                String oid = CodeSystemUtilities.getOID(cs);
                if (oid != null) {
                    if (oid.startsWith("urn:oid:"))
                        oid = oid.substring(8);
                    ns.addUniqueId().setType(NamingSystemIdentifierType.OID).setValue(oid).setPreferred(false);
                }
                ns.setUserData("path", cs.getUserData("path"));
                bnd.addEntry().setResource(ns).setFullUrl("http://hl7.org/fhir/" + ns.fhirType() + "/" + ns.getId());
            }
        }
    }
    xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.xml")), bnd);
    cloneToXhtml("namingsystem-terminologies", "Terminology Registry", false, "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
    xml.setOutputStyle(OutputStyle.CANONICAL);
    xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.xml")), bnd);
    JsonParser json = new JsonParser();
    json.setOutputStyle(OutputStyle.PRETTY);
    json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), bnd);
    jsonToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
    json.setOutputStyle(OutputStyle.CANONICAL);
    json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.json")), bnd);
    RdfParser rdf = new RdfParser();
    rdf.setOutputStyle(OutputStyle.PRETTY);
    rdf.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), bnd);
    ttlToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"grid\">\r\n");
    b.append(" <tr>");
    b.append("<td><b>Name</b></td>");
    b.append("<td><b>Uri</b></td>");
    b.append("<td><b>OID</b></td>");
    b.append("</tr>\r\n");
    for (BundleEntryComponent entry : bnd.getEntry()) {
        NamingSystem ns = (NamingSystem) entry.getResource();
        String uri = "";
        String oid = "";
        for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
            if (id.getType() == NamingSystemIdentifierType.URI)
                uri = id.getValue();
            if (id.getType() == NamingSystemIdentifierType.OID)
                oid = id.getValue();
        }
        String link = "terminologies-systems.html#" + uri;
        if (ns.getUserData("path") != null)
            link = ns.getUserString("path");
        b.append(" <tr>");
        b.append("<td><a href=\"" + link + "\">" + Utilities.escapeXml(ns.getName()) + "</a></td>");
        b.append("<td>" + Utilities.escapeXml(uri) + "</td>");
        b.append("<td>" + Utilities.escapeXml(oid) + "</td>");
        b.append("</tr>\r\n");
    }
    b.append("</table>\r\n");
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", b.toString()).replace("<%example-usage%>", "");
    html = page.processPageIncludes("namingsystem-terminologies.html", html, "resource-instance:NamingSystem", null, bnd, null, "Example", null, null, page.getDefinitions().getWorkgroups().get("fhir"));
    TextFile.stringToFile(html, page.getFolders().dstDir + "namingsystem-terminologies.html");
    cachePage("namingsystem-terminologies.html", html, "Registered Code Systems", false);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) NamingSystemUniqueIdComponent(org.hl7.fhir.r5.model.NamingSystem.NamingSystemUniqueIdComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) Bundle(org.hl7.fhir.r5.model.Bundle) ArrayList(java.util.ArrayList) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) NamingSystem(org.hl7.fhir.r5.model.NamingSystem) FileOutputStream(java.io.FileOutputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) HashSet(java.util.HashSet) JsonParser(org.hl7.fhir.r5.formats.JsonParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Aggregations

Test (org.junit.jupiter.api.Test)222 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)196 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 IOException (java.io.IOException)27 Example (org.hl7.fhir.definitions.model.Example)27 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 ArrayList (java.util.ArrayList)22 FileNotFoundException (java.io.FileNotFoundException)19 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)17 Test (org.junit.Test)17 File (java.io.File)15 CSFile (org.hl7.fhir.utilities.CSFile)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 TransformerException (javax.xml.transform.TransformerException)14 OperationExample (org.hl7.fhir.definitions.model.Operation.OperationExample)14 Profile (org.hl7.fhir.definitions.model.Profile)14 XmlParser (org.hl7.fhir.r5.formats.XmlParser)14 HashMap (java.util.HashMap)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)13 FileOutputStream (java.io.FileOutputStream)12