Search in sources :

Example 1 with ProvenanceAgentComponent

use of org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent in project synthea by synthetichealth.

the class FhirR4 method provenance.

/**
 * Create a Provenance entry at the end of this Bundle that
 * targets all the entries in the Bundle.
 *
 * @param bundle The finished complete Bundle.
 * @param person The person.
 * @param stopTime The time the simulation stopped.
 * @return BundleEntryComponent containing a Provenance resource.
 */
private static BundleEntryComponent provenance(Bundle bundle, Person person, long stopTime) {
    Provenance provenance = new Provenance();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-provenance");
        provenance.setMeta(meta);
    }
    for (BundleEntryComponent entry : bundle.getEntry()) {
        provenance.addTarget(new Reference(entry.getFullUrl()));
    }
    provenance.setRecorded(new Date(stopTime));
    // Provenance sources...
    int index = person.record.encounters.size() - 1;
    Clinician clinician = null;
    while (index >= 0 && clinician == null) {
        clinician = person.record.encounters.get(index).clinician;
        index--;
    }
    String clinicianDisplay = null;
    if (clinician != null) {
        clinicianDisplay = clinician.getFullname();
    }
    String practitionerFullUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirNpiSearchUrl(clinician) : findPractitioner(clinician, bundle);
    Provider providerOrganization = person.record.provider;
    if (providerOrganization == null) {
        providerOrganization = person.getProvider(EncounterType.WELLNESS, stopTime);
    }
    String organizationFullUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirSearchUrl("Organization", providerOrganization.getResourceID()) : findProviderUrl(providerOrganization, bundle);
    // Provenance Author...
    ProvenanceAgentComponent agent = provenance.addAgent();
    agent.setType(mapCodeToCodeableConcept(new Code("http://terminology.hl7.org/CodeSystem/provenance-participant-type", "author", "Author"), null));
    agent.setWho(new Reference().setReference(practitionerFullUrl).setDisplay(clinicianDisplay));
    agent.setOnBehalfOf(new Reference().setReference(organizationFullUrl).setDisplay(providerOrganization.name));
    // Provenance Transmitter...
    agent = provenance.addAgent();
    agent.setType(mapCodeToCodeableConcept(new Code("http://hl7.org/fhir/us/core/CodeSystem/us-core-provenance-participant-type", "transmitter", "Transmitter"), null));
    agent.setWho(new Reference().setReference(practitionerFullUrl).setDisplay(clinicianDisplay));
    agent.setOnBehalfOf(new Reference().setReference(organizationFullUrl).setDisplay(providerOrganization.name));
    return newEntry(person, bundle, provenance);
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) ProvenanceAgentComponent(org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent) Provenance(org.hl7.fhir.r4.model.Provenance) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Clinician(org.mitre.synthea.world.agents.Clinician) Provider(org.mitre.synthea.world.agents.Provider)

Example 2 with ProvenanceAgentComponent

use of org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method execute.

