org.hl7.fhir.dstu3.model.Patient Java Examples
The following examples show how to use
org.hl7.fhir.dstu3.model.Patient.
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
Source File: Example08_ClientSearch.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 7 votes |
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 File: PatientProvider.java From careconnect-reference-implementation with Apache License 2.0 | 6 votes |
@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 #3
Source File: FhirXmlIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@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 #4
Source File: FhirJsonIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@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 #5
Source File: FhirXmlIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@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 #6
Source File: FhirJsonIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@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 #7
Source File: Example04_EncodeResource.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #8
Source File: Example01_CreateAPatient.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #9
Source File: Example34_ContainedResources.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #10
Source File: FhirSearchTest.java From syndesis with Apache License 2.0 | 6 votes |
@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 #11
Source File: Example30_AddSomeExtensions.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Source File: Example09_Interceptors.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #13
Source File: Example01_CreateAPatient.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #14
Source File: FhirTransactionTest.java From syndesis with Apache License 2.0 | 6 votes |
@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 #15
Source File: MeasureEvaluation.java From cqf-ruler with Apache License 2.0 | 6 votes |
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 #16
Source File: BundlesTest.java From bunsen with Apache License 2.0 | 6 votes |
@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 #17
Source File: BundlesTest.java From bunsen with Apache License 2.0 | 6 votes |
@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 #18
Source File: MeasureEvaluation.java From cqf-ruler with Apache License 2.0 | 6 votes |
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 #19
Source File: MeasureEvaluation.java From cqf-ruler with Apache License 2.0 | 5 votes |
private Iterable<Resource> evaluateCriteria(Context context, Patient patient, Measure.MeasureGroupPopulationComponent pop) { if (!pop.hasCriteria()) { return Collections.emptyList(); } context.setContextValue("Patient", patient.getIdElement().getIdPart()); // Hack to clear expression cache // See cqf-ruler github issue #153 try { Field privateField = Context.class.getDeclaredField("expressions"); privateField.setAccessible(true); LinkedHashMap<String, Object> expressions = (LinkedHashMap<String, Object>)privateField.get(context); expressions.clear(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Object result = context.resolveExpressionRef(pop.getCriteria()).evaluate(context); if (result == null) { return Collections.emptyList(); } if (result instanceof Boolean) { if (((Boolean)result)) { return Collections.singletonList(patient); } else { return Collections.emptyList(); } } return (Iterable)result; }
Example #20
Source File: Example02_EnumeratedTypes.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] theArgs) { Patient pat = new Patient(); pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J"); pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135"); // Enumerated types are provided for many coded elements ContactPoint contact = pat.addTelecom(); contact.setUse(ContactPoint.ContactPointUse.HOME); contact.setSystem(ContactPoint.ContactPointSystem.PHONE); contact.setValue("1 (416) 340-4800"); pat.setGender(Enumerations.AdministrativeGender.MALE); }
Example #21
Source File: FhirXmlIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
private Patient createPatient() { Patient patient = new Patient(); patient.addName(new HumanName() .addGiven("Sherlock") .setFamily("Holmes")) .addAddress(new Address().addLine("221b Baker St, Marylebone, London NW1 6XE, UK")); return patient; }
Example #22
Source File: Example02_EnumeratedTypes.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] theArgs) { Patient pat = new Patient(); pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J"); pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135"); // Enumerated types are provided for many coded elements ContactPoint contact = pat.addTelecom(); contact.setUse(ContactPoint.ContactPointUse.HOME); contact.setSystem(ContactPoint.ContactPointSystem.PHONE); contact.setValue("1 (416) 340-4800"); pat.setGender(Enumerations.AdministrativeGender.MALE); }
Example #23
Source File: Example01_StubResourceProvider.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Search List<Patient> search( @OptionalParam(name="family") StringParam theFamily, @OptionalParam(name="given") StringParam theGiven ) { return null; // populate this }
Example #24
Source File: Example99_NarrativeGenerator.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) { // Create an encounter with an invalid status and no class Patient pat = new Patient(); pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("Jay"); pat.addAddress().addLine("342 Evergreen Terrace").addLine("Springfield"); pat.addIdentifier().setSystem("http://acme.org/mrns").setValue("12345"); // Create a new context and enable the narrative generator FhirContext ctx = FhirContext.forDstu2(); ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); String res = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(pat); System.out.println(res); }
Example #25
Source File: MeasureEvaluation.java From cqf-ruler with Apache License 2.0 | 5 votes |
private List<Patient> getAllPatients() { List<Patient> patients = new ArrayList<>(); IBundleProvider patientProvider = registry.getResourceDao("Patient").search(new SearchParameterMap()); List<IBaseResource> patientList = patientProvider.getResources(0, patientProvider.size()); patientList.forEach(x -> patients.add((Patient) x)); return patients; }
Example #26
Source File: MeasureEvaluation.java From cqf-ruler with Apache License 2.0 | 5 votes |
private List<Patient> getPractitionerPatients(String practitionerRef) { SearchParameterMap map = new SearchParameterMap(); map.add("general-practitioner", new ReferenceParam( practitionerRef.startsWith("Practitioner/") ? practitionerRef : "Practitioner/" + practitionerRef)); List<Patient> patients = new ArrayList<>(); IBundleProvider patientProvider = registry.getResourceDao("Patient").search(map); List<IBaseResource> patientList = patientProvider.getResources(0, patientProvider.size()); patientList.forEach(x -> patients.add((Patient) x)); return patients; }
Example #27
Source File: TestDstu3ModelResolver.java From cql_engine with Apache License 2.0 | 5 votes |
@Test public void resolveMissingPropertyReturnsNull() { ModelResolver resolver = new Dstu3FhirModelResolver(); Patient p = new Patient(); Object result = resolver.resolvePath(p, "notapath"); assertNull(result); }
Example #28
Source File: PatientEntityToFHIRPatientTransformerTest.java From careconnect-reference-implementation with Apache License 2.0 | 5 votes |
@Test public void testTransformSimplePatientEntity() throws FHIRException { LocalDate dateOfBirth = LocalDate.of(1996, 6, 21); final PatientEntity patientEntity = new PatientEntityBuilder() .setDateOfBirth(dateOfBirth) .build(); final Patient patient = transformer.transform(patientEntity); assertThat(patient, not(nullValue())); assertThat(patient.getActive(), equalTo(true)); assertThat(patient.getName().size(), equalTo(1)); HumanName name = patient.getName().get(0); assertThat(name.getGivenAsSingleString(), equalTo("John")); assertThat(name.getFamily(), equalTo("Smith")); assertThat(name.getUse(), equalTo(HumanName.NameUse.OFFICIAL)); assertThat(name.getPrefixAsSingleString(), equalTo("Mr")); assertThat(patient.getGender(), equalTo(Enumerations.AdministrativeGender.MALE)); assertThat(patient.getBirthDate(), not(nullValue())); LocalDate patientDoB = DateUtils.asLocalDate(patient.getBirthDate()); assertThat(patientDoB, equalTo(dateOfBirth)); }
Example #29
Source File: PatientProvider.java From careconnect-reference-implementation with Apache License 2.0 | 5 votes |
@Create public MethodOutcome createPatient(HttpServletRequest theRequest, @ResourceParam Patient patient) { log.info("Update Patient Provider called"); resourcePermissionProvider.checkPermission("create"); /* if(CRUD_create.equals("false")) { throw OperationOutcomeFactory.buildOperationOutcomeException( new InvalidRequestException("Invalid Request"), OperationOutcome.IssueSeverity.ERROR, OperationOutcome.IssueType.INVALID); } */ MethodOutcome method = new MethodOutcome(); method.setCreated(true); OperationOutcome opOutcome = new OperationOutcome(); method.setOperationOutcome(opOutcome); Patient newPatient = null; try { newPatient = patientDao.update(ctx, patient, null, null); method.setId(newPatient.getIdElement()); method.setResource(newPatient); } catch (BaseServerResponseException srv) { // HAPI Exceptions pass through throw srv; } catch(Exception ex) { ProviderResponseLibrary.handleException(method,ex); } log.debug("called create Patient method"); return method; }
Example #30
Source File: FhirDataformatTest.java From camel-quarkus with Apache License 2.0 | 5 votes |
@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); }