Kulcare Docs
General

Integration Schema

Purpose: External service integrations, health data exchange, and API management Tenant Scoped: Yes (all tables) RLS Enabled: Yes

Overview

The integration schema manages connections to external systems including:

  • ABDM (Ayushman Bharat Digital Mission) for India
  • Health data exchange protocols
  • Webhook management
  • API logging and rate limiting

Entities

ABDM Integration (India)

Entity: AbdmRecord

Purpose: ABDM health records linked to patients

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
patient_idUUIDYesPatient reference
abha_idStringYesABHA identifier
record_typeEnumYesprescription, diagnostic_report, discharge_summary, op_consult
hip_idStringYesHealth Information Provider ID
care_context_idStringYesABDM care context reference
transaction_idStringNoABDM transaction ID
request_idStringNoABDM request ID
statusEnumYespending, fetched, linked, error
fhir_bundleJSONBNoFHIR bundle data
raw_responseJSONBNoRaw ABDM response
linked_encounter_idUUIDNoLinked encounter
fetched_atTimestampNoWhen fetched
expires_atTimestampNoRecord expiry
error_messageTextNoError details
created_atTimestampYesCreation time

Record Types:

  • prescription - Prescription records
  • diagnostic_report - Lab/imaging reports
  • discharge_summary - Hospital discharge summary
  • op_consult - Outpatient consultation record
  • immunization - Immunization records
  • health_document - Other health documents

Relationships:

  • Belongs to: Tenant, Patient, Encounter

Entity: AbdmConsent

Purpose: ABDM consent artifacts

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
patient_idUUIDYesPatient reference
abha_idStringYesABHA identifier
consent_idStringYesABDM consent ID
consent_statusEnumYesrequested, granted, denied, revoked, expired
purposeEnumYescare_management, break_the_glass, public_health, healthcare_payment
hi_typesString[]YesHealth information types
requester_hip_idStringYesRequesting HIP
date_range_fromDateNoData from date
date_range_toDateNoData to date
consent_expiryTimestampNoConsent expiry
granted_atTimestampNoWhen granted
revoked_atTimestampNoWhen revoked
created_atTimestampYesRequest time

HI Types:

["Prescription", "DiagnosticReport", "DischargeSummary", "OPConsultation", "Immunization", "HealthDocument"]

Purpose Values:

  • care_management - Regular care delivery
  • break_the_glass - Emergency access
  • public_health - Public health purposes
  • healthcare_payment - Insurance/payment

Relationships:

  • Belongs to: Tenant, Patient
  • Has many: AbdmRecords

Entity: AbdmCallback

Purpose: ABDM callback events log

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
callback_typeStringYesCallback endpoint type
request_idStringNoABDM request ID
transaction_idStringNoABDM transaction ID
payloadJSONBYesCallback payload
statusEnumYesreceived, processing, processed, failed
error_messageTextNoProcessing error
received_atTimestampYesReceipt time
processed_atTimestampNoProcessing time

Callback Types:

  • consent-request/on-init
  • consent-request/on-status
  • health-information/on-request
  • health-information/hip/on-request
  • links/link/on-init
  • links/link/on-confirm

Relationships:

  • Belongs to: Tenant

Health Information Exchange

Entity: ExternalRecord

Purpose: Health records from external systems (non-ABDM)

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
patient_idUUIDYesPatient reference
source_systemStringYesSource system name
source_idStringNoExternal record ID
record_typeEnumYeslab_result, imaging, prescription, document
fhir_resource_typeStringNoFHIR resource type
contentJSONBYesRecord content
raw_dataJSONBNoOriginal format data
received_atTimestampYesWhen received
processedBooleanNoProcessing complete
linked_resource_idUUIDNoCreated clinical resource
linked_resource_typeStringNoType of linked resource

Relationships:

  • Belongs to: Tenant, Patient

Webhook Management

Entity: WebhookEndpoint

Purpose: Registered webhook endpoints for external systems

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
nameStringYesEndpoint name
urlStringYesWebhook URL
secretStringNoSigning secret (encrypted)
eventsString[]YesSubscribed events
statusEnumYesactive, paused, disabled
versionStringNoAPI version
headersJSONBNoCustom headers
retry_policyJSONBNoRetry configuration
created_by_idUUIDYesCreator user
last_triggered_atTimestampNoLast trigger time
failure_countIntegerNoConsecutive failures
created_atTimestampYesCreation time

Events:

