import { BaseService } from "../../base"; import { ClientConfig } from "../../base"; import { HprSteps } from "./utilities"; /** * Service class for managing the HPR (Healthcare Professional Registry) registration workflow. * * Provides methods to perform all registration steps, including: * - Aadhaar OTP generation and verification * - Mobile OTP update and verification * - Fetching and submitting profile details * - Handling HPR address suggestions and final HPR ID creation * * Each method integrates with the HPR registration API and includes: * - Input validation * - Encrypted data handling * - Centralized error management * * Built on top of a base HTTP service for consistent request processing. */ export declare class HprService extends BaseService { private readonly logger; constructor(config: ClientConfig); /** * 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: * 1. **RegisterWithAadhaar**: Sends an OTP to the Aadhaar-linked mobile number. * 2. **VerifyAadhaarOtp**: Verifies the Aadhaar OTP to authenticate the professional. * 3. **CheckAccountExists**: Checks if an HPR account already exists. * 4. **VerifyDemographicAuthViaMobile**: Performs demographic authentication via mobile. * - If DemographicAuthViaMobile verified → `GetHprSuggestions` * - If DemographicAuthViaMobile not verified → `GenerateMobileOtp` * 5. **GenerateMobileOtp**: Sends an OTP to the user's mobile for verification. * 6. **VerifyMobileOtp**: Verifies the mobile OTP. * 7. **GetHprSuggestions**: Fetches available HPR ID (username) suggestions. * 8. **CreateHprIdWithPreverified**: Final step to create the HPR ID with all verified details. * * @param {HprSteps | string} step - The current step in the HPR creation flow. * @param {Record} payload - The data payload required for the current step, conforming to the step's specific DTO schema. * @returns {Promise} A promise that resolves to a structured response object. * @throws {ValidationError | Error} Throws a `ValidationError` if the payload fails validation, or a generic `Error` if an operation fails. * * @example * * // 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 * } */ createHpr(step: HprSteps, payload: Record): Promise>; createHprFlow(step: HprSteps | string, payload: Record): Promise>; /** * Initiates the Aadhaar-based registration process by generating an OTP. * * Steps performed: * 1. Validates the input Aadhaar number. * 2. Sends a request to the Aadhaar OTP generation endpoint. * 3. Returns a structured HprFlowResponse indicating the result. * * @param {GenerateAadhaarOtpRequestSchema} requestData - The input data containing: * - aadhaar: 12-digit Aadhaar number (required) * * @returns {Promise} - Structured response with: * - success: boolean indicating whether OTP generation was successful * - message: user-facing message * - response: server response including txnId and mobile number * - nextStep: HprSteps indicating the next step in the flow * - nextStepHint: Optional hint text to guide next action * * @throws {ValidationError} - If the Aadhaar number is missing or invalid */ private _handleRegisterWithAadhaar; /** * Verifies the Aadhaar OTP provided by the user. * * Steps performed: * 1. Validates the input request data. * 2. Sends request to Aadhaar OTP verification endpoint. * 3. Returns a structured HprFlowResponse indicating result and next step. * * @param {VerifyAadhaarOtpRequestSchema} requestData - The input data including: * - domainName - Domain to be associated with the ID (mandatory) * - idType - Type of ID being used, e.g., Aadhaar (mandatory) * - otp - One-time password sent to the user’s registered mobile (mandatory) * - restrictions - Additional restrictions or scopes (optional) * - txnId - Transaction ID received during OTP generation (mandatory) * * @returns {Promise} - Structured response with: * - success - boolean indicating OTP verification status * - message - user-facing message * - response - Aadhaar details such as txnId, mobileNumber, gender, email, etc. * - nextStep - The next step in the HPR registration flow * - nextStepHint - Hint for the user or system about the next action * * @throws {ValidationError} - If OTP is missing or request data fails validation */ private _handleVerifyAadhaarOtp; /** * Checks if an HPR account already exists for the user. * * Steps performed: * 1. Validates the request data. * 2. Sends a request to check account existence using the provided txnId. * 3. Returns a structured HprFlowResponse indicating whether to continue or stop the registration flow. * * @param {CheckAccountExistRequestSchema} requestData - The input data including: * - txnId - Transaction ID received from Aadhaar verification (mandatory) * - preverifiedCheck - Flag indicating whether Aadhaar was pre-verified (mandatory) * * @returns {Promise} - Structured response with: * - success - boolean indicating whether the account exists or not * - message - summary message of the check result * - response - API response with user/account details * - nextStep - The next step in the registration flow, if any * - nextStepHint - Hint about what is expected next * * @throws {ValidationError} - If input validation fails */ private _handleCheckAccountExists; /** * Verifies demographic authentication via mobile number. * * Steps performed: * 1. Validates the input data. * 2. Sends a request to the demographic auth endpoint with txnId and mobileNumber. * 3. Interprets the response to determine whether demographic auth was successful. * 4. Returns the appropriate next step in the registration flow. * * @param {DemographicAuthViaMobileRequestSchema} requestData - The input data including: * - txnId - Transaction ID from the Aadhaar verification step (mandatory) * - mobileNumber - Mobile number to perform demographic match (mandatory) * * @returns {Promise} - Structured response with: * - success - boolean indicating the result of the demographic auth * - message - summary of the outcome * - response - API response with details of the verification result * - nextStep - Next step in the registration flow (e.g., GenerateMobileOtp or GetHprSuggestions) * - nextStepHint - Instructions for the next step * * @throws {ValidationError} - If input validation fails */ private _handleDemographicAuthViaMobile; /** * Generates a mobile OTP for verification. * * Steps performed: * 1. Validates the input data. * 2. Sends a request to the generate OTP endpoint with txnId and mobile number. * 3. Handles success or failure response and determines the next step. * * @param {GenerateMobileOtpRequestSchema} requestData - The input data including: * - txnId - Transaction ID used to track the session (mandatory) * - mobile - Mobile number to which OTP will be sent (mandatory) * * @returns {Promise} - Structured response with: * - success - boolean indicating if OTP generation was successful * - message - summary of the outcome * - response - API response with txnId or error details * - nextStep - Next step in the registration flow (VerifyMobileOtp) * - nextStepHint - Instructions for the next step * * @throws {ValidationError} - If input validation fails or mobile number is missing */ private _handleGenerateMobileOtp; /** * Verifies the OTP sent to the user's mobile. * * Steps performed: * 1. Validates the input data. * 2. Sends a request to verify the mobile OTP using txnId and OTP. * 3. Handles success or failure and determines the next step. * * @param {VerifyMobileOtpRequestSchema} requestData - The input data including: * - txnId - Transaction ID used to track the session (mandatory) * - otp - One-Time Password received on the mobile (mandatory) * * @returns {Promise} - Structured response with: * - success - boolean indicating verification result * - message - summary of the outcome * - response - API response or error details * - nextStep - Next step in the registration flow (GetHprSuggestions) * - nextStepHint - Instructions for the next step * * @throws {ValidationError} - If OTP is missing or input validation fails */ private _handleVerifyMobileOtp; /** * Fetches available HPR ID suggestions for the user. * * Steps performed: * 1. Validates the input transaction ID. * 2. Sends a request to retrieve HPR ID suggestions based on the txnId. * 3. Handles the response and determines the next step in the registration flow. * * @param {HpIdSuggestionRequestSchema} requestData - The input data including: * - txnId - Transaction ID for the ongoing session (mandatory) * * @returns {Promise} - Structured response with: * - success - boolean indicating result of the operation * - message - summary of the outcome * - response - list of HPR ID suggestions * - nextStep - Next step in the flow (CreateHprIdWithPreverified) * - nextStepHint - Instructions for the next step * * @throws {ValidationError} - If txnId is missing or validation fails */ private _handleGetHprSuggestions; /** * Creates a new HPR ID using the provided preverified user data. * * Steps performed: * 1. Validates the complete identity and demographic information. * 2. Sends the data to the HPR creation endpoint. * 3. Returns the generated HPR ID and associated user details on success. * * @param {CreateHprIdWithPreVerifiedRequestBody} requestData - The request payload including: * - address, dayOfBirth, districtCode, email, firstName, hpCategoryCode, hpSubCategoryCode, hprId, * lastName, monthOfBirth, password, pincode, stateCode, txnId, yearOfBirth * - Optional: middleName, profilePhoto * * @returns {Promise} - Structured response including: * - success - boolean indicating result of the operation * - message - summary of the outcome * - response - created HPR ID and user profile data * - nextStep - null (end of flow) * - nextStepHint - null (no further instructions) * * @throws {ValidationError} - If input data is missing or invalid */ private _handleCreateHprIdWithPreverified; private _processStep; }