use of org.hl7.fhir.r4.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;
}
}
use of org.hl7.fhir.r4.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());
}
use of org.hl7.fhir.r4.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());
}
use of org.hl7.fhir.r4.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;
}
use of org.hl7.fhir.r4.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;
}
Aggregations