Retrieve JSON FHIR Data
Using the getFhir Method
getFhir MethodOverview
The getFhir method in the SDK allows you to retrieve FHIR resources in JSON format. This method is versatile, enabling you to search by Resource Type, a list of IDs, and a date filter. The retrieved resources are serialized FHIR JSON strings. You can specify the search criteria using the FhirRequest object, which is built using a fluent builder pattern.
Method Details
suspend fun getFhir(request: FhirRequest) : BWellResult<String>This method returns a list of FHIR resources that match the search criteria provided in the FhirRequest. The results are paginated, and you can navigate through them using the page parameter in the FhirRequest.
Builder Class: FhirRequest.Builder
FhirRequest.BuilderThe FhirRequest.Builder class provides the means to construct a FhirRequest object by setting various search parameters:
- Resource Type (
resourceType): Specifies the type of FHIR resource to retrieve, such asOBSERVATION,PATIENT, etc. - IDs (
ids): A list of resource IDs to filter the search results. Only resources with matching IDs will be returned. - Last Updated (
lastUpdated): A date filter to retrieve resources that have been updated after a certain date.
Date Filtering with GetFhirSearchDate
GetFhirSearchDateThe GetFhirSearchDate class is used to specify date-based search criteria. It supports the following operation:
- greaterThan: Retrieves resources updated after the specified date.
Example Usage
Here’s how you can use the getFhir method in practice:
val request = FhirRequest.Builder()
.resourceType(ResourceType.OBSERVATION)
.lastUpdated(
GetFhirSearchDate.Builder()
.greaterThan(dateFormat.parse("2024"))
.build()
)
.ids(listOf(
"5884a0f8-3d08-4077-a7fc-1817e5b8ce35",
"aab81d50-e53d-45e8-a881-fc22eb2f253f",
"3310e4f4-4a97-47fe-b0ed-7805421aa322",
"fd3fb48c-3565-40fb-be32-9ae014ad2860",
"875ff908-2ebe-46bf-8fe4-72644d7d039f",
"dfd1d287-2b84-45e0-bd5f-39c8c5efca2a"
))
.page(0)
.pageSize(20)
.build()
val result = BWellSdk.health.getFhir(request)Important Notes:
- ResourceType: Ensure the correct resource type is used to avoid empty results.
- IDs: If specified, only the resources matching these IDs will be returned.
- Date Filters: Combining different date filters (e.g.,
greaterThanandlessThan) allows for precise control over the time range of the resources returned.
Updated about 2 months ago
