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); }
private IReadExecutable<IBaseResource> readWithOptionalVersion(String stringId, IReadTyped<IBaseResource> resource, String version) { if (version != null) { return resource.withIdAndVersion(stringId, version); } return resource.withId(stringId); } }
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 }
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 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(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 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); }
/** * @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; } }
@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()); }
public static void main(String[] theArgs) { // Create a client IGenericClient client = FhirContext.forDstu3().newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); // Register some interceptors client.registerInterceptor(new CookieInterceptor("mycookie=Chips Ahoy")); client.registerInterceptor(new LoggingInterceptor()); // Read a Patient Patient patient = client.read().resource(Patient.class).withId("example").execute(); // Change the gender patient.setGender(patient.getGender() == AdministrativeGender.MALE ? AdministrativeGender.FEMALE : AdministrativeGender.MALE); // Update the patient MethodOutcome outcome = client.update().resource(patient).execute(); System.out.println("Now have ID: " + outcome.getId()); } }
@Test public void testGetResource() { PdqPatient p = client.read() .resource(PdqPatient.class) .withId("4711") .execute(); assertEquals("Test", p.getName().get(0).getFamily()); assertEquals(String.format("http://localhost:%d/Patient/4711", DEMO_APP_PORT), p.getId()); AbstractMockedAuditMessageQueue sender = getAuditSender(); assertEquals(1, sender.getMessages().size()); AuditMessage event = sender.getMessages().get(0); // Patient ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0); assertEquals(ParticipantObjectTypeCode.Person, patient.getParticipantObjectTypeCode()); assertEquals(ParticipantObjectTypeCodeRole.Patient, patient.getParticipantObjectTypeCodeRole()); assertEquals("Patient/4711", patient.getParticipantObjectID()); }
@Test public void testGetResource() { PdqPatient p = client.read() .resource(PdqPatient.class) .withId("4711") .execute(); assertEquals("Test", p.getName().get(0).getFamily().get(0).getValue()); assertEquals(String.format("http://localhost:%d/Patient/4711", DEMO_APP_PORT), p.getId()); AbstractMockedAuditMessageQueue sender = getAuditSender(); assertEquals(1, sender.getMessages().size()); AuditMessage event = sender.getMessages().get(0); // Patient ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0); assertEquals(ParticipantObjectTypeCode.Person, patient.getParticipantObjectTypeCode()); assertEquals(ParticipantObjectTypeCodeRole.Patient, patient.getParticipantObjectTypeCodeRole()); assertEquals("Patient/4711", patient.getParticipantObjectID()); }