Search in sources :

Example 71 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project hapi-fhir-jpaserver-starter by hapifhir.

the class ExampleServerR4IT method testBatchPutWithIdenticalTags.

@Test
public void testBatchPutWithIdenticalTags() {
    String batchPuts = "{\n" + "\t\"resourceType\": \"Bundle\",\n" + "\t\"id\": \"patients\",\n" + "\t\"type\": \"batch\",\n" + "\t\"entry\": [\n" + "\t\t{\n" + "\t\t\t\"request\": {\n" + "\t\t\t\t\"method\": \"PUT\",\n" + "\t\t\t\t\"url\": \"Patient/pat-1\"\n" + "\t\t\t},\n" + "\t\t\t\"resource\": {\n" + "\t\t\t\t\"resourceType\": \"Patient\",\n" + "\t\t\t\t\"id\": \"pat-1\",\n" + "\t\t\t\t\"meta\": {\n" + "\t\t\t\t\t\"tag\": [\n" + "\t\t\t\t\t\t{\n" + "\t\t\t\t\t\t\t\"system\": \"http://mysystem.org\",\n" + "\t\t\t\t\t\t\t\"code\": \"value2\"\n" + "\t\t\t\t\t\t}\n" + "\t\t\t\t\t]\n" + "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"fullUrl\": \"/Patient/pat-1\"\n" + "\t\t},\n" + "\t\t{\n" + "\t\t\t\"request\": {\n" + "\t\t\t\t\"method\": \"PUT\",\n" + "\t\t\t\t\"url\": \"Patient/pat-2\"\n" + "\t\t\t},\n" + "\t\t\t\"resource\": {\n" + "\t\t\t\t\"resourceType\": \"Patient\",\n" + "\t\t\t\t\"id\": \"pat-2\",\n" + "\t\t\t\t\"meta\": {\n" + "\t\t\t\t\t\"tag\": [\n" + "\t\t\t\t\t\t{\n" + "\t\t\t\t\t\t\t\"system\": \"http://mysystem.org\",\n" + "\t\t\t\t\t\t\t\"code\": \"value2\"\n" + "\t\t\t\t\t\t}\n" + "\t\t\t\t\t]\n" + "\t\t\t\t}\n" + "\t\t\t},\n" + "\t\t\t\"fullUrl\": \"/Patient/pat-2\"\n" + "\t\t}\n" + "\t]\n" + "}";
    Bundle bundle = FhirContext.forR4().newJsonParser().parseResource(Bundle.class, batchPuts);
    ourClient.transaction().withBundle(bundle).execute();
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 72 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType 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 73 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType 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)

Example 74 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project cqf-ruler by DBCG.

the class FhirMeasureBundler method bundle.

// Adds the resources returned from the given expressions to a bundle
@SuppressWarnings("unchecked")
public Bundle bundle(Context context, String... expressionNames) {
    Bundle bundle = new Bundle();
    bundle.setType(Bundle.BundleType.COLLECTION);
    for (String expressionName : expressionNames) {
        Object result = context.resolveExpressionRef(expressionName).evaluate(context);
        for (Object element : (Iterable<Object>) result) {
            Bundle.BundleEntryComponent entry = new Bundle.BundleEntryComponent();
            entry.setResource((Resource) element);
            // The null check for resourceType handles Lists, which don't have a resource
            // type.
            entry.setFullUrl((((Resource) element).getIdElement().getResourceType() != null ? (((Resource) element).getIdElement().getResourceType() + "/") : "") + ((Resource) element).getIdElement().getIdPart());
            bundle.getEntry().add(entry);
        }
    }
    return bundle;
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Resource(org.hl7.fhir.dstu3.model.Resource)

Example 75 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project cqf-ruler by DBCG.

the class FhirMeasureBundler method bundle.

public Bundle bundle(Iterable<Resource> resources, String fhirServerBase) {
    Bundle bundle = new Bundle();
    bundle.setType(Bundle.BundleType.COLLECTION);
    for (Resource resource : resources) {
        Bundle.BundleEntryComponent entry = new Bundle.BundleEntryComponent();
        entry.setResource(resource);
        // The null check for resourceType handles Lists, which don't have a resource
        // type.
        entry.setFullUrl(fhirServerBase + (resource.getIdElement().getResourceType() != null ? (resource.getIdElement().getResourceType() + "/") : "") + resource.getIdElement().getIdPart());
        bundle.getEntry().add(entry);
    }
    return bundle;
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Resource(org.hl7.fhir.dstu3.model.Resource)

Aggregations

JsonElement (com.google.gson.JsonElement)33 HashSet (java.util.HashSet)26 Bundle (org.hl7.fhir.r4.model.Bundle)24 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)21 Test (org.junit.Test)20 Nonnull (javax.annotation.Nonnull)18 ArrayList (java.util.ArrayList)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)10 FhirContext (ca.uhn.fhir.context.FhirContext)9 File (java.io.File)9 Row (org.apache.spark.sql.Row)9 IdType (org.hl7.fhir.dstu3.model.IdType)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 IOException (java.io.IOException)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Resource (org.hl7.fhir.r4.model.Resource)7