Search in sources :

Example 11 with Meta

use of org.hl7.fhir.r5.model.Meta in project cqf-ruler by DBCG.

the class ProcessMessageProvider method processMessageBundle.

@Operation(name = "$process-message-bundle", idempotent = false)
public Bundle processMessageBundle(HttpServletRequest theServletRequest, RequestDetails theRequestDetails, @OperationParam(name = "content", min = 1, max = 1) @Description(formalDefinition = "The message to process (or, if using asynchronous messaging, it may be a response message to accept)") Bundle theMessageToProcess) {
    logger.info("Validating the Bundle");
    Bundle bundle = theMessageToProcess;
    Boolean errorExists = false;
    OperationOutcome outcome = validateBundle(errorExists, bundle);
    if (!errorExists) {
        IVersionSpecificBundleFactory bundleFactory = this.getFhirContext().newBundleFactory();
        bundle.setId(getUUID());
        bundleFactory.initializeWithBundleResource(bundle);
        Bundle dafBundle = (Bundle) bundleFactory.getResourceBundle();
        dafBundle.setTimestamp(new Date());
        this.getDaoRegistry().getResourceDao(Bundle.class).create(dafBundle);
        MessageHeader messageHeader = null;
        String patientId = null;
        String commId = null;
        List<MessageHeader> headers = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, MessageHeader.class);
        for (MessageHeader mh : headers) {
            messageHeader = mh;
            messageHeader.setId(getUUID());
            Meta meta = messageHeader.getMeta();
            meta.setLastUpdated(new Date());
            messageHeader.setMeta(meta);
        }
        List<IBaseResource> resources = new ArrayList<>();
        List<Patient> patients = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Patient.class);
        for (Patient p : patients) {
            patientId = p.getId();
            p.setId(p.getIdElement().toVersionless());
            resources.add(p);
        }
        List<Bundle> bundles = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Bundle.class);
        for (Bundle b : bundles) {
            patientId = this.processBundle(b, theRequestDetails);
            b.setId(b.getIdElement().toVersionless());
            resources.add(b);
        }
        for (BundleEntryComponent e : bundle.getEntry()) {
            Resource r = e.getResource();
            if (r == null) {
                continue;
            }
            if (r.fhirType().equals("Bundle") || r.fhirType().equals("MessageHeader") || r.fhirType().equals("Patient")) {
                continue;
            }
            r.setId(r.getIdElement().toVersionless());
            resources.add(r);
        }
        if (patientId != null) {
            commId = constructAndSaveCommunication(patientId);
        }
        if (messageHeader == null) {
            messageHeader = constructMessageHeaderResource();
            BundleEntryComponent entryComp = new BundleEntryComponent();
            entryComp.setResource(messageHeader);
            dafBundle.addEntry(entryComp);
        }
        if (commId != null) {
            List<Reference> referenceList = new ArrayList<>();
            Reference commRef = new Reference();
            commRef.setReference("Communication/" + commId);
            referenceList.add(commRef);
            messageHeader.setFocus(referenceList);
        }
        IVersionSpecificBundleFactory newBundleFactory = this.getFhirContext().newBundleFactory();
        newBundleFactory.addResourcesToBundle(resources, BundleTypeEnum.TRANSACTION, theRequestDetails.getFhirServerBase(), null, null);
        Bundle transactionBundle = (Bundle) newBundleFactory.getResourceBundle();
        for (BundleEntryComponent entry : transactionBundle.getEntry()) {
            UriType uri = new UriType(theRequestDetails.getFhirServerBase() + "/" + entry.getResource().fhirType() + "/" + entry.getResource().getIdElement().getIdPart());
            Enumeration<HTTPVerb> method = new Enumeration<>(new HTTPVerbEnumFactory());
            method.setValue(HTTPVerb.PUT);
            entry.setRequest(new BundleEntryRequestComponent(method, uri));
        }
        @SuppressWarnings("unchecked") IFhirSystemDao<Bundle, Meta> fhirSystemDao = this.getDaoRegistry().getSystemDao();
        fhirSystemDao.transaction(theRequestDetails, transactionBundle);
        return dafBundle;
    } else {
        BundleEntryComponent entryComp = new BundleEntryComponent();
        entryComp.setResource(outcome);
        bundle.addEntry(entryComp);
        return bundle;
    }
}
Also used : HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) Meta(org.hl7.fhir.r4.model.Meta) ArrayList(java.util.ArrayList) UriType(org.hl7.fhir.r4.model.UriType) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Enumeration(org.hl7.fhir.r4.model.Enumeration) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IVersionSpecificBundleFactory(ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory) Patient(org.hl7.fhir.r4.model.Patient) HTTPVerbEnumFactory(org.hl7.fhir.r4.model.Bundle.HTTPVerbEnumFactory) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) MessageHeader(org.hl7.fhir.r4.model.MessageHeader) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 12 with Meta

use of org.hl7.fhir.r5.model.Meta in project cqf-ruler by DBCG.

the class ReportProvider method patientReport.

