Search in sources :

Example 51 with Base

use of org.hl7.fhir.dstu2.model.Base in project kindling by HL7.

the class ProfileGenerator method generateXhtml.

public StructureDefinition generateXhtml() throws Exception {
    uml.getTypes().put("html:div", new UMLPrimitive("html:div"));
    StructureDefinition p = new StructureDefinition();
    p.setId("xhtml");
    p.setUrl("http://hl7.org/fhir/StructureDefinition/xhtml");
    p.setKind(StructureDefinitionKind.PRIMITIVETYPE);
    p.setAbstract(false);
    p.setUserData("filename", "xhtml");
    p.setUserData("path", "narrative.html#xhtml");
    p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element");
    p.setType("xhtml");
    p.setDerivation(TypeDerivationRule.SPECIALIZATION);
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
    ToolResourceUtilities.updateUsage(p, "core");
    p.setName("xhtml");
    p.setPublisher("HL7 FHIR Standard");
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    p.setDescription("Base StructureDefinition for xhtml Type");
    p.setDate(genDate.getTime());
    p.setStatus(PublicationStatus.fromCode("active"));
    Set<String> containedSlices = new HashSet<String>();
    // first, the differential
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    ElementDefinition ec = new ElementDefinition();
    p.getDifferential().getElement().add(ec);
    ec.setId("xhtml");
    ec.setPath("xhtml");
    ec.setShort("Primitive Type " + "xhtml");
    ec.setDefinition("XHTML");
    ec.setMin(0);
    ec.setMax("*");
    ec = new ElementDefinition();
    p.getDifferential().getElement().add(ec);
    ec.setId("xhtml" + ".extension");
    ec.setPath("xhtml" + ".extension");
    ec.setMax("0");
    ec = new ElementDefinition();
    p.getDifferential().getElement().add(ec);
    ec.setId("xhtml" + ".value");
    ec.setPath("xhtml" + ".value");
    ec.addRepresentation(PropertyRepresentation.XHTML);
    ec.setShort("Actual xhtml");
    ec.setDefinition("Actual xhtml");
    ec.setMin(1);
    ec.setMax("1");
    TypeRefComponent t = ec.addType();
    t.setCodeElement(new UriType());
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (d)");
    t.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
    reset();
    // now. the snapshot
    p.setSnapshot(new StructureDefinitionSnapshotComponent());
    ElementDefinition ec1 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ec1);
    ec1.setId("xhtml");
    ec1.setPath("xhtml");
    ec1.setShort("Primitive Type " + "xhtml");
    ec1.setDefinition("XHTML");
    ec1.setMin(0);
    ec1.setMin(0);
    ec1.setMax("*");
    ec1.makeBase();
    generateElementDefinition(p, ec1, null);
    ElementDefinition ec2 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ec2);
    ec2.setId("xhtml.id");
    ec2.setPath("xhtml.id");
    ec2.addRepresentation(PropertyRepresentation.XMLATTR);
    ec2.setDefinition("unique id for the element within a resource (for internal references)");
    ec2.setMin(0);
    ec2.setMax("1");
    ec2.setShort("xml:id (or equivalent in JSON)");
    TypeRefComponent tr = ec2.addType();
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (e)");
    tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
    generateElementDefinition(p, ec2, ec1);
    ec2.makeBase("Element.id", 0, "1");
    ElementDefinition ex = makeExtensionSlice("extension", p, p.getSnapshot(), null, "xhtml");
    ex.setMax("0");
    ElementDefinition ec3 = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    p.getSnapshot().getElement().add(ec3);
    ec3.setId("xhtml.value");
    ec3.setPath("xhtml.value");
    ec3.addRepresentation(PropertyRepresentation.XHTML);
    ec3.setShort("Actual xhtml");
    ec3.setDefinition("Actual xhtml");
    ec3.setMin(1);
    ec3.setMax("1");
    t = ec3.addType();
    t.setCodeElement(new UriType());
    t.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (f)");
    t.setCode(Constants.NS_SYSTEM_TYPE + "String");
    ToolingExtensions.addUriExtension(t, ToolingExtensions.EXT_FHIR_TYPE, "string");
    ec3.makeBase();
    generateElementDefinition(p, ec3, ec);
    containedSlices.clear();
    addElementConstraintToSnapshot(p);
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addText("to do");
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    checkHasTypes(p);
    return p;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionSnapshotComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) UMLPrimitive(org.hl7.fhir.definitions.uml.UMLPrimitive) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet) UriType(org.hl7.fhir.r5.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 52 with Base

use of org.hl7.fhir.dstu2.model.Base in project kindling by HL7.

the class DictHTMLGenerator method invariants.

// 
// 
// for (String id : ids) {
// ElementDefinitionConstraintComponent inv = getConstraint(constraints, id);
// s.append("<tr><td><b title=\"Formal Invariant Identifier\">"+inv.getId()+"</b></td><td>"+presentLevel(inv)+"</td><td>(base)</td><td>"+Utilities.escapeXml(inv.getHuman())+"</td><td><span style=\"font-family: Courier New, monospace\">"+Utilities.escapeXml(inv.getExpression())+"</span>");
// if (inv.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice"))
// s.append("<br/>This is (only) a best practice guideline because: <blockquote>"+page.processMarkdown("best practice guideline", inv.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice-explanation"), prefix)+"</blockquote>");
// s.append("</td></tr>");
// }
// }
private String invariants(Map<String, Invariant> invariants, List<Invariant> stated) throws Exception {
    List<String> done = new ArrayList<String>();
    StringBuilder s = new StringBuilder();
    if (invariants.size() + stated.size() > 0) {
        s.append("<table class=\"dict\">\r\n");
        if (invariants.size() > 0) {
            s.append("<tr><td colspan=\"4\"><b>Defined on this element</b></td></tr>\r\n");
            List<String> ids = new ArrayList<String>();
            for (String id : invariants.keySet()) ids.add(id);
            Collections.sort(ids, new ConstraintsSorter());
            for (String i : ids) {
                Invariant inv = invariants.get(i);
                done.add(inv.getId());
                s.append("<tr><td width=\"60px\"><b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b></td><td>" + presentLevel(inv) + "</td><td>" + Utilities.escapeXml(inv.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>");
                if (!Utilities.noString(inv.getExplanation()))
                    s.append("<br/>This is (only) a best practice guideline because: <blockquote>" + page.processMarkdown("best practice guideline", inv.getExplanation(), prefix) + "</blockquote>");
                s.append("</td></tr>");
            }
        }
        if (stated.size() > 0) {
            s.append("<tr><td colspan=\"4\"><b>Affect this element</b></td></tr>\r\n");
            boolean b = false;
            for (Invariant id : stated) {
                if (!done.contains(id.getId())) {
                    s.append("<tr><td width=\"60px\"><b title=\"Formal Invariant Identifier\">" + id.getId() + "</b></td><td>" + presentLevel(id) + "</td><td>" + Utilities.escapeXml(id.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(id.getExpression()) + "</span>");
                    if (!Utilities.noString(id.getExplanation()))
                        s.append("<br/>This is (only) a best practice guideline because: <blockquote>" + page.processMarkdown("best practice guideline", id.getExplanation(), prefix) + "</blockquote>");
                    s.append("</td></tr>");
                }
            }
        }
        s.append("</table>\r\n");
    }
    return s.toString();
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ArrayList(java.util.ArrayList)

Example 53 with Base

use of org.hl7.fhir.dstu2.model.Base in project kindling by HL7.

the class FhirTurtleGenerator method genBaseMetadata.

/**
 * Emit all the basic atoms that are implicit in the actual model
 */
private void genBaseMetadata() {
    // Declare these for now - they will get filled in more completely later on
    FHIRResource Resource = fact.fhir_class("Resource");
    FHIRResource Element = fact.fhir_class("Element");
    FHIRResource Reference = fact.fhir_class("Reference");
    // Primitive isn't in the actual model - added here
    fact.fhir_class("Primitive").addTitle("Types with only a value").addDefinition("Types with only a value and no additional elements as children").restriction(fact.fhir_restriction(value, RDFS.Literal));
    // A resource can have an optional nodeRole
    FHIRResource treeRoot = fact.fhir_class("treeRoot").addTitle("Class of FHIR base documents");
    FHIRResource nodeRole = fact.fhir_objectProperty("nodeRole").addTitle("Identifies role of subject in context of a given document").domain(Resource).range(treeRoot.resource);
    Resource.restriction(fact.fhir_cardinality_restriction(nodeRole.resource, treeRoot.resource, 0, 1));
    // Any element can have an index to assign order in a list
    FHIRResource index = fact.fhir_dataProperty("index").addTitle("Ordering value for list").domain(Element).range(XSD.nonNegativeInteger);
    Element.restriction(fact.fhir_cardinality_restriction(index.resource, XSD.nonNegativeInteger, 0, 1));
    // References have an optional link
    FHIRResource link = fact.fhir_objectProperty("link").addTitle("URI of a reference");
    Reference.restriction(fact.fhir_cardinality_restriction(link.resource, Resource.resource, 0, 1));
    // XHTML is an XML Literal -- but it isn't recognized by OWL so we use string
    FHIRResource NarrativeDiv = fact.fhir_dataProperty("Narrative.div");
    fact.fhir_class("xhtml", "Primitive").restriction(fact.fhir_cardinality_restriction(value, fact.fhir_datatype(XSD.xstring).resource, 1, 1));
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource)

Example 54 with Base

use of org.hl7.fhir.dstu2.model.Base in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7EventTypeFHIRConversionTest method validate_evn_segment_no_period_override.

@Test
void validate_evn_segment_no_period_override() {
    String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + // + "EVN||||7525||20210319134735|\r"  // TODO, not working with this value
    "EVN||||O||20210319134735|\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||200603150624|200603150625|||||||";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    // Find the encounter from the FHIR bundle.
    List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    // ENV.4 is used for reasonCode
    List<CodeableConcept> reasonCodes = encounter.getReasonCode();
    assertEquals(1, reasonCodes.size());
    CodeableConcept encounterReason = encounter.getReasonCodeFirstRep();
    Coding encounterReasonCoding = encounterReason.getCodingFirstRep();
    // assertThat(encounterReasonCoding.getCode()).isEqualTo("7525");  // TODO, should be able to use user-defined values
    assertThat(encounterReasonCoding.getCode()).isEqualTo("O");
    // EVN.6 is used for start period if there is no PV1.44 but since we have a
    // PV1.44 it should use that not EVN.6
    Base period = encounter.getNamedProperty("period").getValues().get(0);
    String startPeriod = period.getNamedProperty("start").getValues().get(0).toString();
    // And use PV1.45 for end period.
    String endPeriod = period.getNamedProperty("end").getValues().get(0).toString();
    assertThat(startPeriod).isEqualTo("DateTimeType[2006-03-15T06:24:00+08:00]");
    assertThat(endPeriod).isEqualTo("DateTimeType[2006-03-15T06:25:00+08:00]");
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Base(org.hl7.fhir.r4.model.Base) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 55 with Base

use of org.hl7.fhir.dstu2.model.Base in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7EventTypeFHIRConversionTest method validate_evn_segment.

@Test
void validate_evn_segment() {
    String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + // + "EVN||||851||20210319134735|\r"  // TODO, not working with this value
    "EVN||||O||20210319134735|\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||||||||||";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    FHIRContext context = new FHIRContext(true, false);
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    // Find the encounter from the FHIR bundle.
    List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = (Encounter) encounterResource.get(0);
    // ENV.4 is used for reasonCode
    List<CodeableConcept> reasonCodes = encounter.getReasonCode();
    assertEquals(1, reasonCodes.size());
    CodeableConcept encounterReason = encounter.getReasonCodeFirstRep();
    Coding encounterReasonCoding = encounterReason.getCodingFirstRep();
    // assertThat(encounterReasonCoding.getCode()).isEqualTo("851");  // TODO, should be able to use user-defined values
    assertThat(encounterReasonCoding.getCode()).isEqualTo("O");
    // EVN.6 is used for start period (with no end) if there is no PV1.44
    Base period = encounter.getNamedProperty("period").getValues().get(0);
    String startPeriod = period.getNamedProperty("start").getValues().get(0).toString();
    int endPeriodSize = period.getNamedProperty("end").getValues().size();
    assertThat(startPeriod).isEqualTo("DateTimeType[2021-03-19T13:47:35+08:00]");
    assertThat(endPeriodSize).isZero();
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Base(org.hl7.fhir.r4.model.Base) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)324 FHIRException (org.hl7.fhir.exceptions.FHIRException)177 Base (org.hl7.fhir.r4b.model.Base)87 Base (org.hl7.fhir.r5.model.Base)87 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)76 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)70 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)66 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)64 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)55 NotImplementedException (org.apache.commons.lang3.NotImplementedException)47 Base (org.hl7.fhir.dstu2016may.model.Base)47 UcumException (org.fhir.ucum.UcumException)43 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)41 Base (org.hl7.fhir.dstu2.model.Base)40 BigDecimal (java.math.BigDecimal)39 IOException (java.io.IOException)37 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)34 FileOutputStream (java.io.FileOutputStream)29 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)28 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)28