Java Code Examples for org.hl7.fhir.dstu3.model.Patient

The following examples show how to use org.hl7.fhir.dstu3.model.Patient. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void main(String[] theArgs) {
   FhirContext ctx = FhirContext.forDstu3();
   IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");

   // Build a search and execute it
   Bundle response = client.search()
      .forResource(Patient.class)
      .where(Patient.NAME.matches().value("Test"))
      .and(Patient.BIRTHDATE.before().day("2014-01-01"))
      .count(100)
      .returnBundle(Bundle.class)
      .execute();

   // How many resources did we find?
   System.out.println("Responses: " + response.getTotal());

   // Print the ID of the first one
   System.out.println("First response ID: " + response.getEntry().get(0).getResource().getId());
}
 
Example 2
Source Project: syndesis   Source File: FhirSearchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void searchTest() {
    Patient one = new Patient();
    one.setId("one");
    one.setGender(Enumerations.AdministrativeGender.UNKNOWN);
    Patient two = new Patient();
    two.setId("two");
    two.setGender(Enumerations.AdministrativeGender.UNKNOWN);

    Bundle bundle = new Bundle();
    bundle.getEntry().add(new Bundle.BundleEntryComponent().setResource(one));
    bundle.getEntry().add(new Bundle.BundleEntryComponent().setResource(two));

    stubFhirRequest(get(urlEqualTo("/Patient?gender=unknown&_format=xml")).willReturn(okXml(toXml(bundle))));

    FhirResourceQuery query = new FhirResourceQuery();
    query.setQuery("gender=unknown");

    String result = template.requestBody("direct:start", query, String.class);

    Assertions.assertThat(result).isEqualTo(
        "[<Patient xmlns=\"http://hl7.org/fhir\"><id value=\"one\"/><gender value=\"unknown\"/></Patient>, " +
        "<Patient xmlns=\"http://hl7.org/fhir\"><id value=\"two\"/><gender value=\"unknown\"/></Patient>]");
}
 
Example 3
Source Project: syndesis   Source File: FhirTransactionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("JdkObsolete")
public void transactionTest() {
    Bundle bundle = new Bundle();
    bundle.addEntry(new Bundle.BundleEntryComponent().setResource(new Account().setId("1").setMeta(new Meta().setLastUpdated(new Date()))));
    bundle.addEntry(new Bundle.BundleEntryComponent().setResource(new Patient().setId("2").setMeta(new Meta().setLastUpdated(new Date()))));
    stubFhirRequest(post(urlEqualTo("/?_format=xml")).withRequestBody(containing(
        "<type value=\"transaction\"/><total value=\"2\"/><link><relation value=\"fhir-base\"/></link>" +
            "<link><relation value=\"self\"/></link>" +
            "<entry><resource><Account xmlns=\"http://hl7.org/fhir\"><name value=\"Joe\"/></Account></resource>" +
            "<request><method value=\"POST\"/></request></entry><entry><resource>" +
            "<Patient xmlns=\"http://hl7.org/fhir\"><name><family value=\"Jackson\"/></name></Patient></resource>" +
            "<request><method value=\"POST\"/></request></entry>")).willReturn(okXml(toXml(bundle))));

    template.requestBody("direct:start",
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
            "<tns:Transaction xmlns:tns=\"http://hl7.org/fhir\">" +
            "<tns:Account><tns:name value=\"Joe\"/></tns:Account>" +
            "<tns:Patient><name><tns:family value=\"Jackson\"/></name></tns:Patient></tns:Transaction>");
}
 
Example 4
Source Project: bunsen   Source File: BundlesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testXmlBundleStrings() {

  JavaRDD<String> xmlBundlesRdd = spark.sparkContext()
      .wholeTextFiles("src/test/resources/xml/bundles", 1)
      .toJavaRDD()
      .map(tuple -> tuple._2());

  Dataset<String> xmlBundles = spark.createDataset(xmlBundlesRdd.rdd(),
      Encoders.STRING());

  xmlBundles.write().saveAsTable("xml_bundle_table");

  JavaRDD<BundleContainer> bundles = BundlesTest.bundles.fromXml(
      spark.sql("select value from xml_bundle_table"), "value");

  Dataset<Row> patients = BundlesTest.bundles.extractEntry(spark,
      bundles,
      Patient.class);

  checkPatients(patients);
}
 
