public static void simpleExample() { // START SNIPPET: simple // We're connecting to a DSTU1 compliant server in this example FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // Perform a search Bundle results = client .search() .forResource(Patient.class) .where(Patient.FAMILY.matches().value("duck")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); System.out.println("Found " + results.getEntry().size() + " patients named 'duck'"); // END SNIPPET: simple }
@Override public ICriterion<?> values(String... theValues) { return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, Arrays.asList(theValues)); } }
/** * 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); }
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; } }
/** * 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); }
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; }
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 } }
/** * 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())); } }
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; }
@Override public ICriterion<StringClientParam> values(List<String> theValue) { return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, theValue); }
protected ICriterion<?> familyParameters() { return PdqPatient.FAMILY.matches().value("Test"); }
/** * 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())); } }
@Override public ICriterion<?> values(String... theValues) { return new StringCriterion<StringClientParam>(getParamName() + Constants.PARAMQUALIFIER_STRING_CONTAINS, Arrays.asList(theValues)); } }
protected ICriterion<?> familyParameters() { return PdqPatient.FAMILY.matches().value("Test"); }
@Override public ICriterion<StringClientParam> values(List<String> theValue) { return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue); }
.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
@Override public ICriterion<StringClientParam> values(List<String> theValue) { return new StringCriterion<>(getParamName(), theValue); }
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)); }
@Override public ICriterion<StringClientParam> value(String theValue) { return new StringCriterion<>(getParamName() + Constants.PARAMQUALIFIER_STRING_EXACT, theValue); }
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()); } }