org.hl7.fhir.r4.model.Patient Java Examples
The following examples show how to use
org.hl7.fhir.r4.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: TestApplicationHints.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 7 votes |
public static void step2_search_for_patients_named_test() { FhirContext ctx = FhirContext.forDstu3(); IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); org.hl7.fhir.r4.model.Bundle results = client .search() .forResource(Patient.class) .where(Patient.NAME.matches().value("test")) .returnBundle(org.hl7.fhir.r4.model.Bundle.class) .execute(); System.out.println("First page: "); System.out.println(ctx.newXmlParser().encodeResourceToString(results)); // Load the next page org.hl7.fhir.r4.model.Bundle nextPage = client .loadPage() .next(results) .execute(); System.out.println("Next page: "); System.out.println(ctx.newXmlParser().encodeResourceToString(nextPage)); }
Example #2
Source File: TestApplicationHints.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 7 votes |
public static void step1_read_a_resource() { FhirContext ctx = FhirContext.forDstu3(); IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); Patient patient; try { // Try changing the ID from 952975 to 999999999999 patient = client.read().resource(Patient.class).withId("952975").execute(); } catch (ResourceNotFoundException e) { System.out.println("Resource not found!"); return; } String string = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(string); }
Example #3
Source File: TestApplication.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 7 votes |
/** * This is the Java main method, which gets executed */ public static void main(String[] args) { // Create a context FhirContext ctx = FhirContext.forR4(); // Create a client IGenericClient client = ctx.newRestfulGenericClient("https://hapi.fhir.org/baseR4"); // Read a patient with the given ID Patient patient = client.read().resource(Patient.class).withId("example").execute(); // Print the output String string = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(string); }
Example #4
Source File: FhirEncodersTest.java From bunsen with Apache License 2.0 | 6 votes |
/** * Set up Spark. */ @BeforeClass public static void setUp() { spark = SparkSession.builder() .master("local[*]") .appName("testing") .getOrCreate(); patientDataset = spark.createDataset(ImmutableList.of(patient), encoders.of(Patient.class)); decodedPatient = patientDataset.head(); conditionsDataset = spark.createDataset(ImmutableList.of(condition), encoders.of(Condition.class)); decodedCondition = conditionsDataset.head(); observationsDataset = spark.createDataset(ImmutableList.of(observation), encoders.of(Observation.class)); decodedObservation = observationsDataset.head(); medDataset = spark.createDataset(ImmutableList.of(medRequest), encoders.of(MedicationRequest.class)); decodedMedRequest = medDataset.head(); }
Example #5
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
private void mapRelatedContacts(IPatient source, Patient target) { List<ContactComponent> contacts = new ArrayList<>(); IPerson legalGuardian = source.getLegalGuardian(); if (legalGuardian != null) { ContactComponent _legalGuardian = new ContactComponent(); CodeableConcept addCoding = new CodeableConcept().addCoding(new Coding().setCode("N")); _legalGuardian.setRelationship(Collections.singletonList(addCoding)); _legalGuardian.setId(legalGuardian.getId()); List<HumanName> humanNames = contactHelper.getHumanNames(legalGuardian); _legalGuardian.setName((!humanNames.isEmpty()) ? humanNames.get(0) : null); List<Address> addresses = contactHelper.getAddresses(legalGuardian); _legalGuardian.setAddress((!addresses.isEmpty()) ? addresses.get(0) : null); AdministrativeGender gender = contactHelper.getGender(legalGuardian.getGender()); _legalGuardian.setGender(gender); List<ContactPoint> contactPoints = contactHelper.getContactPoints(legalGuardian); _legalGuardian.setTelecom(contactPoints); contacts.add(_legalGuardian); } target.setContact(contacts); }
Example #6
Source File: MeasureEvaluation.java From cqf-ruler with Apache License 2.0 | 6 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 #7
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
public void elexisToFhir(IPatient source, Patient target, SummaryEnum summaryEnum, Set<Include> includes){ target.setId(new IdDt("Patient", source.getId())); mapMetaData(source, target); if(SummaryEnum.DATA != summaryEnum) { mapNarrative(source, target); } if (SummaryEnum.TEXT == summaryEnum || SummaryEnum.COUNT == summaryEnum) { return; } mapIdentifiersAndPatientNumber(source, target); target.setName(contactHelper.getHumanNames(source)); target.setGender(contactHelper.getGender(source.getGender())); target.setBirthDate(contactHelper.getBirthDate(source)); mapAddressTelecom(source, target); mapComments(source, target); mapMaritalStatus(source, target); mapRelatedContacts(source, target); mapContactImage(source, target); }
Example #8
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
private void mapGender(Patient source, IPatient target) { AdministrativeGender gender = source.getGender(); if (gender != null) { switch (gender) { case FEMALE: target.setGender(Gender.FEMALE); break; case MALE: target.setGender(Gender.MALE); break; case UNKNOWN: target.setGender(Gender.UNKNOWN); break; default: target.setGender(Gender.UNDEFINED); } } }
Example #9
Source File: BundlesTest.java From bunsen with Apache License 2.0 | 6 votes |
@Test public void testSaveAsDatabase() { bundles.saveAsDatabase(spark, bundlesRdd, "bundlesdb", "patient", "condition", "observation"); Dataset<Patient> patients = spark .sql("select * from bundlesdb.patient") .as(encoders.of(Patient.class)); checkPatients(patients); Dataset<Condition> conditions = spark .sql("select * from bundlesdb.condition") .as(encoders.of(Condition.class)); checkConditions(conditions); // Ensure the included observations are present as well. Assert.assertEquals(72, spark.sql("select * from bundlesdb.observation") .count()); }
Example #10
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<Patient> patients = BundlesTest.bundles.extractEntry(spark, bundlesRdd, Patient.class); checkPatients(patients); }
Example #11
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<Patient> patients = BundlesTest.bundles.extractEntry(spark, bundles, Patient.class); checkPatients(patients); }
Example #12
Source File: Example07_ClientReadAndUpdate.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void main(String[] theArgs) { // Create a client FhirContext ctx = FhirContext.forR4(); IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/R4"); Patient patient = new Patient(); patient.setId("Patient/example"); // Give the patient an ID patient.addName().setFamily("Simpson").addGiven("Homer"); patient.setGender(Enumerations.AdministrativeGender.MALE); // Update the patient MethodOutcome outcome = client .update() .resource(patient) .execute(); System.out.println("Now have ID: " + outcome.getId()); }
Example #13
Source File: Example06_ClientCreate.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"); pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135"); pat.setGender(AdministrativeGender.MALE); // Create a context FhirContext ctx = FhirContext.forR4(); // Create a client String serverBaseUrl = "http://hapi.fhir.org/baseR4"; IGenericClient client = ctx.newRestfulGenericClient(serverBaseUrl); // Use the client to store a new resource instance MethodOutcome outcome = client .create() .resource(pat) .execute(); // Print the ID of the newly created resource System.out.println(outcome.getId()); }
Example #14
Source File: BundlesTest.java From bunsen with Apache License 2.0 | 6 votes |
private void checkPatients(Dataset<Patient> patients) { List<String> patientIds = patients .collectAsList() .stream() .map(Patient::getId) .collect(Collectors.toList()); Assert.assertEquals(3, patientIds.size()); List<String> expectedIds = ImmutableList.of( "Patient/6666001", "Patient/1032702", "Patient/9995679"); Assert.assertTrue(patientIds.containsAll(expectedIds)); }
Example #15
Source File: MultitenantServerR4IT.java From hapi-fhir-jpaserver-starter with Apache License 2.0 | 6 votes |
@Test public void testCreateAndReadInTenantB() { ourLog.info("Base URL is: " + HapiProperties.getServerAddress()); // Create tenant A ourClientTenantInterceptor.setTenantId("DEFAULT"); ourClient .operation() .onServer() .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION) .withParameter(Parameters.class, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, new IntegerType(2)) .andParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, new CodeType("TENANT-B")) .execute(); ourClientTenantInterceptor.setTenantId("TENANT-B"); Patient pt = new Patient(); pt.addName().setFamily("Family B"); ourClient.create().resource(pt).execute().getId(); Bundle searchResult = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); assertEquals(1, searchResult.getEntry().size()); Patient pt2 = (Patient) searchResult.getEntry().get(0).getResource(); assertEquals("Family B", pt2.getName().get(0).getFamily()); }
Example #16
Source File: MultitenantServerR4IT.java From hapi-fhir-jpaserver-starter with Apache License 2.0 | 6 votes |
@Test public void testCreateAndReadInTenantA() { ourLog.info("Base URL is: " + HapiProperties.getServerAddress()); // Create tenant A ourClientTenantInterceptor.setTenantId("DEFAULT"); ourClient .operation() .onServer() .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION) .withParameter(Parameters.class, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, new IntegerType(1)) .andParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, new CodeType("TENANT-A")) .execute(); ourClientTenantInterceptor.setTenantId("TENANT-A"); Patient pt = new Patient(); pt.addName().setFamily("Family A"); ourClient.create().resource(pt).execute().getId(); Bundle searchResult = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); assertEquals(1, searchResult.getEntry().size()); Patient pt2 = (Patient) searchResult.getEntry().get(0).getResource(); assertEquals("Family A", pt2.getName().get(0).getFamily()); }
Example #17
Source File: Hints.java From fhirstarters with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Search public List<Patient> search(@RequiredParam(name = Patient.SP_FAMILY) StringParam theParam) { List<Patient> retVal = new ArrayList<Patient>(); // Loop through the patients looking for matches for (Patient next : myPatients.values()) { String familyName = next.getNameFirstRep().getFamily().toLowerCase(); if (familyName.contains(theParam.getValue().toLowerCase()) == false) { continue; } retVal.add(next); } return retVal; }
Example #18
Source File: PatientIPatientTransformer.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public Optional<IPatient> getLocalObject(Patient fhirObject) { String id = fhirObject.getIdElement().getIdPart(); if (id != null && !id.isEmpty()) { return modelService.load(id, IPatient.class); } return Optional.empty(); }
Example #19
Source File: PatientIPatientTransformer.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public Optional<IPatient> createLocalObject(Patient fhirObject) { IPatient create = modelService.create(IPatient.class); attributeMapper.fhirToElexis(fhirObject, create); modelService.save(create); return Optional.of(create); }
Example #20
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
public void fhirToElexis(Patient source, IPatient target) { mapIdentifiers(source, target); mapName(source, target); mapGender(source, target); mapBirthDate(source, target); mapAddressTelecom(source, target); mapComments(source, target); mapMaritalStatus(source, target); mapContacts(source, target); mapContactImage(source, target); }
Example #21
Source File: FhirChCrlDocumentBundle.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void fixAhvIdentifier(Patient subject){ List<Identifier> identifiers = subject.getIdentifier(); Optional<Identifier> ahvIdentifier = identifiers.stream() .filter(id -> id.getSystem().equals(XidConstants.DOMAIN_AHV)).findFirst(); subject.getIdentifier().clear(); ahvIdentifier.ifPresent(ahvId -> { Identifier identifier = new Identifier(); identifier.setSystem("urn:oid:2.16.756.5.32"); identifier.setValue(ahvId.getValue()); subject.addIdentifier(identifier); }); }
Example #22
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void mapContactImage(IPatient source, Patient target) { IImage image = source.getImage(); if (image != null) { Attachment _image = new Attachment(); MimeType mimeType = image.getMimeType(); _image.setContentType((mimeType != null) ? mimeType.getContentType() : null); _image.setData(image.getImage()); target.setPhoto(Collections.singletonList(_image)); } }
Example #23
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void mapContactImage(Patient source, IPatient target) { if (!source.getPhoto().isEmpty()) { Attachment fhirImage = source.getPhoto().get(0); IImage image = coreModelService.create(IImage.class); image.setDate(LocalDate.now()); String contentType = fhirImage.getContentTypeElement().asStringValue(); MimeType mimeType = MimeType.getByContentType(contentType); image.setMimeType(mimeType); image.setImage(fhirImage.getData()); target.setImage(image); } else { target.setImage(null); } }
Example #24
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void mapMaritalStatus(Patient source, IPatient target) { CodeableConcept maritalStatus = source.getMaritalStatus(); if (maritalStatus != null && !maritalStatus.getCoding().isEmpty()) { String code = maritalStatus.getCoding().get(0).getCode(); target.setMaritalStatus(MaritalStatus.byFhirCodeSafe(code)); } }
Example #25
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void mapAddressTelecom(Patient source, IPatient target) { List<Address> addresses = source.getAddress(); for (Address address : addresses) { if (AddressUse.HOME.equals(address.getUse())) { target.setCity(address.getCity()); target.setZip(address.getPostalCode()); if (!address.getLine().isEmpty()) { target.setStreet(address.getLine().get(0).asStringValue()); } Country country = null; try { country = Country.valueOf(address.getCountry()); } catch (IllegalArgumentException | NullPointerException e) { // ignore } target.setCountry(country); } } List<ContactPoint> telecoms = source.getTelecom(); for (ContactPoint contactPoint : telecoms) { if (ContactPointSystem.PHONE.equals(contactPoint.getSystem())) { if (ContactPointUse.MOBILE.equals(contactPoint.getUse())) { target.setMobile(contactPoint.getValue()); } else if (1 == contactPoint.getRank()) { target.setPhone1(contactPoint.getValue()); } else if (2 == contactPoint.getRank()) { target.setPhone2(contactPoint.getValue()); } } else if (ContactPointSystem.EMAIL.equals(contactPoint.getSystem())) { target.setEmail(contactPoint.getValue()); } else if (ContactPointSystem.FAX.equals(contactPoint.getSystem())) { target.setFax(contactPoint.getValue()); } } }
Example #26
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void mapName(Patient source, IPatient target) { List<HumanName> names = source.getName(); for (HumanName humanName : names) { if (HumanName.NameUse.OFFICIAL.equals(humanName.getUse())) { target.setFirstName(humanName.getGivenAsSingleString()); target.setLastName(humanName.getFamily()); target.setTitel(humanName.getPrefixAsSingleString()); target.setTitelSuffix(humanName.getSuffixAsSingleString()); } } }
Example #27
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private void mapIdentifiersAndPatientNumber(IPatient source, Patient target) { List<Identifier> identifiers = contactHelper.getIdentifiers(source); identifiers.add(getElexisObjectIdentifier(source)); String patNr = source.getPatientNr(); Identifier identifier = new Identifier(); identifier.setSystem(IdentifierSystem.ELEXIS_PATNR.getSystem()); identifier.setValue(patNr); identifiers.add(identifier); target.setIdentifier(identifiers); }
Example #28
Source File: IPatientPatientAttributeMapper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
/** * Selective support for mapping incoming identifiers. Currently only accepts * AHV Number * * @param source * @param target */ private void mapIdentifiers(Patient source, IPatient target) { // id must not be mapped (not updateable) // patientNumber must not be mapped (not updateable) List<Identifier> identifiers = source.getIdentifier(); for (Identifier identifier : identifiers) { if (XidConstants.CH_AHV.equals(identifier.getSystem())) { target.addXid(XidConstants.CH_AHV, identifier.getValue(), true); } } }
Example #29
Source File: ExampleServerR4IT.java From hapi-fhir-jpaserver-starter with Apache License 2.0 | 5 votes |
@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 #30
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; }