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.dstu3.model.Bundle results = client .search() .forResource(Patient.class) .where(Patient.NAME.matches().value("test")) .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) .execute(); System.out.println("First page: "); System.out.println(ctx.newXmlParser().encodeResourceToString(results)); // Load the next page org.hl7.fhir.dstu3.model.Bundle nextPage = client .loadPage() .next(results) .execute(); System.out.println("Next page: "); System.out.println(ctx.newXmlParser().encodeResourceToString(nextPage)); }
private static synchronized void loadServiceCategories() { if (serviceCategories == null) { Map<String, CodeableConcept> map = new LinkedHashMap<>(); Bundle bundle = ClientUtil.getFhirClient().search().forResource(ValueSet.class) .where(CodeSystem.NAME.matchesExactly().value("EncounterType")).returnBundle(Bundle.class).execute(); for (CodeSystem cs : FhirUtil.getEntries(bundle, CodeSystem.class)) { UriType system = cs.getUrlElement(); for (ConceptDefinitionComponent concept : cs.getConcept()) { CodeableConcept cc = new CodeableConcept(); Coding coding = cc.addCoding(); coding.setCode(concept.getCode()); coding.setDisplay(concept.getDisplay()); coding.setSystemElement(system); cc.setText(concept.getDefinition()); map.put(coding.getCode(), cc); } } serviceCategories = map; } return; }
@Override public void buildQuery(PractitionerSearchCriteria criteria, IQuery<Bundle> query) { super.buildQuery(criteria, query); if (criteria.getDEA() != null) { query.where(Practitioner.IDENTIFIER.exactly().identifier(criteria.getDEA())); } if (criteria.getSSN() != null) { query.where(Practitioner.IDENTIFIER.exactly().identifier(criteria.getSSN())); } if (criteria.getGender() != null) { query.where(Practitioner.GENDER.exactly().code(criteria.getGender())); } if (criteria.getName() != null) { HumanNameDt name = criteria.getName(); if (!name.getFamily().isEmpty()) { query.where(Practitioner.FAMILY.matches().values(FhirUtil.toStringList(name.getFamily()))); } if (!name.getGiven().isEmpty()) { query.where(Practitioner.GIVEN.matches().values(FhirUtil.toStringList(name.getGiven()))); } } }
private static synchronized void loadServiceCategories() { if (serviceCategories == null) { Map<String, CodeableConceptDt> map = new LinkedHashMap<String, CodeableConceptDt>(); Bundle bundle = ClientUtil.getFhirClient().search().forResource(ValueSet.class) .where(ValueSet.NAME.matchesExactly().value("EncounterType")).execute(); for (ValueSet vs : FhirUtil.getEntries(bundle, ValueSet.class)) { UriDt system = vs.getDefine().getSystemElement(); for (ValueSet.DefineConcept concept : vs.getDefine().getConcept()) { CodeableConceptDt cc = new CodeableConceptDt(); CodingDt coding = cc.addCoding(); coding.setCode(concept.getCode()); coding.setDisplay(concept.getDisplay()); coding.setSystem(system); cc.setText(concept.getDefinition()); map.put(coding.getCode(), cc); } } serviceCategories = map; } return; }
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()); } }
/** * Validates the criteria settings and then transfers them to the query object. This method * transfers the base criteria only. Override to transfer additional criteria that are specific * to the resource type. * * @param criteria Research search criteria. * @param query The query object. */ protected void buildQuery(C criteria, IQuery<?> query) { criteria.validate(); if (criteria.getMaximum() > 0) { query.count(criteria.getMaximum()); } if (criteria.getId() != null) { query.where(new StringClientParam(BaseResource.SP_RES_ID).matches().value(criteria.getId())); } }
/** * Validates the criteria settings and then transfers them to the query object. This method * transfers the base criteria only. Override to transfer additional criteria that are specific * to the resource type. * * @param criteria Research search criteria. * @param query The query object. */ protected void buildQuery(C criteria, IQuery<Bundle> query) { criteria.validate(); if (criteria.getMaximum() > 0) { query.limitTo(criteria.getMaximum()); } if (criteria.getId() != null) { query.where(new StringClientParam(BaseResource.SP_RES_ID).matches().value(criteria.getId())); } }
protected ICriterion<?> familyParameters() { return PdqPatient.FAMILY.matches().value("Test"); }
@Override public void buildQuery(LocationSearchCriteria criteria, IQuery<?> query) { super.buildQuery(criteria, query); if (criteria.getType() != null) { query.where(Location.TYPE.exactly().code(criteria.getType())); } if (criteria.getStatus() != null) { query.where(Location.STATUS.exactly().code(criteria.getStatus().toCode())); } if (criteria.getName() != null) { query.where(Location.NAME.matches().value(criteria.getName())); } }
public Collection<String> getTypes() { TreeSet<String> results = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); try { Bundle bundle = ClientUtil.getFhirClient().search().forResource(ValueSet.class) .where(ValueSet.NAME.matchesExactly().value("DocumentType")).execute(); for (ValueSet vs : FhirUtil.getEntries(bundle, ValueSet.class)) { for (ValueSet.DefineConcept concept : vs.getDefine().getConcept()) { results.add(concept.getDisplay().toString()); } } } catch (Exception e) {} return results; } }
protected ICriterion<?> familyParameters() { return PdqPatient.FAMILY.matches().value("Test"); }
/** * Fetch multiple instances of the domain class from the data store. */ @Override public <T extends BaseResource> List<T> fetchObjects(Class<T> clazz, String[] ids) { if (ids == null || ids.length == 0) { return Collections.emptyList(); } StringClientParam param = new StringClientParam(BaseResource.SP_RES_ID); Bundle results = fhirClient.search().forResource(clazz).where(param.matches().values(ids)).execute(); return FhirUtil.getEntries(results, clazz); }
@Test public void testSendManualPdqmWithBirthdayRange() { Bundle result = client.search() .forResource(PdqPatient.class) .where(PdqPatient.BIRTHDATE.exactly().day("2011-12-31")) .and(PdqPatient.FAMILY.matches().value("Miller")) .returnBundle(Bundle.class) .execute(); assertEquals(Bundle.BundleType.SEARCHSET, result.getType()); assertEquals(ResourceType.Bundle, result.getResourceType()); assertTrue(result.hasEntry()); }
@Override public void buildQuery(LocationSearchCriteria criteria, IQuery<Bundle> query) { super.buildQuery(criteria, query); if (criteria.getType() != null) { query.where(Location.TYPE.exactly().code(criteria.getType().getCode())); } if (criteria.getStatus() != null) { query.where(Location.STATUS.exactly().code(criteria.getStatus().getCode())); } if (criteria.getName() != null) { query.where(Location.NAME.matches().value(criteria.getName())); } }
/** * Fetch multiple instances of the domain class from the data store. */ @Override public <T extends BaseResource> List<T> fetchObjects(Class<T> clazz, String[] ids) { if (ids == null || ids.length == 0) { return Collections.emptyList(); } StringClientParam param = new StringClientParam(BaseResource.SP_RES_ID); Bundle results = fhirClient.search().forResource(clazz).where(param.matches().values(ids)).returnBundle(Bundle.class) .execute(); return FhirUtil.getEntries(results, clazz); }
.forResource(Patient.class) .where(Patient.BIRTHDATE.beforeOrEquals().day("2011-01-01")) .and(Patient.CAREPROVIDER.hasChainedProperty(Organization.NAME.matches().value("Health"))) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); .where(Patient.FAMILY.matches().values("Smith", "Smyth")) .returnBundle(Bundle.class) .execute(); .where(Patient.ADDRESS.matches().values("Toronto")) .and(Patient.ADDRESS.matches().values("Ontario")) .and(Patient.ADDRESS.matches().values("Canada")) .returnBundle(Bundle.class) .execute(); .forResource(Patient.class) .withIdAndCompartment("123", "condition") .where(Patient.ADDRESS.matches().values("Toronto")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); .where(Patient.ADDRESS.matches().values("Toronto")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .summaryMode(SummaryEnum.TRUE) .where(Patient.ADDRESS.matches().values("Toronto")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .elementsSubset("identifier", "name") // only include the identifier and name
private static void paging() { { // START SNIPPET: searchPaging FhirContext ctx = FhirContext.forDstu2(); IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2"); // Perform a search Bundle resultBundle = client.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("Smith")) .returnBundle(Bundle.class) .execute(); if (resultBundle.getLink(Bundle.LINK_NEXT) != null) { // load next page Bundle nextPage = client.loadPage().next(resultBundle).execute(); } // END SNIPPET: searchPaging } }