Search in sources :

Example 6 with Patient

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

the class FhirDstu2Resource method updateResourceWithStringId.

@Path("/update/resource/withStringId")
@POST
public void updateResourceWithStringId(@QueryParam("id") String id) throws ParseException {
    Patient patient = getFhirClient().read().resource(Patient.class).withId(id).preferResponseType(Patient.class).execute();
    Date date = new SimpleDateFormat("yyyy-MM-dd").parse("1998-04-29");
    patient.setBirthDate(new DateDt(date));
    Map<String, Object> headers = new HashMap<>();
    headers.put("CamelFhir.resource", patient);
    headers.put("CamelFhir.stringId", patient.getIdElement().getIdPart());
    headers.put("CamelFhir.preferReturn", PreferReturnEnum.REPRESENTATION);
    producerTemplate.sendBodyAndHeaders("direct:updateResourceWithStringId-dstu2", null, headers);
}
Also used : HashMap(java.util.HashMap) DateDt(ca.uhn.fhir.model.primitive.DateDt) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) JsonObject(javax.json.JsonObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 7 with Patient

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

the class FhirDstu2Resource method readPatientByLongIdAndStringResource.

@Path("/readPatient/byLongIdAndStringResource")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response readPatientByLongIdAndStringResource(@QueryParam("id") String id) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("CamelFhir.resourceClass", "Patient");
    headers.put("CamelFhir.longId", Long.valueOf(id));
    try {
        Patient result = producerTemplate.requestBodyAndHeaders("direct:readByLongIdAndStringResource-dstu2", null, headers, Patient.class);
        return Response.ok().entity(patientToJsonObject(result)).build();
    } catch (CamelExecutionException e) {
        Throwable cause = e.getExchange().getException().getCause();
        if (cause instanceof ResourceGoneException) {
            return Response.status(404).build();
        }
    }
    return Response.noContent().build();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) ResourceGoneException(ca.uhn.fhir.rest.server.exceptions.ResourceGoneException) HashMap(java.util.HashMap) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) JsonObject(javax.json.JsonObject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with Patient

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

the class FhirDstu2Resource method updateResourceBySearchUrl.

@Path("/update/resource/bySearchUrl")
@POST
@Produces(MediaType.TEXT_PLAIN)
public String updateResourceBySearchUrl(@QueryParam("id") String id) throws Exception {
    Patient patient = getFhirClient().read().resource(Patient.class).withId(id).preferResponseType(Patient.class).execute();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = dateFormat.parse("1998-04-29");
    patient.setBirthDate(new DateDt(date));
    String url = "Patient?" + Patient.SP_IDENTIFIER + '=' + URLEncoder.encode(patient.getIdElement().getIdPart(), "UTF-8");
    Map<String, Object> headers = new HashMap<>();
    headers.put("CamelFhir.resource", patient);
    headers.put("CamelFhir.url", url);
    headers.put("CamelFhir.preferReturn", PreferReturnEnum.REPRESENTATION);
    MethodOutcome result = producerTemplate.requestBodyAndHeaders("direct:updateResourceBySearchUrl-dstu2", null, headers, MethodOutcome.class);
    Patient updated = (Patient) result.getResource();
    return dateFormat.format(updated.getBirthDate());
}
Also used : HashMap(java.util.HashMap) DateDt(ca.uhn.fhir.model.primitive.DateDt) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) JsonObject(javax.json.JsonObject) SimpleDateFormat(java.text.SimpleDateFormat) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Date(java.util.Date) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 9 with Patient

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

the class FhirDstu2Resource method transactionWithResources.

@Path("/transaction/withResources")
@GET
@Produces(MediaType.TEXT_PLAIN)
@SuppressWarnings("unchecked")
public int transactionWithResources(@QueryParam("summaryEnum") boolean summaryEnum) {
    Patient oscar = new Patient().addName(new HumanNameDt().addGiven("Oscar").setFamily(Arrays.asList(new StringDt("Peterson"))));
    Patient bobbyHebb = new Patient().addName(new HumanNameDt().addGiven("Bobby").setFamily(Arrays.asList(new StringDt("Hebb"))));
    List<IBaseResource> patients = new ArrayList<>(2);
    patients.add(oscar);
    patients.add(bobbyHebb);
    Map<String, Object> headers = new HashMap<>();
    if (summaryEnum) {
        headers.put(ExtraParameters.SUMMARY_ENUM.getHeaderName(), SummaryEnum.DATA);
    }
    List<IBaseResource> result = producerTemplate.requestBodyAndHeaders("direct:transactionWithResources-dstu2", patients, headers, List.class);
    return result.size();
}
Also used : HumanNameDt(ca.uhn.fhir.model.dstu2.composite.HumanNameDt) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) StringDt(ca.uhn.fhir.model.primitive.StringDt) JsonObject(javax.json.JsonObject) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 10 with Patient

use of ca.uhn.fhir.model.dstu2.resource.Patient 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)

Aggregations

Patient (ca.uhn.fhir.model.dstu2.resource.Patient)37 Path (javax.ws.rs.Path)31 Produces (javax.ws.rs.Produces)26 HashMap (java.util.HashMap)25 JsonObject (javax.json.JsonObject)23 GET (javax.ws.rs.GET)21 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)12 ResourceGoneException (ca.uhn.fhir.rest.server.exceptions.ResourceGoneException)12 CamelExecutionException (org.apache.camel.CamelExecutionException)12 StringDt (ca.uhn.fhir.model.primitive.StringDt)11 Date (java.util.Date)10 POST (javax.ws.rs.POST)9 DateDt (ca.uhn.fhir.model.primitive.DateDt)8 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)7 SimpleDateFormat (java.text.SimpleDateFormat)7 HumanNameDt (ca.uhn.fhir.model.dstu2.composite.HumanNameDt)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)6 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)4 Encounter (ca.uhn.fhir.model.dstu2.resource.Encounter)4