@Create public MethodOutcome createPatient(@ResourceParam Patient patient) { patient.setId(createId(counter, 1L)); patients.put(String.valueOf(counter), patient); return new MethodOutcome(patient.getIdElement()); }
protected void createSubscription(Class<? extends IBaseResource> clazz) { String resourceName = clazz.getSimpleName(); String id = patient.getIdElement().getIdPart(); String criteria = resourceName + "?subject=" + id; SubscriptionWrapper wrapper = subscriptionManager.subscribe(criteria, subscriptionListener); if (wrapper != null) { subscriptions.add(wrapper); } }
@Override protected void requestData() { final String url = resourcePath.replace("#", patient.getIdElement().getIdPart()); startBackgroundThread(new IRunnable() { @Override public void run(ThreadEx thread) throws Exception { Bundle bundle = fhirService.getClient().search().byUrl(url).returnBundle(Bundle.class).execute(); thread.setAttribute("bundle", bundle); } @Override public void abort() { } }); }
String info = ids.get(patient.getIdElement().getIdPart()); PatientListItem item = new PatientListItem(patient, info);
/** * Populate context map with information about currently selected patient. * * @param context Context map to be populated. */ @Override protected void updateContext(ContextMap context) { Patient patient = PatientContext.getActivePatient(); if (patient != null) { context.put("patientId", patient.getIdElement().getIdPart()); } }
patids.add(pat.getIdElement().getIdPart());
/** * 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()); }
@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()); }