private Parameters.ParametersParameterComponent patientReport(Patient thePatient, Period thePeriod, String serverBase) {
    String patientId = thePatient.getIdElement().getIdPart();
    final Map<IIdType, IAnyResource> bundleEntries = new HashMap<>();
    bundleEntries.put(thePatient.getIdElement(), thePatient);
    ReferenceParam subjectParam = new ReferenceParam(patientId);
    search(MeasureReport.class, Searches.byParam("subject", subjectParam)).getAllResourcesTyped().forEach(measureReport -> {
        if (measureReport.getPeriod().getEnd().before(thePeriod.getStart()) || measureReport.getPeriod().getStart().after(thePeriod.getEnd())) {
            return;
        }
        bundleEntries.putIfAbsent(measureReport.getIdElement(), measureReport);
        getEvaluatedResources(measureReport).values().forEach(resource -> bundleEntries.putIfAbsent(resource.getIdElement(), resource));
    });
    Bundle patientReportBundle = new Bundle();
    patientReportBundle.setMeta(new Meta().addProfile(PATIENT_REPORT_PROFILE_URL));
    patientReportBundle.setType(Bundle.BundleType.COLLECTION);
    patientReportBundle.setTimestamp(new Date());
    patientReportBundle.setId(patientId + "-report");
    patientReportBundle.setIdentifier(new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID().toString()));
    bundleEntries.entrySet().forEach(resource -> patientReportBundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource.getValue()).setFullUrl(Operations.getFullUrl(serverBase, resource.getValue().fhirType(), resource.getValue().getIdElement().getIdPart()))));
    Parameters.ParametersParameterComponent patientParameter = new Parameters.ParametersParameterComponent();
    patientParameter.setResource(patientReportBundle);
    patientParameter.setId(thePatient.getIdElement().getIdPart() + "-report");
    patientParameter.setName("return");
    return patientParameter;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Parameters(org.hl7.fhir.r4.model.Parameters) HashMap(java.util.HashMap) Bundle(org.hl7.fhir.r4.model.Bundle) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) Resource(org.hl7.fhir.r4.model.Resource) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Date(java.util.Date) Identifier(org.hl7.fhir.r4.model.Identifier) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Example 13 with Meta

use of org.hl7.fhir.r5.model.Meta in project cqf-ruler by DBCG.

the class CareGapsProvider method initializeReport.