["patient.created", "appointment.scheduled", "appointment.cancelled",
 "encounter.completed", "prescription.created", "invoice.paid"]

Retry Policy Structure:

{
  "max_retries": 3,
  "retry_delay_seconds": 60,
  "exponential_backoff": true
}

Relationships:

  • Belongs to: Tenant, User
  • Has many: WebhookEvents

Entity: WebhookEvent

Purpose: Webhook delivery attempts

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
endpoint_idUUIDYesTarget endpoint
event_typeStringYesEvent type
payloadJSONBYesEvent payload
statusEnumYespending, delivered, failed, cancelled
attemptsIntegerNoDelivery attempts
last_attempt_atTimestampNoLast attempt time
next_retry_atTimestampNoNext retry time
response_statusIntegerNoHTTP response status
response_bodyTextNoResponse body (truncated)
error_messageTextNoError details
created_atTimestampYesEvent creation
delivered_atTimestampNoSuccessful delivery

Relationships:

  • Belongs to: Tenant, WebhookEndpoint

API Management

Entity: ApiKey

Purpose: API keys for external access

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
nameStringYesKey name
key_hashStringYesHashed API key
key_prefixStringYesKey prefix for identification
scopesString[]YesPermitted scopes
rate_limitIntegerNoRequests per minute
statusEnumYesactive, revoked
expires_atTimestampNoExpiration time
last_used_atTimestampNoLast usage
created_by_idUUIDYesCreator user
revoked_atTimestampNoRevocation time
revoked_by_idUUIDNoRevoking user
created_atTimestampYesCreation time

Scopes:

["patients:read", "patients:write", "appointments:read", "appointments:write",
 "encounters:read", "reports:read", "billing:read"]

Relationships:

  • Belongs to: Tenant, User

Entity: ApiLog

Purpose: API request/response logging

Attributes:

AttributeTypeRequiredDescription
idUUIDYesPrimary identifier
tenant_idUUIDYesOwning tenant
api_key_idUUIDNoAPI key used
user_idUUIDNoUser if authenticated
methodStringYesHTTP method
pathStringYesRequest path
query_paramsJSONBNoQuery parameters
request_headersJSONBNoRequest headers (filtered)
request_bodyJSONBNoRequest body (filtered)
response_statusIntegerYesResponse status code
response_time_msIntegerNoResponse time
ip_addressStringNoClient IP
user_agentStringNoUser agent
error_messageTextNoError if any
created_atTimestampYesRequest time

Note: Sensitive data (tokens, passwords, PII) is filtered from logs.

Relationships:

  • Belongs to: Tenant, ApiKey, User

Schema Diagram

+---------------+       +---------------+       +---------------+
| abdm_records  |       | abdm_consents |       | abdm_callbacks|
+---------------+       +---------------+       +---------------+
       |                       |
       v                       v
+------------------------------------------+
|              clinical.patients           |
+------------------------------------------+

+---------------+       +---------------+
| external_     |       | webhook_      |
| records       |       | endpoints     |
+---------------+       +---------------+
                               |
                               v
                        +---------------+
                        | webhook_events|
                        +---------------+

+---------------+       +---------------+
|   api_keys    |------>|   api_logs    |
+---------------+       +---------------+

ABDM Integration Flow

1. Patient Links ABHA
   Patient --> AbdmConsent (requested) --> ABDM Gateway

2. Consent Granted
   ABDM Gateway --> AbdmCallback --> AbdmConsent (granted)

3. Health Data Fetch
   AbdmConsent --> AbdmRecord (pending) --> ABDM Gateway

4. Data Received
   ABDM Gateway --> AbdmCallback --> AbdmRecord (fetched)
   AbdmRecord --> clinical.* resources (linked)

RLS Policies

-- All integration tables: tenant isolation
CREATE POLICY tenant_isolation ON integration.abdm_records
    USING (tenant_id = current_setting('app.current_tenant_id')::uuid);

CREATE POLICY tenant_isolation ON integration.webhook_endpoints
    USING (tenant_id = current_setting('app.current_tenant_id')::uuid);

CREATE POLICY tenant_isolation ON integration.api_keys
    USING (tenant_id = current_setting('app.current_tenant_id')::uuid);

Security Considerations

  1. API Keys: Stored as hashed values, never in plaintext
  2. Webhook Secrets: Encrypted at rest
  3. ABDM Data: Follows ABDM data protection guidelines
  4. API Logs: PII and sensitive data filtered before storage
  5. Consent Management: Strict consent lifecycle enforcement

On this page