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; } }
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); }
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()
@Test public void testGetResource() { DocumentManifest p = client.read() .resource(DocumentManifest.class) .withId("9bc72458-49b0-11e6-8a1c-3c1620524153") .execute(); assertEquals(String.format("http://localhost:%d/DocumentManifest/9bc72458-49b0-11e6-8a1c-3c1620524153", DEMO_APP_PORT), p.getId()); }
@Test public void testGetResource() { DocumentReference p = client.read() .resource(DocumentReference.class) .withId("63ab1c29-4225-11e6-9b33-0050569b0094") .execute(); assertEquals(String.format("http://localhost:%d/DocumentReference/63ab1c29-4225-11e6-9b33-0050569b0094", DEMO_APP_PORT), p.getId()); }
@Test public void testGetResource() { DocumentReference p = client.read() .resource(DocumentReference.class) .withId("63ab1c29-4225-11e6-9b33-0050569b0094") .execute(); assertEquals(String.format("http://localhost:%d/DocumentReference/63ab1c29-4225-11e6-9b33-0050569b0094", DEMO_APP_PORT), p.getId()); }
@Test public void testGetResource() { DocumentManifest p = client.read() .resource(DocumentManifest.class) .withId("9bc72458-49b0-11e6-8a1c-3c1620524153") .execute(); assertEquals(String.format("http://localhost:%d/DocumentManifest/9bc72458-49b0-11e6-8a1c-3c1620524153", DEMO_APP_PORT), p.getId()); }