private void execute(String source) throws IOException {
    List<CanonicalResourceAnalysis> list = new ArrayList<>();
    System.out.println("Loading UTG");
    loadFromSource(list, new File(source));
    Map<String, CanonicalResource> r2 = loadPackageR2("hl7.fhir.r2.core");
    Map<String, CanonicalResource> r3 = loadPackageR3("hl7.fhir.r3.core");
    Map<String, CanonicalResource> r4 = loadPackageR4("hl7.fhir.r4.core");
    System.out.println("Processing");
    for (CanonicalResourceAnalysis cr : list) {
        cr.analyse(r2, r3, r4);
    }
    Bundle b = (Bundle) new JsonParser().parse(new FileInputStream("C:\\work\\org.hl7.fhir.igs\\UTG\\input\\sourceOfTruth\\history\\utgrel1hx-1-0-6.json"));
    System.out.println("Summary");
    for (CanonicalResourceAnalysis cr : list) {
        System.out.println(cr.summary());
        Provenance p = new Provenance();
        b.addEntry().setResource(p).setFullUrl("http://terminology.hl7.org/fhir/Provenance/fhir-1.0.51-" + cr.getId());
        p.setId("hx-fhir-1.0.51-" + cr.getId());
        p.addTarget().setReference(cr.fhirType() + "/" + cr.getId());
        p.getOccurredPeriod().setEnd(runTime, TemporalPrecisionEnum.DAY);
        p.setRecorded(runTime);
        p.addAuthorization().getConcept().setText("Reset Version after migration to UTG").addCoding("http://terminology.hl7.org/CodeSystem/v3-ActReason", "METAMGT", null);
        p.getActivity().addCoding("http://terminology.hl7.org/CodeSystem/v3-DataOperation", "UPDATE", null);
        ProvenanceAgentComponent pa = p.addAgent();
        pa.getType().addCoding("http://terminology.hl7.org/CodeSystem/provenance-participant-type", "author", null);
        pa.getWho().setDisplay("Grahame Grieve");
        pa = p.addAgent();
        pa.getType().addCoding("http://terminology.hl7.org/CodeSystem/provenance-participant-type", "custodian", null);
        pa.getWho().setDisplay("Vocabulary WG");
        CanonicalResource res = cr.resource;
        res.setVersion(cr.recommendation);
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(cr.filename), res);
    }
    System.out.println();
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("C:\\work\\org.hl7.fhir.igs\\UTG\\input\\sourceOfTruth\\history\\utgrel1hx-1-0-6.json"), b);
    System.out.println("Done");
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileInputStream(java.io.FileInputStream) ProvenanceAgentComponent(org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent) FileOutputStream(java.io.FileOutputStream) File(java.io.File) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 3 with ProvenanceAgentComponent

use of org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent in project org.hl7.fhir.core by hapifhir.

the class UTGCaseSensitivePopulator method processCodeSystem.

private boolean processCodeSystem(CodeSystem cs, Bundle bundle, Date d, Date dt) {
    if (cs.hasCaseSensitive()) {
        return false;
    }
    if (!cs.getUrl().startsWith("http://terminology.hl7.org") || cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
        return false;
    }
    cs.setCaseSensitive(true);
    Provenance p = new Provenance();
    p.setId("cs-286-" + cs.getId());
    p.addTarget().setReference("CodeSystem/" + cs.getId());
    p.setOccurred(new Period());
    p.getOccurredPeriod().setEnd(d);
    p.setRecorded(dt);
    p.addReason().setText("Populate Missing caseSensitive property;UP-286").addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-ActReason").setCode("METAMGT");
    p.getActivity().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-DataOperation").setCode("UPDATE");
    ProvenanceAgentComponent agent = p.addAgent();
    agent.getType().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/provenance-participant-type").setCode("author");
    agent.getWho().setDisplay("Grahame Grieve");
    agent = p.addAgent();
    agent.getType().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/provenance-participant-type").setCode("custodian");
    agent.getWho().setDisplay("Vocabulary WG");
    bundle.addEntry().setFullUrl("http://terminology.hl7.org/fhir/Provenance/cs-286-" + cs.getId()).setResource(p);
    return true;
}
Also used : ProvenanceAgentComponent(org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent) Provenance(org.hl7.fhir.r4.model.Provenance) Period(org.hl7.fhir.r4.model.Period)

Example 4 with ProvenanceAgentComponent

use of org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent in project org.hl7.fhir.core by hapifhir.

the class ProvenanceRenderer method render.

