import { BaseService } from "../base"; import { ClientConfig } from "../base"; import { CreateUpdatePatientResponse, GetPatientResponse, PatientFiltersDTO, PatientDTO, UpdatePatientDTO } from "./patient.dto"; import { AbhaService } from "./abha"; /** * Service class for handling patient-related operations such as retrieving, * creating, updating, and deleting patients. * * The service provides methods for: * - Retrieving all patients * - Fetching a patient by ID * - Checking patient existence * - Creating a new patient * - Updating an existing patient * - Searching for patients using filters * - Deleting a patient */ export declare class PatientService extends BaseService { private readonly logger; private abhaService; constructor(config: ClientConfig); /** * Retrieves a paginated list of all patients. * * @param {number} [pageSize] - Number of patients to fetch in a single page - optional * (Only effective in the first request. Default is 10 if not provided) * * @param {string} [nextPage] - Cursor to fetch the next set of patients - optional * (Use the value from the previous response's `nextPage` for pagination) * * @returns {Promise} - Returns an object containing: * - type: Type of the response (e.g., "success", "error") * - message: Descriptive message or status of the operation * - requestResource: Actual patient data or list of patients * - totalNumberOfRecords: Total number of patients in the system * - nextPageLink: Token to retrieve the next page of results, if more records exist * * @throws {Error} Throws an error if the request fails or response is invalid. * * @example * // Input: * const patients = await patient.findAll(20); * const morePatients = await patient.findAll(undefined, patients.nextPage); * * // Expected Output: * { * data: { * Entry: [ * { * firstName: 'arya', * lastName: 'bunny', * // ... other fields * }, * { * firstName: 'Neha', * lastName: 'Verma', * // ... other fields * } * // ... more entries * ], * link: { * nextPage: 'X2NvdW50PTEwJl9zb3J0PS1fb' * }, * total: 900 * } * } */ findAll(pageSize?: number, nextPage?: string): Promise; /** * Fetches the details of a patient using Resource ID. * * @param {string} id - Unique identifier (Resource ID) of the patient to fetch - mandatory * * @returns {Promise} - Returns an object containing: * - type: Type of the response (e.g., "Patient") * - message: Descriptive message or status of the operation * - requestResource: Patient data of the requested resource ID * - totalNumberOfRecords: Total number of matched patients * * @throws {ValidationError} If the `id` is null, undefined, or empty. * @throws {Error} If the API request fails. * * @example * // Input: * const patient = await patient.findById("123e4567-e89b-12d3-a456-426614174000"); * console.log(patient); * * * // Expected Output: * { * type: 'Patient', * message: 'Patient Found !!!', * requestResource: { * firstName: 'Sreenivasa', * birthDate: '2025-07-23', * gender: 'male', * mobileNumber: '*********0000', * emailId: '', * address: 'DUMMY_ADDRESS', * pincode: '123456', * resourceType: 'Patient', * resourceId: '123e4567-e89b-12d3-a456-426614174000', * organizationId: 'ACHALA_HEALTH_01', * state: 'Telangana', * idNumber: 'BGSG-0000123456', * idType: 'UHID', * photo: '', * wantsToLinkWhatsapp: true, * abhaAddress: '', * patientType: 'NEW', * lastUpdated: '2025-07-23T09:51:13.201881128Z' * }, * totalNumberOfRecords: 1 * } */ findById(id: string): Promise; /** * Checks whether a patient exists in the system using their Resource ID. * * @param {string} id - Unique identifier (Resource ID) of the patient to check - mandatory * * @returns {Promise} A promise that resolves to: * - `true` if the patient exists * * @throws {ValidationError} If the `id` is null, undefined, or an empty string. * @throws {Error} If the API request fails or an unexpected error occurs. * * @example * // Input: * const doesExist = await patient.exists("123e4567-e89b-12d3-a456-426614174000"); * console.log(doesExist); * * * // Expected Output: * true */ exists(id: string): Promise; /** * Creates a new patient record in the system. * * @param {PatientDTO} patient - Object containing patient details: * * Fields: * - idNumber - Unique patient identification number - mandatory * - idType - Type of identification (e.g., Aadhaar, Passport) - mandatory * - abhaAddress - ABHA address linked to the patient - mandatory * - patientType - Category/type of patient - mandatory * - firstName - Patient's first name (3–20 characters, only alphabets/spaces/dots allowed) - mandatory * - middleName - Patient's middle name (optional, alphabets/spaces/dots allowed) - optional * - lastName - Patient's last name (3–20 characters, only alphabets/spaces/dots allowed) - mandatory * - birthDate - Date of birth in ISO format (YYYY-MM-DD) - mandatory * - gender - Gender of the patient (Male/Female/Other) - mandatory * - mobileNumber - Valid mobile number (should not contain masked characters like *) - mandatory * - emailId - Patient’s valid email address - mandatory * - address - Residential address (5–50 characters) - mandatory * - pincode - 6-digit postal code - mandatory * - state - State or union territory (from predefined enum list) - mandatory * - wantsToLinkWhatsapp - Whether the patient wants to link WhatsApp number - optional * - photo - Base64 or URL string of the patient’s photo - optional * - resourceType - Type of FHIR resource (usually "Patient") - mandatory * - resourceId - Existing resource ID if updating - optional * * @returns {Promise} - Returns an object containing: * - type : Type of the response (e.g., "Patient") * - message : Descriptive message or status of the operation * - resourceId : Unique identifier of the updated patient resource * - validationErrors : Array of validation errors (if any) * - resource : Full updated patient object * @throws {ValidationError} If the input data is invalid. * @throws {Error} If the API request fails. * * @example * // Input: * const data = await patient.create({ * idNumber: "123456789012", * idType: PatientIdTypeEnum.AADHAAR, * abhaAddress: "abha55578@example.com", * patientType: PatientTypeEnum.REGULAR, * firstName: "John", * lastName: "Doe", * birthDate: "1990-01-01", * gender: 'male', * mobileNumber: "+911234563291", * emailId: "john@example.com", * address: "123 Main St, Anytown, Anystate", * pincode: "560001", * state: StatesAndUnionTerritories.KARNATAKA, * resourceType: "Patient" * }); * console.log(data); * * * // Expected Output: * { * message: 'Successfully created the Patient profile', * type: 'Patient', * resourceId: '791708f6-de6d-439e-bece-041e5d64e463', * validationErrors: [], * fhirProfileId: '', * resource: { * firstName: 'John', * lastName: 'Doe', * birthDate: '1990-01-01', * gender: 'male', * mobileNumber: '*********3291', * emailId: 'john@example.com', * address: '123 Main St, Anytown, Anystate, 12345', * pincode: '560001', * resourceType: 'Patient', * resourceId: '791708f6-de6d-439e-bece-041e5d64e463', * organizationId: 'ACHALA_HEALTH_01', * state: 'Andhra Pradesh', * idNumber: '1234567000', * idType: 'ABHA', * photo: '', * wantsToLinkWhatsapp: true, * abhaAddress: 'abha55578@example.com', * patientType: 'OLD', * lastUpdated: '2025-07-31T11:12:08.014760704Z' * } * } */ create(patient: PatientDTO): Promise; /** * Updates existing patient data in the system. * * @param {UpdatePatientDTO} updatePatientData - Object containing fields to update: * * Fields: * - resourceId - Unique resource ID of the patient (used for identification) - mandatory * - resourceType - Type of FHIR resource (usually "Patient") - mandatory * - emailId - Updated email address (must be a valid email) - optional * - mobileNumber - Updated mobile number (must be valid, should not include masked characters like "*") - optional * * @returns {Promise} - Returns an object containing: * - type : Type of the response (e.g., "Patient") * - message : Descriptive message or status of the operation * - resourceId : Unique identifier of the updated patient resource * - validationErrors : Array of validation errors (if any) * - resource : Full updated patient object * * @throws {ValidationError} If the input data is invalid. * @throws {Error} If the API request fails. * * @example * // Input: * await patient.update({ * "resourceType": "Patient", * "resourceId": "791708f6-de6d-439e-bece-041e5d64e463", * "emailId": "VijayaLatha123@gmail.com", * "mobileNumber": "+919182853291" * }); * * * // Expected Output: * { * message: 'Details Updated successfully', * type: 'Patient', * resource: { * firstName: 'Vijaya', * middleName: 'A', * lastName: 'Doe', * birthDate: '1980-01-01', * gender: 'male', * mobileNumber: '*********3291', * emailId: 'VijayaLatha123@gmail.com', * address: '123 Main St, Anytown, Anystate, 12345', * pincode: '12345', * resourceType: 'Patient', * resourceId: '791708f6-de6d-439e-bece-041e5d64e463', * organizationId: 'ACHALA_HEALTH_01', * state: 'Andhra Pradesh', * idNumber: '1234567000', * idType: 'ABHA', * photo: '', * wantsToLinkWhatsapp: true, * abhaAddress: 'abha55578@example.com', * patientType: 'OLD', * lastUpdated: '2025-07-31T11:16:36.550237457Z' * } * } */ update(updatePatientData: UpdatePatientDTO): Promise; /** * Retrieves a list of patients using a combination of optional filter criteria. * * @param {PatientFiltersDTO} filters - Filters to apply for fetching patients. * * Fields: * - firstName - Patient's first name (3–20 characters, alphabets/spaces/dots only) - optional * - lastName - Patient's last name (3–20 characters, alphabets/spaces/dots only) - optional * - email - Patient’s email address (must be a valid format) - optional * - birthDate - Patient's date of birth in ISO format (YYYY-MM-DD) - optional * - gender - Gender of the patient (Male/Female/Other) - optional * - phone - Patient’s phone number (must be valid and unmasked) - optional * - state - Patient’s state or union territory - optional * - pincode - 6-digit postal code - optional * - organizationId - ID of the organization associated with the patient - optional * - pageSize - Number of records to fetch per page (defaults to 10 if not specified) - optional * - identifier - Unique patient identifier (e.g., ABHA ID, ABHA Address) - optional * - fromDate - Start date (inclusive) for filtering based on last updated records - optional * - toDate - End date (inclusive) for filtering based on last updated records - optional * * Note: * - All filter fields are **optional**, but at least one should ideally be provided to avoid fetching unfiltered results. * - `fromDate` and `toDate` should be valid ISO date strings and are used together to define a last-updated range. * - `nextPage` token is used for pagination and is effective only on subsequent requests (not the first one). * Note: All filter parameters are only effective for the first request. * Subsequent requests using the nextPage parameter will return the records based on filters as specified in the initial request. * * @param {string} [nextPage] - Token for retrieving the next page of results from the previous response. * * @returns {Promise} - Returns an object containing: * - type: Type of the response (e.g., "Patient") * - message: Descriptive message or status of the operation * - requestResource: Patient data of the requested resource ID * - totalNumberOfRecords: Total number of matched patients * * @throws {ValidationError} If any filter value is invalid. * @throws {Error} If the API request fails. * * @example * // Input: * const filters = { * identifier: "joelpauljoel@sbx", * state : "Telangana", * fromDate": "2025-03-04T13:33:51.397512770Z", * toDate": "2025-03-05T13:33:51.397512770Z", * } * const response = await patient.findByFilters(filters); * console.log(response) * * * // Expected Output: * { * data: { * Entry: [ * { * firstName: 'Joel', * middleName: 'Paul', * lastName: 'Jeripothula', * abhaAddress: 'joelpauljoel@sbx', * state: 'Telangana' * // ... other fields * }, * { * firstName: 'Neha', * lastName: 'Verma', * abhaAddress: 'joelpauljoel@sbx', * state: 'Telangana' * // ... other fields * } * // ... more entries * ], * total: 2 * } * } * */ findByFilters(filters: PatientFiltersDTO, nextPage?: string): Promise; transformFilterKeys(filters: Record): Promise>; get abha(): AbhaService; /** * Delete a patient * @param id - Patient's unique identifier */ delete(id: string): Promise; }