Search in sources :

Example 1 with EntryRequest

use of ca.uhn.fhir.model.dstu2.resource.Bundle.EntryRequest in project synthea by synthetichealth.

the class FhirDstu2 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 resourceID to use.
 * @return the created Entry
 */
private static Entry newEntry(Bundle bundle, BaseResource resource, String resourceID) {
    Entry entry = bundle.addEntry();
    resource.setId(resourceID);
    if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
        entry.setFullUrl(resource.getResourceName() + "/" + resourceID);
    } else {
        entry.setFullUrl("urn:uuid:" + resourceID);
    }
    entry.setResource(resource);
    if (TRANSACTION_BUNDLE) {
        EntryRequest request = entry.getRequest();
        request.setMethod(HTTPVerbEnum.POST);
        String resourceType = resource.getResourceName();
        request.setUrl(resourceType);
        if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
            IdentifierDt identifier = null;
            switch(resourceType) {
                case "Practitioner":
                    Practitioner practitioner = (Practitioner) resource;
                    identifier = practitioner.getIdentifierFirstRep();
                    break;
                case "Organization":
                    Organization organization = (Organization) resource;
                    identifier = organization.getIdentifierFirstRep();
                    break;
                default:
                    break;
            }
            if (identifier != null) {
                request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
            }
        }
        entry.setRequest(request);
    }
    return entry;
}
Also used : Practitioner(ca.uhn.fhir.model.dstu2.resource.Practitioner) EntryRequest(ca.uhn.fhir.model.dstu2.resource.Bundle.EntryRequest) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) IdentifierDt(ca.uhn.fhir.model.dstu2.composite.IdentifierDt) Organization(ca.uhn.fhir.model.dstu2.resource.Organization)

Aggregations

IdentifierDt (ca.uhn.fhir.model.dstu2.composite.IdentifierDt)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 EntryRequest (ca.uhn.fhir.model.dstu2.resource.Bundle.EntryRequest)1 Organization (ca.uhn.fhir.model.dstu2.resource.Organization)1 Practitioner (ca.uhn.fhir.model.dstu2.resource.Practitioner)1