Initiates or continues the HPR (Healthcare Professional Registry) creation flow.
This function serves as the single entry point for the entire HPR 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.
The flow is as follows:
GetHprSuggestions
GenerateMobileOtp
The current step in the HPR creation flow.
The data payload required for the current step, conforming to the step's specific DTO schema.
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
const requestAadhaarOtpPayload = { aadhaar: '123456789012' };
const aadhaarOtpResponse = await practitioner.hpr.createHpr(HprSteps.RegisterWithAadhaar, requestAadhaarOtpPayload);
// Expected Output:
{
"success": true,
"message": "OTP sent successfully...",
"response": {
"txnId": "a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6",
"mobileNumber": "******3210"
},
"nextStep": "VerifyAadhaarOtp",
"nextStepHint": "Enter txnId and OTP to verify mobile number."
}
// Step 2: Verify Aadhaar OTP
const verifyAadhaarOtpPayload = {
otp: '123456',
txnId: 'a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6'
* };
* const aadhaarVerificationResponse = await practitioner.hpr.createHpr(HprSteps.VerifyAadhaarOtp, verifyAadhaarOtpPayload);
*
* // Expected Output:
* {
* "success": true,
* "message": "Aadhaar OTP verified successfully.",
* "response": {
* "txnId": "a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6",
* "name": "Dr. Priya Sharma",
* "gender": "F",
* "birthdate": "15-08-1990",
* "state": "Telangana",
* "district": "Hyderabad"
* },
* "nextStep": "CheckAccountExists",
* "nextStepHint": "Please provide txnId to check account existence."
* }
*
* // Step 3: Check If Account Exists
* const checkAccountExistsPayload = {
* txnId: 'a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6'
* };
* const accountCheckResponse = await practitioner.hpr.createHpr(HprSteps.CheckAccountExists, checkAccountExistsPayload);
*
* // Expected Output:
* {
* "success": true,
* "message": "No HPR account found. Proceed to the next step.",
* "response": {
* "txnId": "a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6",
* "firstName": "Priya",
* "lastName": "Sharma",
* "yearOfBirth": "1990",
* "monthOfBirth": "8",
* "dayOfBirth": "15",
* "new": true
* },
* "nextStep": "VerifyDemographicAuthViaMobile",
* "nextStepHint": "Provide txnId and mobileNumber for demographic auth via mobile."
* }
*
* // Step 4: Demographic Authentication via Mobile
* const demographicAuthPayload = {
* txnId: 'a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6',
* mobileNumber: '9876543210'
* };
* const demographicAuthResponse = await practitioner.hpr.createHpr(HprSteps.VerifyDemographicAuthViaMobile, demographicAuthPayload);
*
* // Expected Output:
* {
* "success": true,
* "message": "Demographic auth successful. Proceed to generate mobile OTP.",
* "response": { "verified": true },
* "nextStep": "GenerateMobileOtp",
* "nextStepHint": "Provide txnId and mobile to generate OTP."
* }
*
* // Step 5: Generate Mobile OTP
* const generateMobileOtpPayload = {
* txnId: 'a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6',
* mobile: '9876543210'
* };
* const mobileOtpResponse = await practitioner.hpr.createHpr(HprSteps.GenerateMobileOtp, generateMobileOtpPayload);
*
* // Expected Output:
* {
* "success": true,
* "message": "Mobile OTP sent successfully.",
* "response": { "txnId": "a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6" },
* "nextStep": "VerifyMobileOtp",
* "nextStepHint": "Enter txnId and OTP to verify mobile"
* }
*
* // Step 6: Verify Mobile OTP
* const verifyMobileOtpPayload = {
* txnId: 'a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6',
* otp: '654321'
* };
* const mobileVerificationResponse = await practitioner.hpr.createHpr(HprSteps.VerifyMobileOtp, verifyMobileOtpPayload);
*
* // Expected Output:
* {
* "success": true,
* "message": "Mobile OTP verified successfully.",
* "response": {
* "txnId": "a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6",
* "verified": true
* },
* "nextStep": "GetHprSuggestions",
* "nextStepHint": "Provide txnId for HPR ID suggestions"
* }
*
* // Step 7: Get HPR ID Suggestions
* const suggestionsPayload = { txnId: 'a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6' };
* const suggestionsResponse = await practitioner.hpr.createHpr(HprSteps.GetHprSuggestions, suggestionsPayload);
*
* // Expected Output:
* {
* "success": true,
* "message": "Here are your HPR ID suggestions.",
* "response": ["priya.sharma", "drpriya.sharma", "priya.sharma.1990"],
* "nextStep": "CreateHprIdWithPreverified",
* "nextStepHint": "Provide txnId and final details to create HPR ID"
* }
*
* // Step 8: Create HPR ID with Pre-verified Data
* const createHprIdPayload = {
* txnId: 'a1b2c3d4-e5f6-4a5b-8c9d-e1f2a3b4c5d6',
* hprId: 'priya.sharma',
* password: 'Password@123',
* firstName: 'Priya',
* lastName: 'Sharma',
* yearOfBirth: '1990',
* monthOfBirth: '8',
* dayOfBirth: '15',
* stateCode: '36',
* districtCode: '533',
* address: '123 Jubilee Hills, Hyderabad',
* pincode: '500033',
* email: 'priya.sharma@example.com',
* hpCategoryCode: 'DENT',
* hpSubCategoryCode: 'DENT_GEN'
* };
* const finalResponse = await practitioner.hpr.createHpr(HprSteps.CreateHprIdWithPreverified, createHprIdPayload);
*
* // Expected Output:
* {
* "success": true,
* "message": "HPR ID created successfully.",
* "response": {
* "hprId": "priya.sharma",
* "hprIdNumber": "12-3456-7890-1234",
* "name": "Dr. Priya Sharma",
* "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
* },
* "nextStep": null,
* "nextStepHint": null
* }
Service class for managing the HPR (Healthcare Professional Registry) registration workflow.
Provides methods to perform all registration steps, including:
Each method integrates with the HPR registration API and includes:
Built on top of a base HTTP service for consistent request processing.