private static void tmp() { // Create a FHIR Context FhirContext ctx = FhirContext.forDstu2(); // Create a client IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2"); // Read a patient with the given ID Patient patient = client .read() .resource(Patient.class) .withId("952975") .execute(); // Print the patient's name String string = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(string); }
public void customTypeDeclared() { //START SNIPPET: customTypeClientDeclared FhirContext ctx = FhirContext.forDstu3(); // Instruct the context that if it receives a resource which // claims to conform to the given profile (by URL), it should // use the MyPatient type to parse this resource ctx.setDefaultTypeForProfile("http://example.com/StructureDefinition/mypatient", MyPatient.class); // You can declare as many default types as you like ctx.setDefaultTypeForProfile("http://foo.com/anotherProfile", CustomObservation.class); // Create a client IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); // You can also read the resource back like normal Patient patient = client.read().resource(Patient.class).withId("123").execute(); if (patient instanceof MyPatient) { // If the server supplied a resource which declared to conform // to the given profile, MyPatient will have been returned so // process it differently.. } //END SNIPPET: customTypeClientDeclared }
@Override public MethodOutcome invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { MethodOutcome response = MethodUtil.process2xxResponse(myContext, theResponseStatusCode, theResponseMimeType, theResponseInputStream, theHeaders); response.setCreatedUsingStatusCode(theResponseStatusCode); if (myPrefer == PreferReturnEnum.REPRESENTATION) { if (response.getResource() == null) { if (response.getId() != null && isNotBlank(response.getId().getValue()) && response.getId().hasBaseUrl()) { ourLog.info("Server did not return resource for Prefer-representation, going to fetch: {}", response.getId().getValue()); IBaseResource resource = read().resource(response.getId().getResourceType()).withUrl(response.getId()).execute(); response.setResource(resource); } } } response.setResponseHeaders(theHeaders); return response; } }
custPatient = client.read().resource(MyPatient.class).withId("123").execute();
@Override public IClientExecutable<IReadExecutable<Patient>, Patient> getClientExecutable(IGenericClient client, Object requestData, Map<String, Object> parameters) { IClientExecutable<IReadExecutable<Patient>, Patient> executable = client.read() .resource(Patient.class) .withId(requestData.toString()); return executable; } }
@Override public IClientExecutable<IReadExecutable<Patient>, Patient> getClientExecutable(IGenericClient client, Object requestData, Map<String, Object> parameters) { return client.read() .resource(Patient.class) .withId(requestData.toString()); } }
public IBaseResource resourceByUrl(String resourceClass, IIdType iUrl, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withUrl(iUrl); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceById(Class<IBaseResource> resource, IIdType id, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withId(id); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceById(Class<IBaseResource> resource, String stringId, String version, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadTyped<IBaseResource> readTyped = client.read().resource(resource); IReadExecutable<IBaseResource> readExecutable = readWithOptionalVersion(stringId, readTyped, version); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceById(String resourceClass, String stringId, String ifVersionMatches, String version, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadTyped<IBaseResource> resource = client.read().resource(resourceClass); IReadExecutable<IBaseResource> readExecutable = readWithOptionalVersion(stringId, resource, version); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceByUrl(Class<IBaseResource> resource, IIdType iUrl, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withUrl(iUrl); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceByUrl(String resourceClass, String url, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withUrl(url); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceById(String resourceClass, IIdType id, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withId(id); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceById(Class<IBaseResource> resource, Long longId, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withId(longId); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceByUrl(Class<IBaseResource> resource, String url, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withUrl(url); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public IBaseResource resourceById(String resourceClass, Long longId, String ifVersionMatches, Boolean returnNull, IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters) { IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withId(longId); ExtraParameters.process(extraParameters, readExecutable); return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError, readExecutable); }
public static void step1_read_a_resource() { FhirContext ctx = FhirContext.forDstu3(); IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); Patient patient; try { // Try changing the ID from 952975 to 999999999999 patient = client.read().resource(Patient.class).withId("952975").execute(); } catch (ResourceNotFoundException e) { System.out.println("Resource not found!"); return; } String string = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(string); }
Patient patient = client.read().resource(Patient.class).withId("123").execute(); .resource(Patient.class) .withId("123") .execute(); .resource(Patient.class) .withIdAndVersion("123", "888") .execute(); .resource(Patient.class) .withUrl(url) .execute(); .resource(Patient.class) .withId("123") .ifVersionMatches("001").returnNull()
/** * @return The location resource corresponding to the location id in context. If caching is enabled, this * resource will be remembered for subsequent calls, and not loaded fresh with each call. */ public Location getLocationResource() { String locationId = getLocationId(); if (locationId != null) { if (enableCaching) { // is the id matching the prior loaded location? if (priorLocation != null && priorLocation.getId() != null) { if (locationId.equals(priorLocation.getId())) { return priorLocation; } } } // find the location priorLocation = session.read().resource(Location.class).withId(locationId).execute(); return priorLocation; } else { priorLocation = null; return null; } }
/** * @return The location resource corresponding to the location id in context. If caching is enabled, this * resource will be remembered for subsequent calls, and not loaded fresh with each call. */ public Location getLocationResource() { String locationId = getLocationId(); if (locationId != null) { if (enableCaching) { // is the id matching the prior loaded location? if (priorLocation != null && priorLocation.getId() != null) { if (locationId.equals(priorLocation.getId())) { return priorLocation; } } } // find the location priorLocation = session.read().resource(Location.class).withId(locationId).execute(); return priorLocation; } else { priorLocation = null; return null; } }