/** * Alternative method for performing a search that allows for external configuration of the * query object. * * @param query The query object. * @return List of matching resources. May return null to indicate no matches. */ @Override public List<R> search(IQuery<?> query) { return FhirUtil.getEntries(query.returnBundle(Bundle.class).execute(), resourceClass); } }
Boolean encode = (Boolean) extraParameters.get(ENCODE_JSON); if (encode) { clientExecutable.encodedJson(); Boolean encodeXml = (Boolean) extraParameters.get(ENCODE_XML); if (encodeXml) { clientExecutable.encodedXml(); clientExecutable.cacheControl(cacheControlDirective); break; case SUBSET_ELEMENTS: String[] subsetElements = (String[]) extraParameters.get(SUBSET_ELEMENTS); clientExecutable.elementsSubset(subsetElements); break; case ENCODING_ENUM: EncodingEnum encodingEnum = (EncodingEnum) extraParameters.get(ENCODING_ENUM); clientExecutable.encoded(encodingEnum); break; case PREFER_RESPONSE_TYPE: Class<? extends IBaseResource> type = (Class<? extends IBaseResource>) extraParameters.get(PREFER_RESPONSE_TYPE); clientExecutable.preferResponseType(type); break; case PREFER_RESPONSE_TYPES: List<Class<? extends IBaseResource>> types = (List<Class<? extends IBaseResource>>) extraParameters.get(PREFER_RESPONSE_TYPES); clientExecutable.preferResponseTypes(types); break; case PRETTY_PRINT: Boolean prettyPrint = (Boolean) extraParameters.get(PRETTY_PRINT); if (prettyPrint) {
/** * Fetch the current metadata from a specific resource * @param extraParameters see {@link ExtraParameters} for a full list of parameters that can be passed, may be NULL * @param metaType the {@link IBaseMetaType} class * @param id the id * @param <T> extends {@link IBaseMetaType} * @return the {@link IBaseMetaType} */ public <T extends IBaseMetaType> T getFromResource(Class<T> metaType, IIdType id, Map<ExtraParameters, Object> extraParameters) { IClientExecutable<IClientExecutable<?, T>, T> clientExecutable = client.meta().get(metaType).fromResource(id); ExtraParameters.process(extraParameters, clientExecutable); return clientExecutable.execute(); }
/** * Fetch the current metadata from a specific type * @param <T> extends {@link IBaseMetaType} * @param metaType the {@link IBaseMetaType} class * @param resourceType the resource type e.g "Patient" * @param extraParameters see {@link ExtraParameters} for a full list of parameters that can be passed, may be NULL * @return the {@link IBaseMetaType} */ public <T extends IBaseMetaType> T getFromType(Class<T> metaType, String resourceType, Map<ExtraParameters, Object> extraParameters) { IClientExecutable<IClientExecutable<?, T>, T> clientExecutable = client.meta().get(metaType).fromType(resourceType); ExtraParameters.process(extraParameters, clientExecutable); return clientExecutable.execute(); }
/** * Fetch the current metadata from the whole Server * * @param metaType The type of the meta datatype for the given FHIR model version (should be <code>MetaDt.class</code> or <code>MetaType.class</code>) * @param <T> extends {@link IBaseMetaType} * @param extraParameters see {@link ExtraParameters} for a full list of parameters that can be passed, may be NULL * @return the {@link IBaseMetaType} */ public <T extends IBaseMetaType> T getFromServer(Class<T> metaType, Map<ExtraParameters, Object> extraParameters) { IClientExecutable<IClientExecutable<?, T>, T> clientExecutable = client.meta().get(metaType).fromServer(); ExtraParameters.process(extraParameters, clientExecutable); return clientExecutable.execute(); }
@Override public void run(ThreadEx thread) throws Exception { Bundle bundle = fhirService.getClient().search().byUrl(url).returnBundle(Bundle.class).execute(); thread.setAttribute("bundle", bundle); }
/** * Add the elements in the given metadata to the already existing set (do not remove any) * @param <T> extends {@link IBaseMetaType} * @param id the id * @param meta the {@link IBaseMetaType} class * @param extraParameters see {@link ExtraParameters} for a full list of parameters that can be passed, may be NULL * @return the {@link IBaseMetaType} */ public <T extends IBaseMetaType> T add(T meta, IIdType id, Map<ExtraParameters, Object> extraParameters) { IClientExecutable<IClientExecutable<?, T>, T> clientExecutable = client.meta().add().onResource(id).meta(meta); ExtraParameters.process(extraParameters, clientExecutable); return clientExecutable.execute(); }
/** * 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); }
/** * Delete the elements in the given metadata from the given id * @param <T> extends {@link IBaseMetaType} * @param id the id * @param meta the {@link IBaseMetaType} class * @param extraParameters see {@link ExtraParameters} for a full list of parameters that can be passed, may be NULL * @return the {@link IBaseMetaType} */ public <T extends IBaseMetaType> T delete(T meta, IIdType id, Map<ExtraParameters, Object> extraParameters) { IClientExecutable<IClientExecutable<?, T>, T> clientExecutable = client.meta().delete().onResource(id).meta(meta); ExtraParameters.process(extraParameters, clientExecutable); return clientExecutable.execute(); } }
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; }
/** * General purpose find * * @param clazz Resource class to find * @param criterion Criterion to be applied to the query. Must include a patient matching criterion * @param <T> Resource * @return A list of resource matching the criterion */ public <T extends IBaseResource> Collection<T> find(Class<T> clazz, ICriterion<?>... criterion) { String patientId = session.getContextSTU3().getPatientResource().getIdElement().getIdPart(); IQuery<ca.uhn.fhir.model.api.Bundle> queryBuilder = session.search().forResource(clazz); // use reflection to match the getPatientContext criterion queryBuilder.where(findPatientReferenceOnResource(clazz).hasId(patientId)); for (ICriterion<?> theCriterion : criterion) { queryBuilder = queryBuilder.and(theCriterion); } IClientExecutable<IQuery<Bundle>, Bundle> results = queryBuilder.returnBundle(Bundle.class); return asCollection(results.execute()); }
/** * General purpose find * * @param clazz Resource class to find * @param criterion Criterion to be applied to the query. Must include a patient matching criterion * @param <T> Resource * @return A list of resource matching the criterion */ public <T extends IResource> Collection<T> find(Class<T> clazz, ICriterion<?>... criterion) { String patientId = session.getContextDSTU2().getPatientResource().getIdElement().getIdPart(); IQuery<ca.uhn.fhir.model.api.Bundle> queryBuilder = session.search().forResource(clazz); // use reflection to match the getPatientContext criterion queryBuilder.where(findPatientReferenceOnResource(clazz).hasId(patientId)); for (ICriterion<?> theCriterion : criterion) { queryBuilder = queryBuilder.and(theCriterion); } IClientExecutable<IQuery<Bundle>, Bundle> results = queryBuilder.returnBundle(Bundle.class); return asCollection(results.execute()); }
@Test public void testClient() { FhirContext ctx = new FhirContext(FhirVersionEnum.DSTU3); GenericClient client = (GenericClient) ctx.newRestfulGenericClient(FHIR_EP); //client.registerInterceptor(new BasicAuthInterceptor("user123", "user321$")); client.setDontValidateConformance(true); Bundle bundle = client.search().forResource(Patient.class).count(1).returnBundle(Bundle.class).execute(); assertTrue("No patient resources returned.", bundle.getEntry().size() > 0); Patient patient = (Patient) bundle.getEntryFirstRep().getResource(); String patient_id = patient.getIdElement().getIdPart(); Patient patient1 = client.read(Patient.class, "Patient/" + patient_id); assertEquals(patient_id, patient1.getIdElement().getIdPart()); bundle = client.search().byUrl("Patient?_id=" + patient_id).returnBundle(Bundle.class).execute(); assertEquals(1, bundle.getEntry().size()); Patient patient2 = (Patient) bundle.getEntry().get(0).getResource(); assertEquals(patient_id, patient2.getIdElement().getIdPart()); }