Search in sources :

Example 11 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project camel-quarkus by apache.

the class FhirDstu2Resource method createTransactionBundle.

private Bundle createTransactionBundle() {
    Bundle input = new Bundle();
    input.setType(BundleTypeEnum.TRANSACTION);
    input.addEntry().setResource(new Patient().addName(new HumanNameDt().addGiven("Art").setFamily(Arrays.asList(new StringDt("Tatum"))))).getRequest().setMethod(HTTPVerbEnum.POST);
    return input;
}
Also used : HumanNameDt(ca.uhn.fhir.model.dstu2.composite.HumanNameDt) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) StringDt(ca.uhn.fhir.model.primitive.StringDt)

Example 12 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project camel-quarkus by apache.

the class FhirDstu2Resource method operationOnType.

@Path("/operation/onType")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String operationOnType() {
    Map<String, Object> headers = new HashMap<>();
    headers.put("CamelFhir.resourceType", Patient.class);
    headers.put("CamelFhir.name", "everything");
    headers.put("CamelFhir.parameters", null);
    headers.put("CamelFhir.outputParameterType", Parameters.class);
    headers.put("CamelFhir.useHttpGet", Boolean.FALSE);
    headers.put("CamelFhir.returnType", null);
    headers.put("CamelFhir.extraParameters", null);
    Parameters result = producerTemplate.requestBodyAndHeaders("direct:operationOnType-dstu2", null, headers, Parameters.class);
    Parameters.Parameter parameter = result.getParameter().get(0);
    Bundle bundle = (Bundle) parameter.getResource();
    IdDt patientId = bundle.getEntry().get(0).getResource().getId();
    return patientId.toUnqualifiedVersionless().getValue();
}
Also used : Parameters(ca.uhn.fhir.model.dstu2.resource.Parameters) ExtraParameters(org.apache.camel.component.fhir.api.ExtraParameters) HashMap(java.util.HashMap) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) IdDt(ca.uhn.fhir.model.primitive.IdDt) JsonObject(javax.json.JsonObject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project camel-quarkus by apache.

the class FhirDstu2Resource method transactionWithStringBundle.

@Path("/transaction/withStringBundle")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String transactionWithStringBundle() {
    Bundle transactionBundle = createTransactionBundle();
    String stringBundle = fhirContextInstance.get().newJsonParser().encodeResourceToString(transactionBundle);
    return producerTemplate.requestBody("direct:transactionWithStringBundle-dstu2", stringBundle, String.class);
}
Also used : Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project camel-quarkus by apache.

the class FhirDstu2Resource method loadPagePrevious.

@Path("/load/page/previous")
@GET
@Produces(MediaType.TEXT_PLAIN)
public int loadPagePrevious(@QueryParam("encodeAsXml") boolean encodeAsXml) {
    String url = "Patient?_count=2";
    Bundle bundle = getFhirClient().search().byUrl(url).returnBundle(Bundle.class).execute();
    String nextPageLink = bundle.getLink("next").getUrl();
    bundle = getFhirClient().loadPage().byUrl(nextPageLink).andReturnBundle(Bundle.class).execute();
    Map<String, Object> headers = new HashMap<>();
    if (encodeAsXml) {
        headers.put(ExtraParameters.ENCODING_ENUM.getHeaderName(), EncodingEnum.XML);
    }
    Bundle result = producerTemplate.requestBodyAndHeaders("direct:loadPagePrevious-dstu2", bundle, headers, Bundle.class);
    return result.getEntry().size();
}
Also used : HashMap(java.util.HashMap) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) JsonObject(javax.json.JsonObject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with Bundle

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

the class FhirDstu2 method procedure.

/**
 * Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Person entry
 * @param bundle
 *          Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param procedure
 *          The Procedure
 * @return The added Entry
 */
private static Entry procedure(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Procedure procedure) {
    ca.uhn.fhir.model.dstu2.resource.Procedure procedureResource = new ca.uhn.fhir.model.dstu2.resource.Procedure();
    procedureResource.setStatus(ProcedureStatusEnum.COMPLETED);
    procedureResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    procedureResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = procedure.codes.get(0);
    procedureResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
    if (procedure.stop != 0L) {
        Date startDate = new Date(procedure.start);
        Date endDate = new Date(procedure.stop);
        procedureResource.setPerformed(new PeriodDt().setStart(new DateTimeDt(startDate)).setEnd(new DateTimeDt(endDate)));
    } else {
        procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
    }
    if (!procedure.reasons.isEmpty()) {
        // Only one element in list
        Code reason = procedure.reasons.get(0);
        for (Entry entry : bundle.getEntry()) {
            if (entry.getResource().getResourceName().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                CodingDt coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    procedureResource.setReason(new ResourceReferenceDt(entry.getFullUrl()));
                }
            }
        }
    }
    Entry procedureEntry = newEntry(rand, bundle, procedureResource);
    procedure.fullUrl = procedureEntry.getFullUrl();
    return procedureEntry;
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure)

Aggregations

Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)37 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)34 Date (java.util.Date)20 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)18 ArrayList (java.util.ArrayList)16 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)15 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)15 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)15 HashMap (java.util.HashMap)11 GET (javax.ws.rs.GET)11 Path (javax.ws.rs.Path)11 Produces (javax.ws.rs.Produces)11 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)10 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)9 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)8 JsonObject (javax.json.JsonObject)8 Provider (org.mitre.synthea.world.agents.Provider)8 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)7 Patient (ca.uhn.fhir.model.dstu2.resource.Patient)7 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)7