private void initializeReport(MeasureReport report) {
    if (Strings.isNullOrEmpty(report.getId())) {
        IIdType id = Ids.newId(MeasureReport.class, UUID.randomUUID().toString());
        report.setId(id);
    }
    Reference reporter = new Reference().setReference(crProperties.getMeasureReport().getReporter());
    // TODO: figure out what this extension is for
    // reporter.addExtension(new
    // Extension().setUrl(CARE_GAPS_MEASUREREPORT_REPORTER_EXTENSION));
    report.setReporter(reporter);
    if (report.hasMeta()) {
        report.getMeta().addProfile(CARE_GAPS_REPORT_PROFILE);
    } else {
        report.setMeta(new Meta().addProfile(CARE_GAPS_REPORT_PROFILE));
    }
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Example 14 with Meta

use of org.hl7.fhir.r5.model.Meta in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method testSetReportMeasureToMeasureId__includesMetaVersion__hasHistoryInMeasureOnReport.

@Test
public void testSetReportMeasureToMeasureId__includesMetaVersion__hasHistoryInMeasureOnReport() {
    MeasureReport report = new MeasureReport();
    String measureInput = "{\"resourceType\":\"Measure\",\"id\":\"id1\",\"meta\":{\"versionId\":\"2\"}}";
    Measure measure = fhirParser.parseResource(Measure.class, measureInput);
    CDMMeasureEvaluation.setReportMeasureToMeasureId(report, measure);
    assertEquals("Measure/id1/_history/2", report.getMeasure());
}
Also used : Measure(org.hl7.fhir.r4.model.Measure) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Test(org.junit.Test)

Example 15 with Meta

use of org.hl7.fhir.r5.model.Meta in project summary-care-record-api by NHSDigital.

the class GpSummaryMapper method map.

@SneakyThrows
public List<Resource> map(Node document) {
    var gpSummaryId = xmlUtils.getValueByXPath(document, GP_SUMMARY_ID_XPATH);
    var gpSummaryCodeCode = xmlUtils.getValueByXPath(document, GP_SUMMARY_CODE_CODE_XPATH);
    var gpSummaryCodeDisplayName = xmlUtils.getValueByXPath(document, GP_SUMMARY_CODE_DISPLAY_NAME_XPATH);
    var gpSummaryStatusCode = xmlUtils.getValueByXPath(document, GP_SUMMARY_STATUS_CODE_XPATH);
    var gpSummaryEffectiveTime = parseDate(xmlUtils.getValueByXPath(document, GP_SUMMARY_EFFECTIVE_TIME_XPATH), InstantType.class);
    var authorTime = parseDate(xmlUtils.getValueByXPath(document, GP_SUMMARY_AUTHOR_TIME_XPATH), DateTimeType.class);
    var replacementOfPriorMessageRefIdRoot = xmlUtils.getOptionalValueByXPath(document, REPLACEMENT_OF_PRIOR_MESSAGE_REF_ID_ROOT_XPATH);
    var pertinentRootCreTypeCodeCode = xmlUtils.getValueByXPath(document, PERTINENT_ROOT_CRE_TYPE_CODE_CODE_XPATH);
    var pertinentRootCreTypeCodeDisplayName = xmlUtils.getValueByXPath(document, PERTINENT_ROOT_CRE_TYPE_CODE_DISPLAY_NAME_XPATH);
    var presentationTextValue = xmlUtils.detachOptionalNodeByXPath(document, PRESENTATION_TEXT_VALUE);
    var eventId = xmlUtils.getValueByXPath(document, EVENT_ID_XPATH);
    List<Resource> resources = new ArrayList<>();
    var composition = new Composition();
    composition.setId(eventId);
    composition.setIdentifier(new Identifier().setValue(gpSummaryId).setSystem("https://tools.ietf.org/html/rfc4122"));
    composition.setType(new CodeableConcept().addCoding(new Coding().setCode(gpSummaryCodeCode).setSystem(SNOMED_SYSTEM).setDisplay(gpSummaryCodeDisplayName)));
    composition.setMeta(new Meta().setLastUpdatedElement(gpSummaryEffectiveTime));
    composition.setStatus(mapCompositionStatus(gpSummaryStatusCode));
    composition.setDateElement(authorTime);
    replacementOfPriorMessageRefIdRoot.ifPresent(val -> composition.addRelatesTo(new Composition.CompositionRelatesToComponent().setTarget(new Identifier().setValue(val)).setCode(REPLACES)));
    composition.addCategory(new CodeableConcept().addCoding(new Coding().setCode(pertinentRootCreTypeCodeCode).setSystem(SNOMED_SYSTEM).setDisplay(pertinentRootCreTypeCodeDisplayName)));
    Map<String, List<String>> references = sectionReferences(document);
    presentationTextValue.map(htmlParser::parse).map(Collection::stream).ifPresent(it -> it.forEach(section -> {
        if (section.getTitle() != null && CODED_ENTRY_RESOURCE_MAP.keySet().contains(section.getTitle()) && references.containsKey(section.getTitle())) {
            for (String codedEntryId : references.get(section.getTitle())) {
                section.addEntry(new Reference(CODED_ENTRY_RESOURCE_MAP.get(section.getTitle()) + "/" + codedEntryId));
            }
        }
        composition.addSection(section);
    }));
    resources.add(composition);
    addAuthor(document, resources, composition);
    return resources;
}
Also used : SneakyThrows(lombok.SneakyThrows) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Collection(java.util.Collection) Identifier(org.hl7.fhir.r4.model.Identifier) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Resource(org.hl7.fhir.r4.model.Resource) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Composition(org.hl7.fhir.r4.model.Composition) Reference(org.hl7.fhir.r4.model.Reference) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) ArrayList(java.util.ArrayList) Organization(org.hl7.fhir.r4.model.Organization) List(java.util.List) InstantType(org.hl7.fhir.r4.model.InstantType) Component(org.springframework.stereotype.Component) XmlToFhirMapper.parseDate(uk.nhs.adaptors.scr.mappings.from.hl7.XmlToFhirMapper.parseDate) Coding(org.hl7.fhir.r4.model.Coding) Map(java.util.Map) Node(org.w3c.dom.Node) REPLACES(org.hl7.fhir.r4.model.Composition.DocumentRelationshipType.REPLACES) XmlUtils(uk.nhs.adaptors.scr.utils.XmlUtils) Meta(org.hl7.fhir.r4.model.Meta) Meta(org.hl7.fhir.r4.model.Meta) Composition(org.hl7.fhir.r4.model.Composition) Reference(org.hl7.fhir.r4.model.Reference) Resource(org.hl7.fhir.r4.model.Resource) ArrayList(java.util.ArrayList) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) ArrayList(java.util.ArrayList) List(java.util.List) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) SneakyThrows(lombok.SneakyThrows)

Aggregations

Meta (org.hl7.fhir.r4.model.Meta)40 HashMap (java.util.HashMap)36 Date (java.util.Date)35 Meta (org.hl7.fhir.dstu3.model.Meta)31 IBaseMetaType (org.hl7.fhir.instance.model.api.IBaseMetaType)28 Reference (org.hl7.fhir.r4.model.Reference)26 JsonObject (javax.json.JsonObject)24 Path (javax.ws.rs.Path)24 Produces (javax.ws.rs.Produces)24 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)20 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)18 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)17 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)17 ArrayList (java.util.ArrayList)16 Coding (org.hl7.fhir.r4.model.Coding)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)15 Test (org.junit.jupiter.api.Test)15 Test (org.junit.Test)14 NotImplementedException (org.apache.commons.lang3.NotImplementedException)13 GET (javax.ws.rs.GET)12