Search in sources :

Example 21 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project kindling by HL7.

the class ProfileGenerator method generate.

public StructureDefinition generate(ProfiledType pt, List<ValidationMessage> issues) throws Exception {
    StructureDefinition p = new StructureDefinition();
    p.setId(pt.getName());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
    p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType());
    p.setKind(StructureDefinitionKind.COMPLEXTYPE);
    p.setType(pt.getBaseType());
    p.setDerivation(TypeDerivationRule.CONSTRAINT);
    p.setAbstract(false);
    p.setUserData("filename", pt.getName().toLowerCase());
    p.setUserData("path", "datatypes.html#" + pt.getName());
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
    p.setStatus(PublicationStatus.fromCode("active"));
    ToolResourceUtilities.updateUsage(p, "core");
    p.setName(pt.getName());
    p.setPublisher("HL7 FHIR Standard");
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    p.setDescription("Base StructureDefinition for Type " + pt.getName() + ": " + pt.getDefinition());
    p.setDescription(pt.getDefinition());
    p.setDate(genDate.getTime());
    // first, the differential
    p.setName(pt.getName());
    ElementDefinition e = new ElementDefinition();
    String idroot = e.getId();
    e.setPath(pt.getBaseType());
    // e.setSliceName(pt.getName());
    e.setShort(pt.getDefinition());
    e.setDefinition(preProcessMarkdown(pt.getDescription(), "??"));
    e.setMin(0);
    e.setMax("*");
    e.setIsModifier(false);
    String s = definitions.getTLAs().get(pt.getName().toLowerCase());
    if (s == null)
        throw new Exception("There is no TLA for '" + pt.getName() + "' in fhir.ini");
    ElementDefinitionConstraintComponent inv = new ElementDefinitionConstraintComponent();
    inv.setKey(s + "-1");
    inv.setRequirements(pt.getInvariant().getRequirements());
    inv.setSeverity(ConstraintSeverity.ERROR);
    inv.setHuman(pt.getInvariant().getEnglish());
    if (!"n/a".equals(pt.getInvariant().getExpression())) {
        fpUsages.add(new FHIRPathUsage(pt.getName(), pt.getName(), pt.getName(), null, pt.getInvariant().getExpression()));
        inv.setExpression(pt.getInvariant().getExpression());
    }
    inv.setXpath(pt.getInvariant().getXpath());
    e.getConstraint().add(inv);
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    p.getDifferential().getElement().add(e);
    StructureDefinition base = getTypeSnapshot(pt.getBaseType());
    if (!pt.getRules().isEmpty()) {
        // throw new Exception("todo");
        for (String rule : pt.getRules().keySet()) {
            String[] parts = rule.split("\\.");
            String value = pt.getRules().get(rule);
            ElementDefinition er = findElement(p.getDifferential(), pt.getBaseType() + '.' + parts[0]);
            if (er == null) {
                er = new ElementDefinition();
                er.setId(pt.getBaseType() + ':' + p.getId() + '.' + parts[0]);
                er.setPath(pt.getBaseType() + '.' + parts[0]);
                p.getDifferential().getElement().add(er);
            }
            if (parts[1].equals("min"))
                er.setMin(Integer.parseInt(value));
            else if (parts[1].equals("max"))
                er.setMax(value);
            else if (parts[1].equals("defn"))
                er.setDefinition(preProcessMarkdown(value, "er"));
        }
        List<String> errors = new ArrayList<String>();
        new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, true);
        for (String se : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), se, IssueSeverity.WARNING));
    }
    reset();
    // now, the snapshot
    new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType(), "http://hl7.org/fhir", p.getName());
    // for (ElementDefinition ed : p.getSnapshot().getElement())
    // generateElementDefinition(ed, getParent(ed, p.getSnapshot().getElement()));
    p.getDifferential().getElement().get(0).getType().clear();
    p.getSnapshot().getElement().get(0).getType().clear();
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addTag("h2").addText("Data type " + pt.getName());
    div.addTag("p").addText(pt.getDefinition());
    div.addTag("h3").addText("Rule");
    div.addTag("p").addText(pt.getInvariant().getEnglish());
    div.addTag("p").addText("XPath:");
    div.addTag("blockquote").addTag("pre").addText(pt.getInvariant().getXpath());
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    addElementConstraintToSnapshot(p);
    new ProfileUtilities(context, issues, pkp).setIds(p, false);
    checkHasTypes(p);
    return p;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ArrayList(java.util.ArrayList) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) FHIRPathUsage(org.hl7.fhir.definitions.validation.FHIRPathUsage)

Example 22 with Narrative

use of org.hl7.fhir.r4b.model.Narrative 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 23 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7EncounterFHIRConversionTest method test_encounter_PV2segment_missing.

