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.
RegisterWithAadhaar: Sends an OTP to the Aadhaar-linked mobile number.
{ aadhaar: string }
VerifyAadhaarOtp
VerifyAadhaarOtp: Verifies the OTP received on the Aadhaar-linked mobile.
{ otp: string, txnId: string, mobile?: string }
GetAbhaAddressSuggestions
UpdateMobile
UpdateMobile: Sends OTP to the mobile number entered by the user (used when Aadhaar has no mobile linked).
{ txnId: string, mobile: string }
VerifyUpdateMobileOtp
VerifyUpdateMobileOtp: Verifies the OTP sent to the mobile number entered in the previous step.
{ otp: string, txnId: string }
GetAbhaAddressSuggestions
GetAbhaAddressSuggestions: Retrieves suggested ABHA addresses for the user to choose from.
{ txnId: string }
FinalRegister
FinalRegister: Final step where the user selects an ABHA address and completes the registration.
{ txnId: string, abhaAddress: string }
null
(workflow complete)The current step in the ABHA creation flow.
The data payload required for the current step.
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
}
ABHA Creation Workflow Service
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.
Core Responsibilities:
AbhaSteps
enum.The primary entry point is the createAbha method, which dispatches requests to the appropriate handler based on the current step.