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

    This service orchestrates the multi-step Ayushman Bharat Health Account (ABHA) creation workflow. It functions as a state machine, guiding the user through a series of steps from Aadhaar OTP generation to the final ABHA address creation.

    • State Management: Manages the user's progress through the registration flow using the AbhaSteps enum.
    • Data Validation: Ensures that the data provided at each step is valid.
    • Data Encryption: Encrypts sensitive information like Aadhaar numbers and OTPs before sending them to the ABHA APIs, as per security requirements.
    • API Interaction: Communicates with the backend ABHA services for each step of the process.

    The primary entry point is the createAbha method, which dispatches requests to the appropriate handler based on the current step.

    Hierarchy

    • BaseService
      • AbhaService
    Index

    Constructors

    Properties

    Methods

    Constructors

    • Parameters

      • config: ClientConfig

      Returns AbhaService

    Properties

    utilities: Utilities = ...

    Methods

    • Initiates or continues the multi-step ABHA creation flow.

      This function serves as the single entry point for the entire ABHA registration process. It orchestrates the various stages by delegating to internal handlers based on the provided 'step'. The client should sequentially call this function, passing the output from one step as input to the next, guided by the nextStep field in the response.

      1. RegisterWithAadhaar: Sends an OTP to the Aadhaar-linked mobile number.

        • Input: { aadhaar: string }
        • Next Step: VerifyAadhaarOtp
      2. VerifyAadhaarOtp: Verifies the OTP received on the Aadhaar-linked mobile.

        • Input: { otp: string, txnId: string, mobile?: string }
        • Next Step:
          • If Aadhaar has a linked mobile → GetAbhaAddressSuggestions
          • If Aadhaar is not linked to mobile → UpdateMobile
      3. UpdateMobile: Sends OTP to the mobile number entered by the user (used when Aadhaar has no mobile linked).

        • Input: { txnId: string, mobile: string }
        • Next Step: VerifyUpdateMobileOtp
      4. VerifyUpdateMobileOtp: Verifies the OTP sent to the mobile number entered in the previous step.

        • Input: { otp: string, txnId: string }
        • Next Step: GetAbhaAddressSuggestions
      5. GetAbhaAddressSuggestions: Retrieves suggested ABHA addresses for the user to choose from.

        • Input: { txnId: string }
        • Next Step: FinalRegister
      6. FinalRegister: Final step where the user selects an ABHA address and completes the registration.

        • Input: { txnId: string, abhaAddress: string }
        • Next Step: null (workflow complete)

      Parameters

      • step: AbhaSteps

        The current step in the ABHA creation flow.

      • payload: Record<string, any>

        The data payload required for the current step.

      Returns Promise<any>

      A promise that resolves to a structured response object.

      Throws a ValidationError if the payload fails validation, or a generic Error if an operation fails.

      // Step 1: Register With Aadhaar
      // -----------------------------
      // Expected Input:
      const requestAadhaarOtpPayload = { aadhaar: '123456789012' };
      const aadhaarOtpResponse = await patient.abha.createAbha('RegisterWithAadhaar', requestAadhaarOtpPayload);

      // Expected Output:
      {
      "success": true,
      "message": "OTP sent successfully...",
      "response": {
      "txnId": "a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6"
      },
      "nextStep": "VerifyAadhaarOtp",
      "nextStepHint": "Please enter the OTP..."
      }


      // Step 2: Verify Aadhaar OTP
      // --------------------------
      // Expected Input:
      const verifyAadhaarOtpPayload = {
      otp: '123456',
      txnId: 'a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
      mobile: '9876543210'
      };
      const aadhaarVerificationResponse = await patient.abha.createAbha('VerifyAadhaarOtp', verifyAadhaarOtpPayload);

      // Expected Output:
      {
      "success": true,
      "message": "Aadhaar OTP verified successfully.",
      "response": {
      "ABHAProfile": { "mobile": "9876543210", "...": "..." }
      },
      "nextStep": "GetAbhaAddressSuggestions",
      "nextStepHint": "Mobile number is already verified. Proceed to select ABHA address."
      }


      // Step 3: Update Mobile
      // ---------------------
      // Expected Input:
      const UpdateMobileOtpRequestDto = {
      txnId: 'a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
      mobile: '9876543210'
      };
      const updateMobileOtpResponse = await patient.abha.createAbha('UpdateMobile', UpdateMobileOtpRequestDto);

      // Expected Output:
      {
      "success": true,
      "message": "OTP sent to your new mobile number..",
      "response": {
      "ABHAProfile": { "mobile": "9876543210", "...": "..." }
      },
      "nextStep": "GetAbhaAddressSuggestions",
      "nextStepHint": "Please enter the OTP sent to your new mobile number"
      }


      // Step 4: Verify Mobile OTP
      // -------------------------
      // Expected Input:
      const VerifyUpdateMobileOtpBodyDto = {
      otp: '123456',
      txnId: 'a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
      };
      const aadhaarVerificationResponse = await patient.abha.createAbha('VerifyUpdateMobileOtp', VerifyUpdateMobileOtpBodyDto);

      // Expected Output:
      {
      "success": true,
      "message": "Mobile number updated successfully",
      "response": {
      "ABHAProfile": { "mobile": "9876543210", "...": "..." }
      },
      "nextStep": "GetAbhaAddressSuggestions",
      "nextStepHint": "Now, select an address from the suggestions."
      }


      // Step 5: Get ABHA Address Suggestions
      // ------------------------------------
      // Expected Input:
      const addressSuggestionsRequestPayload = { txnId: 'a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6' };
      const addressSuggestionsResponse = await patient.abha.createAbha('GetAbhaAddressSuggestions', addressSuggestionsRequestPayload);

      // Expected Output:
      {
      "success": true,
      "message": "Here are your ABHA address suggestions.",
      "response": {
      "abhaAddressList": ["user.2025", "user.01", "user.123"]
      },
      "nextStep": "FinalRegister",
      "nextStepHint": "Select an address and proceed to final registration."
      }


      // Step 6: Final Register
      // ----------------------
      // Expected Input:
      const createAbhaAddressPayload = {
      abhaAddress: 'user.2025',
      txnId: 'a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6'
      };
      const finalRegistrationResponse = await patient.abha.createAbha('FinalRegister', createAbhaAddressPayload);

      // Expected Output:
      {
      "success": true,
      "message": "ABHA registered successfully.",
      "response": {
      "healthIdNumber": "91-1234-5678-9012",
      "preferredAbhaAddress": "user.2025@sbx"
      },
      "nextStep": null,
      "nextStepHint": null
      }
    • Parameters

      • step: string
      • payload: Record<string, any>

      Returns Promise<Record<string, any>>