Reputation: 105
I want the fetch the list of resource types available for a patient from the FHIR server. I tried to fetch the List of items from the Patient. But it doesn't contain all the resource types available for that particular patient.
Upvotes: 1
Views: 1789
Reputation: 105
Thank you all for posting your answers. I have achieved this by making a batch request like the below,
Bundle bundle = new Bundle();
bundle.setType(Bundle.BundleType.TRANSACTION);
// Adding bundle entries to make the batch request
// To fetch the resource count for each resource type
for (String resource : resources) {
String url = String.format(MyConstants.URLs.FETCH_SUMMARY_COUNT,
resource, patientId);
bundle.addEntry().getRequest().setUrl(url).setMethod(Bundle.HTTPVerb.GET);
}
try {
// Create a client
IGenericClient client = fhirContext.newRestfulGenericClient(fhirServerUrl);
BearerTokenAuthInterceptor bearerTokenAuthInterceptor = new BearerTokenAuthInterceptor(accessToken);
client.registerInterceptor(bearerTokenAuthInterceptor);
bundle = client.transaction().withBundle(bundle).execute();
IFhirPath iFhirPath = fhirContext.newFhirPath();
List<IntegerType> counts = iFhirPath.evaluate(bundle, MyConstants.FHIRPATH.SUMMARY_COUNT_FROM_BUNDLE,
IntegerType.class);
ResourceTypesResponse resourceTypesResponse = ResourceParser.getResourceTypes(counts, resources);
if (resourceTypesResponse == null) {
throw new PatientNotFoundException("Resource Not Found");
}
return resourceTypesResponse;
} catch (Exception e) {
if (e.getMessage().equalsIgnoreCase("HTTP 401 Unauthorized")) {
return getResourceBundleForPatient(patientId, resources);
} else {
throw new PatientNotFoundException("Patient Id Not Found");
}
}
Upvotes: 0
Reputation: 27852
http://hapi.fhir.org/baseR4/metadata
http://wildfhir4.aegis.net/fhir4-0-1/metadata
https://vonk.fire.ly/R4/metadata
I think you're asking this.
If you examine any of the reference implementations above: you'll retrieve the CapabilityStatement.
EVERY FHIR server must supply a CapabilityStatement.
You look at the CapabilityStatement, find the Fhir-Resource ("Patient" here), and then any includes and rev-includes.
"type": "Patient",
"searchInclude": [
"Patient:general-practitioner",
"Patient:link",
"Patient:organization"
],
"searchRevInclude": [
"Account:patient",
"Account:subject",
also see:
https://www.hl7.org/fhir/search.html#include
Upvotes: 1
Reputation: 520
When you say "the list of resource types available for a patient from the FHIR server", I think what you mean is the resource types that can be searched by patient on the FHIR server.
To build such a list, read the FHIR server's CapabilityStatement
. Iterate through the CapabilityStatement's resource
array, checking each item's searchParam
array for an element where name
= 'patient' and type
= 'reference'. If you find it, add that item's type
value (i.e. the resource type) to the list.
Upvotes: 2
Reputation: 471
I think what your asking is resources types linked to a Patient. In this case you can do a http://base/fhir/Patient/[id]/$everything
https://hl7.org/fhir/operation-patient-everything.html
Upvotes: 1