// Test messages with PV1 segment and no PV2 segment, and no serviceProvider provided
// Extension list should be empty and serviceProvider should be null
@ParameterizedTest
@ValueSource(strings = { "ADT^A01", /* "ADT^A02", "ADT^A03", "ADT^A04", */
"ADT^A08", // MDM messages are not tested here because they do not have PV2 segments
"OMP^O09", "ORU^R01", "RDE^O11", "RDE^O25", "VXU^V04" })
void test_encounter_PV2segment_missing(String message) {
    String hl7message = "MSH|^~\\&|WHI_LOAD_GENERATOR|IBM_TORONTO_LAB||IBM|20210330144208|8078780|" + message + "|MSGID_4e1c575f-6c6d-47b2-ab9f-829f20c96db2|T|2.3\n" + "EVN||20210330144208||ADT_EVENT|007|20210309140700\n" + "PID|1||0a8a1752-e336-43e1-bf7f-0c8f6f437ca3^^^MRN||Patient^Load^Generator||19690720|M|Patient^Alias^Generator|AA|9999^^CITY^STATE^ZIP^CAN|COUNTY|(866)845-0900||ENGLISH^ENGLISH|SIN|NONE|Account_0a8a1752-e336-43e1-bf7f-0c8f6f437ca3|123-456-7890|||N|BIRTH PLACE|N||||||N\n" + "PV1||I|^^^^^5642 Hilly Av||||2905^Doctor^Attending^M^IV^^M.D|5755^Doctor^Referring^^Sr|770542^Doctor^Consulting^Jr||||||||59367^Doctor^Admitting||Visit_0a3be81e-144b-4885-9b4e-c5cd33c8f038|||||||||||||||||||||||||20210407191342\n";
    Encounter encounter = ResourceUtils.getEncounter(ftv, hl7message);
    Narrative encText = encounter.getText();
    assertNull(encText.getStatus());
    assertThat(encText.getDiv().getChildNodes()).isEmpty();
    List<Extension> extensionList = encounter.getExtension();
    assertNotNull(extensionList);
    assertThat(extensionList).isEmpty();
    Reference serviceProvider = encounter.getServiceProvider();
    assertThat(serviceProvider).isNotNull();
    assertThat(serviceProvider.getReference()).isNull();
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Narrative(org.hl7.fhir.r4.model.Narrative) Reference(org.hl7.fhir.r4.model.Reference) Encounter(org.hl7.fhir.r4.model.Encounter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7EncounterFHIRConversionTest method test_encounter_visitdescription_missing.

@Test
void test_encounter_visitdescription_missing() {
    String hl7message = "MSH|^~\\&|WHI_LOAD_GENERATOR|IBM_TORONTO_LAB||IBM|20210330144208|8078780|ADT^A01|MSGID_4e1c575f-6c6d-47b2-ab9f-829f20c96db2|T|2.3\n" + "EVN||20210330144208||ADT_EVENT|007|20210309140700\n" + "PID|1||0a8a1752-e336-43e1-bf7f-0c8f6f437ca3^^^MRN||Patient^Load^Generator||19690720|M|Patient^Alias^Generator|AA|9999^^CITY^STATE^ZIP^CAN|COUNTY|(866)845-0900||ENGLISH^ENGLISH|SIN|NONE|Account_0a8a1752-e336-43e1-bf7f-0c8f6f437ca3|123-456-7890|||N|BIRTH PLACE|N||||||N\n" + "PV1||I|^^^Toronto^^5642 Hilly Av||||2905^Doctor^Attending^M^IV^^M.D|5755^Doctor^Referring^^Sr|770542^Doctor^Consulting^Jr||||||||59367^Doctor^Admitting|S|Visit_0a3be81e-144b-4885-9b4e-c5cd33c8f038|||||||||||||||||||||||||20210407191342\n" + "PV2||TEL||||X-5546||20210330144208|20210309||||||||||||n|N|South Shore Hosptial Weymouth^SSHW^^^^^^SSH-WEYMOUTH|||||||||N||||||\n";
    String json = ftv.convert(hl7message, OPTIONS);
    assertThat(json).isNotBlank();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    assertThat(patientResource).hasSize(1);
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    assertThat(encounterResource).hasSize(1);
    Encounter encounter = ResourceUtils.getResourceEncounter(encounterResource.get(0), context);
    // This assertion is to confirm that we do not get a type from PV1.18
    assertThat(encounter.hasType()).isFalse();
    Narrative encText = encounter.getText();
    assertNull(encText.getStatus());
    assertThat(encText.getDiv().getChildNodes()).isEmpty();
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Narrative(org.hl7.fhir.r4.model.Narrative) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Encounter(org.hl7.fhir.r4.model.Encounter) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project cqf-ruler by DBCG.

the class CompositionSectionComponentBuilder method initializeDstu2_1.

@Override
protected void initializeDstu2_1(T theResource) {
    super.initializeDstu2_1(theResource);
    org.hl7.fhir.dstu2016may.model.Composition.SectionComponent section = (org.hl7.fhir.dstu2016may.model.Composition.SectionComponent) theResource;
    section.setTitle(myTitle).setId(getId());
    getEntries().forEach(entry -> section.addEntry(new Reference(entry)));
    if (myText != null) {
        Narrative narrative = new Narrative();
        narrative.setStatusAsString(myText.getStatus());
        narrative.setDivAsString(myText.getText());
        section.setText(narrative);
    }
// no focus
}
Also used : Narrative(org.hl7.fhir.dstu2016may.model.Narrative) Reference(org.hl7.fhir.dstu2016may.model.Reference)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)80 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 IOException (java.io.IOException)34 NotImplementedException (org.apache.commons.lang3.NotImplementedException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 Test (org.junit.Test)22 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)19 ArrayList (java.util.ArrayList)19 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)17 Narrative (org.hl7.fhir.r4.model.Narrative)15 Narrative (org.hl7.fhir.r5.model.Narrative)15 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)14 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)14 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)12 FileNotFoundException (java.io.FileNotFoundException)10 LinkedHashMap (java.util.LinkedHashMap)10