Example 5
Source Project: bunsen   Source File: BundlesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonBundleStrings() {

  JavaRDD<String> jsonBundlesRdd = spark.sparkContext()
      .wholeTextFiles("src/test/resources/json/bundles", 1)
      .toJavaRDD()
      .map(tuple -> tuple._2());

  Dataset<String> jsonBundles = spark.createDataset(jsonBundlesRdd.rdd(),
      Encoders.STRING());

  jsonBundles.write().saveAsTable("json_bundle_table");

  JavaRDD<BundleContainer> bundlesRdd = bundles.fromJson(
      spark.sql("select value from json_bundle_table"), "value");

  Dataset<Row> patients = BundlesTest.bundles.extractEntry(spark,
      bundlesRdd,
      Patient.class);

  checkPatients(patients);
}
 
Example 6
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Patient patient, @IdParam IdType theId,@ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

    log.debug("Update Patient Provider called");
    
    resourcePermissionProvider.checkPermission("update");

    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);
    Patient newPatient = null;
    try {
        newPatient = patientDao.update(ctx, patient, theId, theConditional);
    } catch (OperationOutcomeException ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }
    method.setId(newPatient.getIdElement());
    method.setResource(newPatient);


    log.debug("called update Patient method");

    return method;
}
 
Example 7
Source Project: cqf-ruler   Source File: MeasureEvaluation.java    License: Apache License 2.0 6 votes vote down vote up
public MeasureReport evaluatePatientMeasure(Measure measure, Context context, String patientId) {
    logger.info("Generating individual report");

    if (patientId == null) {
        return evaluatePopulationMeasure(measure, context);
    }

    Patient patient = registry.getResourceDao(Patient.class).read(new IdType(patientId));
    // Iterable<Object> patientRetrieve = provider.retrieve("Patient", "id",
    // patientId, "Patient", null, null, null, null, null, null, null, null);
    // Patient patient = null;
    // if (patientRetrieve.iterator().hasNext()) {
    // patient = (Patient) patientRetrieve.iterator().next();
    // }

    return evaluate(measure, context,
            patient == null ? Collections.emptyList() : Collections.singletonList(patient),
            MeasureReport.MeasureReportType.INDIVIDUAL);
}
 
Example 8
Source Project: cqf-ruler   Source File: MeasureEvaluation.java    License: Apache License 2.0 6 votes vote down vote up
private void addPopulationCriteriaReport(MeasureReport report, MeasureReport.MeasureReportGroupComponent reportGroup, Measure.MeasureGroupPopulationComponent populationCriteria, int populationCount, Iterable<Patient> patientPopulation) {
     if (populationCriteria != null) {
         MeasureReport.MeasureReportGroupPopulationComponent populationReport = new MeasureReport.MeasureReportGroupPopulationComponent();
         populationReport.setIdentifier(populationCriteria.getIdentifier());
         populationReport.setCode(populationCriteria.getCode());
         if (report.getType() == MeasureReport.MeasureReportType.PATIENTLIST && patientPopulation != null) {
             ListResource subjectList = new ListResource();
	subjectList.setId(UUID.randomUUID().toString());
             populationReport.setPatients(new Reference().setReference("#" + subjectList.getId()));
             for (Patient patient : patientPopulation) {
                 ListResource.ListEntryComponent entry = new ListResource.ListEntryComponent()
                         .setItem(new Reference().setReference(
                                 patient.getIdElement().getIdPart().startsWith("Patient/") ?
                                         patient.getIdElement().getIdPart() :
                                         String.format("Patient/%s", patient.getIdElement().getIdPart()))
                                 .setDisplay(patient.getNameFirstRep().getNameAsSingleString()));
                 subjectList.addEntry(entry);
             }
             report.addContained(subjectList);
         }            
populationReport.setCount(populationCount);
         reportGroup.addPopulation(populationReport);
     }
 }
 
Example 9
public static void main(String[] theArgs) {

      // Create a resource instance
      Patient pat = new Patient();

      // Add a "name" element
      HumanName name = pat.addName();
      name.setFamily("Simpson").addGiven("Homer").addGiven("J");

      // Add an "identifier" element
      Identifier identifier = pat.addIdentifier();
      identifier.setSystem("http://acme.org/MRNs").setValue("7000135");

      // Model is designed to be chained
      pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("12345");

   }
 
Example 10
public static void main(String[] theArgs) {

		// Create a client
      IGenericClient client = FhirContext.forDstu3().newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");

      // Register some interceptors
      client.registerInterceptor(new CookieInterceptor("mycookie=Chips Ahoy"));
      client.registerInterceptor(new LoggingInterceptor());

      // Read a Patient
      Patient patient = client.read().resource(Patient.class).withId("example").execute();

		// Change the gender
		patient.setGender(patient.getGender() == AdministrativeGender.MALE ? AdministrativeGender.FEMALE : AdministrativeGender.MALE);

		// Update the patient
		MethodOutcome outcome = client.update().resource(patient).execute();
		
		System.out.println("Now have ID: " + outcome.getId());
	}
 