public boolean render(XhtmlNode x, Provenance prv) throws UnsupportedEncodingException, IOException {
    boolean hasExtensions = false;
    if (!prv.getTarget().isEmpty()) {
        if (prv.getTarget().size() == 1) {
            XhtmlNode p = x.para();
            p.tx("Provenance for ");
            renderReference(prv, p, prv.getTargetFirstRep());
        } else {
            x.para().tx("Provenance for:");
            XhtmlNode ul = x.ul();
            for (Reference ref : prv.getTarget()) {
                renderReference(prv, ul.li(), ref);
            }
        }
    }
    // summary table
    x.para().tx("Summary");
    XhtmlNode t = x.table("grid");
    XhtmlNode tr;
    if (prv.hasOccurred()) {
        tr = t.tr();
        tr.td().tx("Occurrence");
        if (prv.hasOccurredPeriod()) {
            renderPeriod(tr.td(), prv.getOccurredPeriod());
        } else {
            renderDateTime(tr.td(), prv.getOccurredDateTimeType());
        }
    }
    if (prv.hasRecorded()) {
        tr = t.tr();
        tr.td().tx("Recorded");
        tr.td().addText(prv.getRecordedElement().toHumanDisplay());
    }
    if (prv.hasPolicy()) {
        tr = t.tr();
        tr.td().tx("Policy");
        if (prv.getPolicy().size() == 1) {
            renderUri(tr.td(), prv.getPolicy().get(0));
        } else {
            XhtmlNode ul = tr.td().ul();
            for (UriType u : prv.getPolicy()) {
                renderUri(ul.li(), u);
            }
        }
    }
    if (prv.hasLocation()) {
        tr = t.tr();
        tr.td().tx("Location");
        renderReference(prv, tr.td(), prv.getLocation());
    }
    if (prv.hasActivity()) {
        tr = t.tr();
        tr.td().tx("Activity");
        renderCodeableConcept(tr.td(), prv.getActivity(), false);
    }
    boolean hasType = false;
    boolean hasRole = false;
    boolean hasOnBehalfOf = false;
    for (ProvenanceAgentComponent a : prv.getAgent()) {
        hasType = hasType || a.hasType();
        hasRole = hasRole || a.hasRole();
        hasOnBehalfOf = hasOnBehalfOf || a.hasOnBehalfOf();
    }
    x.para().b().tx("Agents");
    t = x.table("grid");
    tr = t.tr();
    if (hasType) {
        tr.td().b().tx("Type");
    }
    if (hasRole) {
        tr.td().b().tx("Role");
    }
    tr.td().b().tx("who");
    if (hasOnBehalfOf) {
        tr.td().b().tx("On Behalf Of");
    }
    for (ProvenanceAgentComponent a : prv.getAgent()) {
        tr = t.tr();
        if (hasType) {
            if (a.hasType()) {
                renderCodeableConcept(tr.td(), a.getType(), false);
            } else {
                tr.td();
            }
        }
        if (hasRole) {
            if (a.hasRole()) {
                if (a.getRole().size() == 1) {
                    renderCodeableConcept(tr.td(), a.getType(), false);
                } else {
                    XhtmlNode ul = tr.td().ul();
                    for (CodeableConcept cc : a.getRole()) {
                        renderCodeableConcept(ul.li(), cc, false);
                    }
                }
            } else {
                tr.td();
            }
        }
        if (a.hasWho()) {
            renderReference(prv, tr.td(), a.getWho());
        } else {
            tr.td();
        }
        if (hasOnBehalfOf) {
            if (a.hasOnBehalfOf()) {
                renderReference(prv, tr.td(), a.getOnBehalfOf());
            } else {
                tr.td();
            }
        }
    }
    return hasExtensions;
}
Also used : ProvenanceAgentComponent(org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent) Reference(org.hl7.fhir.r5.model.Reference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.r5.model.UriType) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 5 with ProvenanceAgentComponent

use of org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent in project org.hl7.fhir.core by hapifhir.

the class ProvenanceRenderer method render.

