CareStack EHR Node.js SDK Documentation
    Preparing search index...

    Executes a multistep, transactional process for linking a patient's health documents.

    This service manages a complex workflow that includes:

    • Creating a care context.
    • Updating visit records with health information.
    • Linking the care context to the patient's profile.

    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.

    If any stage of the process encounters an issue, the transaction is halted and rolled back.

    Hierarchy

    • BaseService
      • DocumentLinkingService
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Performs the complete health document linking process, including the following steps:

      1. Validates the input data.
      2. Creates a care context using appointment reference.
      3. Optionally updates visit records if health records are provided.
      4. Links the created care context with the patient's ABHA account.

      Parameters

      • healthDocumentLinkingDTO: HealthDocumentLinkingDTO

        Object containing the necessary data for linking the health document:

        • patientReference - Unique reference ID of the patient - mandatory
        • practitionerReference - Unique reference ID of the practitioner - mandatory
        • patientAddress - Address of the patient - mandatory
        • patientName - Full name of the patient - mandatory
        • appointmentStartDate - Start date/time of the appointment in ISO format - mandatory
        • appointmentEndDate - End date/time of the appointment in ISO format - mandatory
        • appointmentPriority - Priority of the appointment (e.g., EMERGENCY, ROUTINE) - optional
        • organizationId - Unique ID of the organization creating the care context - mandatory
        • appointmentSlot - Appointment slot identifier - optional
        • appointmentReference - Unique ID/reference of the appointment - mandatory
        • patientAbhaAddress - Patient’s ABHA address - mandatory
        • hiType - Type of health information being linked (e.g., OPConsultation, Prescription) - mandatory
        • mobileNumber - Patient’s mobile number - mandatory
        • healthRecords - Array of health information records to be linked - optional

      Returns Promise<boolean>

      A boolean indicating whether the health document linking was successful.

      If any step in the process fails, the error is logged and re-thrown.

      // 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