Search in sources :

Example 1 with BundleEntryRequestComponent

use of org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent 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 2 with BundleEntryRequestComponent

use of org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderRequest.

private void renderRequest(XhtmlNode root, BundleEntryRequestComponent request) {
    root.para().addText("Response:");
    StringBuilder b = new StringBuilder();
    b.append(request.getMethod() + " " + request.getUrl() + "\r\n");
    if (request.hasIfNoneMatch())
        b.append("If-None-Match: " + request.getIfNoneMatch() + "\r\n");
    if (request.hasIfModifiedSince())
        b.append("If-Modified-Since: " + request.getIfModifiedSince() + "\r\n");
    if (request.hasIfMatch())
        b.append("If-Match: " + request.getIfMatch() + "\r\n");
    if (request.hasIfNoneExist())
        b.append("If-None-Exist: " + request.getIfNoneExist() + "\r\n");
    root.pre().addText(b.toString());
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 3 with BundleEntryRequestComponent

use of org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderRequest.

private void renderRequest(XhtmlNode root, BundleEntryRequestComponent request) {
    root.para().addText("Response:");
    StringBuilder b = new StringBuilder();
    b.append(request.getMethod() + " " + request.getUrl() + "\r\n");
    if (request.hasIfNoneMatch())
        b.append("If-None-Match: " + request.getIfNoneMatch() + "\r\n");
    if (request.hasIfModifiedSince())
        b.append("If-Modified-Since: " + request.getIfModifiedSince() + "\r\n");
    if (request.hasIfMatch())
        b.append("If-Match: " + request.getIfMatch() + "\r\n");
    if (request.hasIfNoneExist())
        b.append("If-None-Exist: " + request.getIfNoneExist() + "\r\n");
    root.pre().addText(b.toString());
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 4 with BundleEntryRequestComponent

use of org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent in project synthea by synthetichealth.

the class FhirR4 method newEntry.

/**
 * Helper function to create an Entry for the given Resource within the given Bundle. Sets the
 * resourceID to a random UUID, sets the entry's fullURL to that resourceID, and adds the entry to
 * the bundle.
 *
 * @param bundle   The Bundle to add the Entry to
 * @param resource Resource the new Entry should contain
 * @param resourceID The Resource ID to assign
 * @return the created Entry
 */
private static BundleEntryComponent newEntry(Bundle bundle, Resource resource, String resourceID) {
    BundleEntryComponent entry = bundle.addEntry();
    resource.setId(resourceID);
    entry.setFullUrl(getUrlPrefix(resource.fhirType()) + resourceID);
    entry.setResource(resource);
    if (TRANSACTION_BUNDLE) {
        BundleEntryRequestComponent request = entry.getRequest();
        request.setMethod(HTTPVerb.POST);
        String resourceType = resource.getResourceType().name();
        request.setUrl(resourceType);
        if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
            Property prop = entry.getResource().getNamedProperty("identifier");
            if (prop != null && prop.getValues().size() > 0) {
                Identifier identifier = (Identifier) prop.getValues().get(0);
                request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
            }
        }
        entry.setRequest(request);
    }
    return entry;
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) Property(org.hl7.fhir.r4.model.Property)

Example 5 with BundleEntryRequestComponent

use of org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent in project synthea by synthetichealth.

the class FhirStu3 method newEntry.

/**
 * Helper function to create an Entry for the given Resource within the given Bundle.
 * Sets the entry's fullURL to resourceID, and adds the entry to the bundle.
 *
 * @param bundle The Bundle to add the Entry to
 * @param resource Resource the new Entry should contain
 * @param resourceID The Resource ID to assign
 * @return the created Entry
 */
private static BundleEntryComponent newEntry(Bundle bundle, Resource resource, String resourceID) {
    BundleEntryComponent entry = bundle.addEntry();
    resource.setId(resourceID);
    if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
        entry.setFullUrl(resource.fhirType() + "/" + resourceID);
    } else {
        entry.setFullUrl("urn:uuid:" + resourceID);
    }
    entry.setResource(resource);
    if (TRANSACTION_BUNDLE) {
        BundleEntryRequestComponent request = entry.getRequest();
        request.setMethod(HTTPVerb.POST);
        String resourceType = resource.getResourceType().name();
        request.setUrl(resourceType);
        if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
            Property prop = entry.getResource().getNamedProperty("identifier");
            if (prop != null && prop.getValues().size() > 0) {
                Identifier identifier = (Identifier) prop.getValues().get(0);
                request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
            }
        }
        entry.setRequest(request);
    }
    return entry;
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.dstu3.model.Identifier) BundleEntryRequestComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent) Property(org.hl7.fhir.dstu3.model.Property)

Aggregations

BundleEntryRequestComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent)6 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)5 Resource (org.hl7.fhir.r4.model.Resource)3 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)2 Operation (ca.uhn.fhir.rest.annotation.Operation)1 IVersionSpecificBundleFactory (ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Nonnull (javax.annotation.Nonnull)1 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)1 BundleEntryRequestComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent)1 Identifier (org.hl7.fhir.dstu3.model.Identifier)1 Property (org.hl7.fhir.dstu3.model.Property)1 HTTPVerb (org.hl7.fhir.r4.model.Bundle.HTTPVerb)1 HTTPVerbEnumFactory (org.hl7.fhir.r4.model.Bundle.HTTPVerbEnumFactory)1 Enumeration (org.hl7.fhir.r4.model.Enumeration)1 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)1 IdType (org.hl7.fhir.r4.model.IdType)1