Example 11
public static void main(String[] theArgs) {
Patient pat = new Patient();
pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J");

// Add an extension on the resource
pat.addExtension()
		.setUrl("http://hl7.org/fhir/StructureDefinition/patient-importance")
		.setValue(new CodeableConcept().setText("Patient is a VIP"));

// Add an extension on a primitive
pat.getBirthDateElement().setValueAsString("1955-02-22");
pat.getBirthDateElement().addExtension()
		.setUrl("http://hl7.org/fhir/StructureDefinition/patient-birthTime")
		.setValue(new TimeType("23:30"));

    IParser parser = FhirContext.forDstu3().newJsonParser().setPrettyPrint(true);
    System.out.println(parser.encodeResourceToString(pat));
 }
 
Example 12
public static void main(String[] theArgs) {

		// Create a Patient
		Patient pat = new Patient();
		pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J");
		pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135");
		pat.addTelecom().setUse(ContactPointUse.HOME).setSystem(ContactPointSystem.PHONE).setValue("1 (416) 340-4800");
		pat.setGender(AdministrativeGender.MALE);

		// Create a context
		FhirContext ctx = FhirContext.forDstu3();

		// Create a JSON parser
		IParser parser = ctx.newJsonParser();
		parser.setPrettyPrint(true);

		String encode = parser.encodeResourceToString(pat);
		System.out.println(encode);

	}
 
Example 13
public static void main(String[] args) {

      // Create an Observation
      Observation obs = new Observation();
      obs.setStatus(Observation.ObservationStatus.FINAL);
      obs.setValue(new StringType("This is a value"));

      // Create a Patient
      Patient pat = new Patient();
      pat.addName().setFamily("Simpson").addGiven("Homer");

      // Assign the Patient to the Observation
      obs.getSubject().setResource(pat);

      FhirContext ctx = FhirContext.forDstu3();
      String output = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(obs);
      System.out.println(output);

   }
 
Example 14
public static void main(String[] theArgs) {

      // Create a resource instance
      Patient pat = new Patient();

      // Add a "name" element
      HumanName name = pat.addName();
      name.setFamily("Simpson").addGiven("Homer").addGiven("J");

      // Add an "identifier" element
      Identifier identifier = pat.addIdentifier();
      identifier.setSystem("http://acme.org/MRNs").setValue("7000135");

      // Model is designed to be chained
      pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("12345");

   }
 
Example 15
Source Project: wildfly-camel   Source File: FhirJsonIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFhirJsonMarshal() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal().fhirJson("DSTU3");
        }
    });

    camelctx.start();
    try {
        Patient patient = createPatient();
        ProducerTemplate template = camelctx.createProducerTemplate();
        InputStream inputStream = template.requestBody("direct:start", patient, InputStream.class);
        IBaseResource result = FhirContext.forDstu3().newJsonParser().parseResource(new InputStreamReader(inputStream));
        Assert.assertTrue("Expected marshaled patient to be equal", patient.equalsDeep((Base)result));
    } finally {
        camelctx.close();
    }
}
 
Example 16
Source Project: wildfly-camel   Source File: FhirJsonIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFhirJsonUnmarshal() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .unmarshal().fhirJson("DSTU3");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        Patient result = template.requestBody("direct:start", PATIENT_JSON, Patient.class);
        Assert.assertTrue("Expected unmarshaled patient to be equal", result.equalsDeep(createPatient()));
    } finally {
        camelctx.close();
    }
}
 
Example 17
Source Project: wildfly-camel   Source File: FhirXmlIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFhirJsonMarshal() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal().fhirXml();
        }
    });

    camelctx.start();
    try {
        Patient patient = createPatient();
        ProducerTemplate template = camelctx.createProducerTemplate();
        InputStream inputStream = template.requestBody("direct:start", patient, InputStream.class);
        IBaseResource result = FhirContext.forDstu3().newXmlParser().parseResource(new InputStreamReader(inputStream));
        Assert.assertTrue("Expected marshaled patient to be equal", patient.equalsDeep((Base)result));
    } finally {
        camelctx.close();
    }
}
 
Example 18
Source Project: wildfly-camel   Source File: FhirXmlIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFhirJsonUnmarshal() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .unmarshal().fhirXml();
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        Patient result = template.requestBody("direct:start", PATIENT_XML, Patient.class);
        Assert.assertTrue("Expected unmarshaled patient to be equal", result.equalsDeep(createPatient()));
    } finally {
        camelctx.close();
    }
}
 
