Performs the complete health document linking process, including the following steps:
Object containing the necessary data for linking the health document:
A boolean indicating whether the health document linking was successful.
// Input:
const linkingData = {
patientReference: "a8654878-4202-4b47-bcc4-868060a75254",
practitionerReference: "3c7271bb-4212-4291-9f75-64d886d69893",
patientAddress: "123 Main St, Springfield, IL",
patientName: "John Doe",
appointmentStartDate: "2025-02-28T09:00:00Z",
appointmentEndDate: "2025-02-28T10:00:00Z",
organizationId: "org123",
appointmentReference: "3c832da8-9cfd-446b-be1c-4a8d01f39374",
patientAbhaAddress: "sbx@sbx",
hiType: "OPConsultation",
mobileNumber: "+911234567890",
healthRecords: [
{
rawFhir: false,
fhirDocument: null,
informationType: "OPConsultation",
dto: {
chiefComplaints: "Severe headache and nausea for the past 1 day",
physicalExamination: {
bloodPressure: { value: "140/90", unit: "mmHg" },
heartRate: { value: "88", unit: "bpm" },
respiratoryRate: { value: "18", unit: "breaths/min" },
temperature: { value: "98.7", unit: "°F" },
oxygenSaturation: { value: "97", unit: "%" },
height: { value: "160", unit: "cm" },
weight: { value: "60", unit: "kg" }
},
conditions: ["Migraine (suspected)"],
medicalHistory: [{ condition: "Hypothyroidism diagnosed 3 years ago", procedure: "None" }],
familyHistory: [{ relation: "Sister", healthNote: "Diagnosed with migraine at age 22", condition: "Migraine" }],
allergies: ["No known drug allergies"],
immunizations: ["Tetanus booster taken 2 years ago, Lot number: TET987, Expiry: 2026-06-30"],
currentMedications: ["Levothyroxine 50 mcg - active - reason: Hypothyroidism"],
investigationAdvice: ["MRI Brain - active - order", "Blood Sugar (Fasting) - active - order"],
prescribedMedications: [
"Sumatriptan 50 mg – once at onset – oral – for migraine",
"Ondansetron 4 mg – as needed – oral – for nausea"
],
currentProcedures: [{ description: "Appendectomy surgery", complications: "No postoperative complications" }],
advisoryNotes: ["Avoid bright lights and loud noises", "Take rest in a dark, quiet room during episodes"],
followUp: ["Review after MRI report – OP-87954 – In-person"],
opConsultDocument: ["base64-pdf-data-placeholder"]
}
}
]
};
const result = await encounter.documentLinking.linkHealthDocument(linkingData);
console.log(result);
// Expected Output:
true
Executes a multistep, transactional process for linking a patient's health documents.
This service manages a complex workflow that includes:
The entire operation is designed to be atomic — if any step fails, the whole transaction is aborted, and a descriptive error is returned.
The current state of the process is tracked using the TransactionState object, allowing for clear diagnostics and debugging in case of failure.
Throws
If any stage of the process encounters an issue, the transaction is halted and rolled back.