health.fhirr4
Module health.fhirr4
API
Definitions
ballerinax/health.fhirr4 Ballerina library
Package containing the FHIR R4 service type that can be used for creating FHIR APIs
FHIR Service Type
Ballerina FHIR service type can be used for developing FHIR APIs. It provides a range of capabilities related to FHIR APIs that make development much easier.
Capabilitites and features
- Validating search parameters.
- Parsing and validating the request payload when creating FHIR resources.
- Validating content-related headers.
- Executing post-processing logic that can be plugged in.
- Handling errors in all these validations and responding an operation outcome.
Classes
health.fhirr4: DefaultConsentEnforcer
Default implementation of the ConsentEnforcer interface. Checks if the resource type matches any approved consent element.
Constructor
Initializes the DefaultConsentEnforcer and creates the OpenFGC client
init ()getConsentDetails
function getConsentDetails(string userIds, string consentStatuses) returns ConsentResponse|errorRetrieves consent information related to action
Parameters
- userIds string - Comma-separated user IDs to filter by
- consentStatuses string (default ACTIVE_CONSENT_STATUS) - Comma-separated consent statuses to filter by
Return Type
- ConsentResponse|error - ConsentResponse if successful, or an error if the consent details retrieval fails
validateConsent
function validateConsent(string consentId) returns ConsentValidationResponse|errorValidates a consent using its ID and retrieves detailed consent information
Parameters
- consentId string - The unique identifier of the consent to validate
Return Type
- ConsentValidationResponse|error - ConsentValidationResponse if successful, or an error if validation fails
getAndValidateConsents
function getAndValidateConsents(string patientId) returns ConsentResponse|errorGets and validates all consents for a user
Parameters
- patientId string - The patient ID to retrieve consents for
Return Type
- ConsentResponse|error - ConsentResponse with validated consents or an error
enforce
function enforce(string userID) returns ConsentContext|errorRetrieves resource types approved by user consent. Iterates through all consents and collects resource types from approved consent elements.
Parameters
- userID string - The user ID for which consent needs to be enforced
Return Type
- ConsentContext|error - ConsentContext containing consented resource types or error if enforcement fails
health.fhirr4: FHIRPreprocessor
FHIR Pre-processor implementation.
Constructor
Initialize the FHIR pre-processor
init (ResourceAPIConfig apiConfig)- apiConfig ResourceAPIConfig - The API configuration
processRead
function processRead(string fhirResourceType, string id, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Read interaction.
Parameters
- fhirResourceType string - The FHIR resource type
- id string - The FHIR resource id
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - The next service or an error
processSearch
function processSearch(string fhirResourceType, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Search interaction.
Parameters
- fhirResourceType string - The FHIR resource type
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - The next service or an error
processCreate
function processCreate(string resourceType, json|xml payload, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Create interaction.
Parameters
- resourceType string - The FHIR resource type
- payload json|xml - The payload
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - The next service or an error
processInstanceHistory
function processInstanceHistory(string fhirResourceType, string id, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Instance History interaction.
Parameters
- fhirResourceType string - The FHIR resource type
- id string - The FHIR resource id
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - Error if occurs
processVread
function processVread(string fhirResourceType, string id, string vid, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Vread interaction.
Parameters
- fhirResourceType string - The FHIR resource type
- id string - The FHIR resource id
- vid string - Resource's version id
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - Error if occurs
processHistory
function processHistory(Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR History interaction.
Return Type
- FHIRError? - Error if occurs
processCapability
function processCapability(Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Capabilities interaction.
Return Type
- FHIRError? - Error if occurs
processUpdate
function processUpdate(string fhirResourceType, string id, json payload, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Update interaction.
Parameters
- fhirResourceType string - The FHIR resource type
- id string - The FHIR resource id
- payload json - Request payload
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - The next service or an error
processPatch
function processPatch(string fhirResourceType, string id, json payload, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Patch interaction.
Parameters
- fhirResourceType string - The FHIR resource type
- id string - The FHIR resource id
- payload json - Request payload
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - The next service or an error
processDelete
function processDelete(string fhirResourceType, string id, Request httpRequest, RequestContext httpCtx) returns FHIRError?Process the FHIR Delete interaction.
Parameters
- fhirResourceType string - FHIR resource
- id string - Resource ID
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP request context
Return Type
- FHIRError? - Error if occurs
processOperation
function processOperation(string fhirResourceType, string fhirOperation, FHIRInteractionLevel operationRequestScope, json|xml? payload, Request httpRequest, RequestContext httpCtx) returns FHIRError?Processes a FHIR operation request.
Parameters
- fhirResourceType string - The FHIR resource type
- fhirOperation string - The FHIR operation to be processed
- operationRequestScope FHIRInteractionLevel - The scope of the operation request
- payload json|xml? - The payload of the request
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP context
Return Type
- FHIRError? - A
r4:FHIRErrorif an error occurs during the processing, or()otherwise
processIPSGenerateOperation
function processIPSGenerateOperation(string patientId, json|xml? payload, FHIRInteractionLevel operationRequestScope, string baseResourcePath, OperationConfig[] patientOperationConfigs, Request httpRequest, RequestContext httpCtx) returns FHIRError|BundleProcesses a FHIR IPS generation operation request. IPS generation is a special Patient-level operation with the following characteristics:
- POST request only
- Operation name: "summary"
- Resource path: Patient/[id]/$summary or Patient/$summary
- Instance level operation scope
Parameters
- patientId string - The patient ID for which to generate IPS
- payload json|xml? - The payload of the request
- operationRequestScope FHIRInteractionLevel - The scope of the operation request
- baseResourcePath string - The base resource path for the operation
- patientOperationConfigs OperationConfig[] - The operation configurations for the Patient resource
- httpRequest Request - The HTTP request
- httpCtx RequestContext - The HTTP context
health.fhirr4: FHIRResponseErrorInterceptor
Response error interceptor to handle errors thrown by fhir preproccessors
interceptResponseError
function interceptResponseError(error err) returns NotFound|BadRequest|UnsupportedMediaType|NotAcceptable|Unauthorized|NotImplemented|MethodNotAllowed|InternalServerError|PreconditionFailed|OkParameters
- err error -
health.fhirr4: FHIRResponseInterceptor
Response error interceptor to post-process FHIR responses
interceptResponse
function interceptResponse(RequestContext ctx, Response res) returns NextService|FHIRError?Service types
health.fhirr4: Service
Represents a FHIR service type
Listeners
health.fhirr4: Listener
Represents a FHIR listener endpoint
attach
'start
function 'start() returns error?gracefulStop
function gracefulStop() returns error?immediateStop
function immediateStop() returns error?detach
Parameters
- fhirService Service -
Configurables
health.fhirr4: analytics
health.fhirr4: analyticsPayloadEnrichConfig
health.fhirr4: consentEnforcement
Records
health.fhirr4: AnalyticsConfig
AnalyticsConfig Record.
Fields
- enabled boolean(default false) - if analytics is enabled or not
- fhirServerContext string(default DEFAULT_SERVER_CONTEXT) -
- jwtAttributes string[] - the attributes that should be extracted from JWT for analytics
- shouldPublishPayloads boolean(default false) - whether to include request/response payloads in analytics
- filePath string(default DEFAULT_FILE_LOCATION) - the file path where analytics logs are stored, if not configured, defaults to the server's directory
- fileName string(default LOG_FILE_NAME) - the name of the analytics log file
- allowedApiContexts? string[] -
- excludedApiContexts? string[] -
- enrichPayload? AnalyticsPayloadEnrich - configuration for enriching analytics payloads with additional information
health.fhirr4: AnalyticsData
Represents the complete analytics data structure
Fields
- request Request - Request
- response? Response - Response
- user_id? string - User ID
- company_id? string - Company ID
- transaction_id? string - Transaction ID
- trace_id? string - Trace ID
- metadata? json - Metadata
health.fhirr4: AnalyticsDataRecord
Fields
- requestPayload? json -
- responsePayload? json -
- statusCode int -
- requestPath string -
- httpMethod string -
health.fhirr4: AnalyticsPayloadEnrich
MoreInfoConfig Record.
Fields
- enabled boolean(default false) - if more info fetching is enabled or not
- url? string - the URL to fetch more information
- username? string - the username for the more info server
- password? string - the password for the more info server
health.fhirr4: Consent
Represents a single consent record. Contains comprehensive information about a user's consent including purposes, authorizations, and validity.
Fields
- id? string - Unique identifier for the consent
- purposes? ConsentPurpose[] - Array of purposes for which the consent is granted
- createdTime? int - The timestamp when this consent was created (in milliseconds)
- updatedTime? int - The timestamp when this consent was last updated (in milliseconds)
- clientId? string - The client application ID that requested this consent
- 'type? string -
- status? string - The current status of the consent (e.g., "ACTIVE", "CREATED", "REVOKED")
- frequency? int - The frequency of data access allowed under this consent
- validityTime? int - The timestamp until which this consent is valid (in milliseconds)
- recurringIndicator? boolean - Indicates whether this consent allows recurring access
- dataAccessValidityDuration? int - Duration for which data access is valid under this consent
- attributes? record {} - Additional custom attributes associated with the consent
- authorizations? ConsentAuthorization[] - Array of authorization entries for this consent
health.fhirr4: ConsentAuthorization
Represents an authorization entry. Contains information about a user's authorization for a specific consent.
Fields
- id? string - Unique identifier for the authorization
- userId? string - The user ID associated with this authorization (e.g., "Patient/991")
- 'type? string -
- status? string - The current status of the authorization (e.g., "APPROVED", "REJECTED")
- updatedTime? int - The timestamp when this authorization was last updated (in milliseconds)
- resources? record {} - Additional resource information associated with the authorization
health.fhirr4: ConsentElement
Represents a consent element with user approval status. Contains information about specific data elements that can be accessed under a consent purpose.
Fields
- name string - The name of the consent element (e.g., "fhir-patient-v1")
- isUserApproved boolean - Indicates whether the user has approved this element
- value? record {} - Additional attributes or metadata associated with the element
- isMandatory? boolean - Indicates whether this element is mandatory
- 'type? string -
- description? string - Description of what this element allows
- properties? record {} - Additional properties containing resource-specific information
health.fhirr4: ConsentEnforcementConfig
ConsentEnforcementConfig Record.
Fields
- enabled boolean(default false) - if consent enforcement is enabled or not
- openFgcClient? OpenFgcClientConfig - Configuration for Open FGC client
health.fhirr4: ConsentPurpose
Represents a purpose with associated elements. Defines the purpose for which consent is being requested along with the specific data elements.
Fields
- name string - The name of the consent purpose (e.g., "access-all-health-data")
- elements ConsentElement[] - Array of consent elements associated with this purpose
health.fhirr4: ConsentResponse
Represents the complete consent response from the Open FGC API. Contains an array of consent records along with pagination metadata.
Fields
- data? Consent[] - Array of consent records
- metadata? ResponseMetadata - Pagination and result count metadata
health.fhirr4: ConsentValidationResponse
Represents a consent validation response containing detailed consent information. This is returned by the /api/v1/consents/validate endpoint.
Fields
- isValid? boolean - Indicates whether the consent is valid
- errorMessage? string - Error message returned when validation fails
- errorDescription? string - Detailed description of the validation error
- consentInformation? Consent - Detailed information about the validated consent
health.fhirr4: FHIRCapabilitiesInteraction
FHIR Capabilities interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction CAPABILITIES(default r4:CAPABILITIES) - Interaction type
health.fhirr4: FHIRCreateInteraction
FHIR Create interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction CREATE(default r4:CREATE) - Interaction type
health.fhirr4: FHIRDeleteInteraction
FHIR Delete interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction DELETE(default r4:DELETE) - Interaction type
- id string - Target resource id
health.fhirr4: FHIRHistoryInteraction
FHIR History interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction HISTORY(default r4:HISTORY) - Interaction type
health.fhirr4: FHIRInstanceHistoryInteraction
FHIR Instance History interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction HISTORY(default r4:HISTORY) - Interaction type
- id string - target resource id
health.fhirr4: FHIRPatchInteraction
FHIR Patch interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction PATCH(default r4:PATCH) - Interaction type
- id string - Target resource id
health.fhirr4: FHIRReadInteraction
FHIR Read interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction READ(default r4:READ) - Interaction type
- id string - target resource id
health.fhirr4: FHIRSearchInteraction
FHIR Search interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction SEARCH(default r4:SEARCH) - Interaction type
- defaultProfile? string - International resource URL will set as default.
health.fhirr4: FHIRUpdateInteraction
FHIR Update interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction UPDATE(default r4:UPDATE) - Interaction type
- id string - Target resource id
health.fhirr4: FHIRVReadInteraction
FHIR VRead interaction.
Fields
- Fields Included from *FHIRInteraction
- interaction FHIRInteractionType
- anydata...
- interaction HISTORY(default r4:HISTORY) - Interaction type
- id string - target resource id
- vid string - target version id
health.fhirr4: OpenFgcClientConfig
OpenFgcClientConfig Record.
Fields
- url? string - Open FGC server URL
- username? string - Open FGC client basicAuth username
- password? string - Open FGC client basicAuth password
- orgId string(default DEFAULT_ORG_ID) - Organization ID for API requests
health.fhirr4: Request
Represents the request information
Fields
- time string - Request time
- uri string - Full URI of the request
- verb string - HTTP verb
- api_version? string - API version
- ip_address? string - IP address of the requester
- headers json - Request headers
- body? json - Request body
- transfer_encoding? string - Transfer encoding
health.fhirr4: Response
Represents the response information
Fields
- time string - Time of the response
- status int - Status code of the response
- headers json - Response headers
- body? json - Response body
- transfer_encoding? string - Transfer encoding
health.fhirr4: ResponseMetadata
Represents metadata for the consent response. Contains pagination and result count information.
Fields
- total? int - Total number of consents available matching the query
- 'limit? int -
- offset? int - The starting position of the returned results
- count? int - Actual number of consents returned in this response
Object types
health.fhirr4: ConsentEnforcer
Interface for consent enforcement implementations. Defines the contract for checking if a resource type is authorized based on consent data.
enforce
function enforce(string userID) returns ConsentContext|errorEnforces consent by checking if the resource type is authorized
Parameters
- userID string - The user ID for which consent needs to be enforced
Return Type
- ConsentContext|error - ConsentContext containing consented resource types or error if enforcement fails
Import
import ballerinax/health.fhirr4;Metadata
Released date: 2 days ago
Version: 3.0.5
Compatibility
Platform: java21
Ballerina version: 2201.12.2
GraalVM compatible: Yes
Pull count
Total: 5624
Current verison: 29
Weekly downloads
Keywords
Healthcare
FHIR
R4
service
Contributors