Example 19
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.Dstu2Enabled.class)
public void jsonDstu2() {
    LOG.info("Running DSTU2 JSON test");

    final ca.uhn.fhir.model.dstu2.resource.Patient patient = getDstu2Patient();
    final String patientString = FhirContext.forDstu2().newJsonParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.JSON).body(patientString).post("/dstu2/fhir2json")
            .then().statusCode(201);
}
 
Example 20
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.Dstu2Enabled.class)
public void xmlDstu2() {
    LOG.info("Running DSTU2 XML test");

    final ca.uhn.fhir.model.dstu2.resource.Patient patient = getDstu2Patient();
    final String patientString = FhirContext.forDstu2().newXmlParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.XML).body(patientString).post("/dstu2/fhir2xml")
            .then().statusCode(201);
}
 
Example 21
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.Dstu3Enabled.class)
public void jsonDstu3() {
    LOG.info("Running DSTU3 JSON test");

    final Patient patient = getDstu3Patient();
    final String patientString = FhirContext.forDstu3().newJsonParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.JSON).body(patientString).post("/dstu3/fhir2json")
            .then().statusCode(201);
}
 
Example 22
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.Dstu3Enabled.class)
public void xmlDstu3() {
    LOG.info("Running DSTU3 XML test");

    final Patient patient = getDstu3Patient();
    final String patientString = FhirContext.forDstu3().newXmlParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.XML).body(patientString).post("/dstu3/fhir2xml")
            .then().statusCode(201);
}
 
Example 23
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.R4Enabled.class)
public void jsonR4() {
    LOG.info("Running R4 JSON test");

    final org.hl7.fhir.r4.model.Patient patient = getR4Patient();
    final String patientString = FhirContext.forR4().newJsonParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.JSON).body(patientString).post("/r4/fhir2json")
            .then().statusCode(201);
}
 
Example 24
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.R4Enabled.class)
public void xmlR4() {
    LOG.info("Running R4 XML test");

    final org.hl7.fhir.r4.model.Patient patient = getR4Patient();
    final String patientString = FhirContext.forR4().newXmlParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.XML).body(patientString).post("/r4/fhir2xml")
            .then().statusCode(201);
}
 
Example 25
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.R5Enabled.class)
public void jsonR5() {
    LOG.info("Running R5 JSON test");

    final org.hl7.fhir.r5.model.Patient patient = getR5Patient();
    final String patientString = FhirContext.forR5().newJsonParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.JSON).body(patientString).post("/r5/fhir2json")
            .then().statusCode(201);
}
 
Example 26
Source Project: camel-quarkus   Source File: FhirDataformatTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@EnabledIf(FhirFlags.R5Enabled.class)
public void xmlR5() {
    LOG.info("Running R5 XML test");

    final org.hl7.fhir.r5.model.Patient patient = getR5Patient();
    final String patientString = FhirContext.forR5().newXmlParser().encodeResourceToString(patient);

    RestAssured.given()
            .contentType(ContentType.XML).body(patientString).post("/r5/fhir2xml")
            .then().statusCode(201);
}
 
Example 27
@Test
public void testCreateAndRead() {
	ourLog.info("Base URL is: " +  HapiProperties.getServerAddress());
	String methodName = "testCreateResourceConditional";

	Patient pt = new Patient();
	pt.addName().setFamily(methodName);
	IIdType id = ourClient.create().resource(pt).execute().getId();

	Patient pt2 = ourClient.read().resource(Patient.class).withId(id).execute();
	assertEquals(methodName, pt2.getName().get(0).getFamily());
}
 
Example 28
Source Project: syndesis   Source File: FhirReadTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void readWithIdProvidedAsParameterTest() {
    stubFhirRequest(get(urlEqualTo("/Patient/1234?_format=xml")).willReturn(okXml(toXml(new Patient().setId("1234")))));

    String patient = template.requestBody("direct:start", "", String.class);

    Assertions.assertThat(patient).contains("<id value=\"1234\"/>");
}
 
Example 29
Source Project: syndesis   Source File: FhirReadTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void readWithIdProvidedInBodyTest() {
    stubFhirRequest(get(urlEqualTo("/Patient/4321?_format=xml")).willReturn(okXml(toXml(new Patient().setId("4321")))));

    FhirResourceId id = new FhirResourceId();
    id.setId("4321");

    String patient = template.requestBody("direct:start", id, String.class);

    Assertions.assertThat(patient).contains("<id value=\"4321\"/>");
}
 
Example 30
Source Project: syndesis   Source File: FhirUpdateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void updateTest() {
    stubFhirRequest(put(urlEqualTo("/Patient/1234?_format=xml")).willReturn(okXml(toXml(new OperationOutcome()))));

    template.requestBody("direct:start",
        toXml(new Patient().addName(new HumanName().setFamily("Smith")).setId("1234")), MethodOutcome.class);
}