@Search private List<IBaseResource> searchForPatients() { // Create an organization Organization org = new Organization(); org.setId("Organization/65546"); org.setName("Test Organization"); // Create a patient Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier().setSystem("urn:mrns").setValue("253345"); patient.getManagingOrganization().setResource(org); // Here we return only the patient object, which has links to other resources List<IBaseResource> retVal = new ArrayList<IBaseResource>(); retVal.add(patient); return retVal; } // END SNIPPET: addIncludes
/** * Returns a resource given a resource reference. If the resource has not been previously * fetched, it will be fetched from the server. * * @param reference A resource reference. * @return The corresponding resource. */ public static IBaseResource getResource(ResourceReferenceDt reference) { if (reference.isEmpty()) { return null; } if (reference.getResource() != null) { return reference.getResource(); } IdDt resourceId = reference.getReference(); if (resourceId == null) { throw new IllegalStateException("Reference has no resource ID defined"); } String resourceUrl = expandURL(resourceId.getValue()); IBaseResource resource = getFhirClient().read(new UriDt(resourceUrl)); reference.setResource(resource); return resource; }