public boolean render(XhtmlNode x, Provenance prv) throws UnsupportedEncodingException, IOException {
    boolean hasExtensions = false;
    if (!prv.getTarget().isEmpty()) {
        if (prv.getTarget().size() == 1) {
            XhtmlNode p = x.para();
            p.tx("Provenance for ");
            renderReference(prv, p, prv.getTargetFirstRep());
        } else {
            x.para().tx("Provenance for:");
            XhtmlNode ul = x.ul();
            for (Reference ref : prv.getTarget()) {
                renderReference(prv, ul.li(), ref);
            }
        }
    }
    // summary table
    x.para().tx("Summary");
    XhtmlNode t = x.table("grid");
    XhtmlNode tr;
    if (prv.hasOccurred()) {
        tr = t.tr();
        tr.td().tx("Occurrence");
        if (prv.hasOccurredPeriod()) {
            renderPeriod(tr.td(), prv.getOccurredPeriod());
        } else {
            renderDateTime(tr.td(), prv.getOccurredDateTimeType());
        }
    }
    if (prv.hasRecorded()) {
        tr = t.tr();
        tr.td().tx("Recorded");
        tr.td().addText(prv.getRecordedElement().toHumanDisplay());
    }
    if (prv.hasPolicy()) {
        tr = t.tr();
        tr.td().tx("Policy");
        if (prv.getPolicy().size() == 1) {
            renderUri(tr.td(), prv.getPolicy().get(0));
        } else {
            XhtmlNode ul = tr.td().ul();
            for (UriType u : prv.getPolicy()) {
                renderUri(ul.li(), u);
            }
        }
    }
    if (prv.hasLocation()) {
        tr = t.tr();
        tr.td().tx("Location");
        renderReference(prv, tr.td(), prv.getLocation());
    }
    if (prv.hasActivity()) {
        tr = t.tr();
        tr.td().tx("Activity");
        renderCodeableConcept(tr.td(), prv.getActivity(), false);
    }
    boolean hasType = false;
    boolean hasRole = false;
    boolean hasOnBehalfOf = false;
    for (ProvenanceAgentComponent a : prv.getAgent()) {
        hasType = hasType || a.hasType();
        hasRole = hasRole || a.hasRole();
        hasOnBehalfOf = hasOnBehalfOf || a.hasOnBehalfOf();
    }
    x.para().b().tx("Agents");
    t = x.table("grid");
    tr = t.tr();
    if (hasType) {
        tr.td().b().tx("Type");
    }
    if (hasRole) {
        tr.td().b().tx("Role");
    }
    tr.td().b().tx("who");
    if (hasOnBehalfOf) {
        tr.td().b().tx("On Behalf Of");
    }
    for (ProvenanceAgentComponent a : prv.getAgent()) {
        tr = t.tr();
        if (hasType) {
            if (a.hasType()) {
                renderCodeableConcept(tr.td(), a.getType(), false);
            } else {
                tr.td();
            }
        }
        if (hasRole) {
            if (a.hasRole()) {
                if (a.getRole().size() == 1) {
                    renderCodeableConcept(tr.td(), a.getType(), false);
                } else {
                    XhtmlNode ul = tr.td().ul();
                    for (CodeableConcept cc : a.getRole()) {
                        renderCodeableConcept(ul.li(), cc, false);
                    }
                }
            } else {
                tr.td();
            }
        }
        if (a.hasWho()) {
            renderReference(prv, tr.td(), a.getWho());
        } else {
            tr.td();
        }
        if (hasOnBehalfOf) {
            if (a.hasOnBehalfOf()) {
                renderReference(prv, tr.td(), a.getOnBehalfOf());
            } else {
                tr.td();
            }
        }
    }
    return hasExtensions;
}
Also used : ProvenanceAgentComponent(org.hl7.fhir.r4b.model.Provenance.ProvenanceAgentComponent) Reference(org.hl7.fhir.r4b.model.Reference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.r4b.model.UriType) CodeableConcept(org.hl7.fhir.r4b.model.CodeableConcept)

Aggregations

Provenance (org.hl7.fhir.r4.model.Provenance)2 ProvenanceAgentComponent (org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent)2 ProvenanceAgentComponent (org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent)2 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Date (java.util.Date)1 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)1 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)1 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)1 Meta (org.hl7.fhir.r4.model.Meta)1 Period (org.hl7.fhir.r4.model.Period)1 Reference (org.hl7.fhir.r4.model.Reference)1 CodeableConcept (org.hl7.fhir.r4b.model.CodeableConcept)1 ProvenanceAgentComponent (org.hl7.fhir.r4b.model.Provenance.ProvenanceAgentComponent)1 Reference (org.hl7.fhir.r4b.model.Reference)1 UriType (org.hl7.fhir.r4b.model.UriType)1 JsonParser (org.hl7.fhir.r5.formats.JsonParser)1 XmlParser (org.hl7.fhir.r5.formats.XmlParser)1