import { BaseService } from "../base"; import { AddOrganizationDTO, GetOrganizationsResponse, SearchOrganizationDTO, SearchOrganizationResponse, UpdateOrganizationDTO, OrganizationTypeRequest, OrganizationSubTypeRequest, OwnershipSubTypeRequest, SpecialitiesRequest } from "./organization.dto"; import { OrganizationIdType } from "../common/enums"; /** * Provides specialized services for managing Organization resources. * * This class handles all operations related to organizations, including: * - Searching * - Registration * - Finding specific organization * - To check whether a organization exists or not * - Fetching associated demographic or master data (such as states, districts, and facility types) * * Unlike other resource services, this class has custom methods tailored specifically for * organization management and does not implement the generic `ResourceService` interface. */ export declare class OrganizationService extends BaseService { private readonly logger; /** * Retrieves a paginated list of all organizations. * * @param {string} [nextPage] - Token to fetch the next set of organizations (optional). * Use the value from the previous response's `nextPageLink` for pagination. * * @returns {Promise} A promise that resolves to an object containing: * - `message` - Status or information message about the response (mandatory) * - `data` - List of organization objects or related information (mandatory) * - `nextPageLink` - Token to retrieve the next page of organizations (mandatory) * - `totalNumberOfRecords` - Total number of organizations available (optional) * * @throws {Error} Throws an error if: * - The API request fails * - There is a network issue * - The response is invalid or incomplete * * @example * // Input: * const organizations = await organization.findAll(); * * // Fetch next page using pagination token * const moreOrgs = await organization.findAll(organizations.nextPageLink); * * * // Expected output: * { * data: [ * { id: "ORG001", organizationName: "City Hospital", ... }, * { id: "ORG002", organizationName: "Community Clinic", ... } * ], * nextPageLink: "someOpaqueTokenForPage2", * message: "Successfully fetched organizations", * totalNumberOfRecords: 200 * } */ findAll(nextPage?: string): Promise; /** * Retrieves an organization by its identifier and ID type. * * @param {OrganizationIdType} idType - Type of identifier used to fetch the organization (e.g., "accountId", "facilityId", "id") - mandatory * Accepted values: OrganizationIdType.ACCOUNT_ID | OrganizationIdType.FACILITY_ID | OrganizationIdType.ID * * @param {string} id - Unique identifier value for the organization based on the provided `idType` - mandatory * * @returns {Promise} A promise that resolves to: * - `message`: Status or informational message about the response (mandatory) * - `data`: Organization data associated with the given identifier (mandatory) * - `nextPageLink`: Pagination token if additional data exists (optional) * - `totalNumberOfRecords`: Total count of matching records (optional) * * @throws {ValidationError} If `idType` or `id` is missing or invalid * @throws {Error} For any API or network-related issues * * @example * // Input: * const response = await organization.findById("accountId", "12345"); * console.log(response) * * @example * // Expected Output: * { * message: "Organization Found !!!", * data: { * id: "someInternalId", * organizationId: "HFR-XYZ-123", * organizationName: "Sunshine Hospital", * basicInformation: { * address: "123 Main Street, Hyderabad", * state: "Telangana", * pincode: "500001", * contactNumber: "+919876543210" * }, * // ... other organization fields * }, * totalNumberOfRecords: 1 * } */ findById(idType: OrganizationIdType, id: string): Promise; /** * Checks if an organization exists for the given identifier and ID type. * * @param idType - Type of identifier used to check the organization (e.g., accountId, facilityId, id) - mandatory * Accepted values: OrganizationIdType.ACCOUNT_ID | OrganizationIdType.FACILITY_ID | OrganizationIdType.ID * * @param id - Unique identifier value of the organization corresponding to the given `idType` - mandatory * * @returns {Promise} - Returns: * - `true` if the organization exists * * @throws ValidationError - If `idType` or `id` is missing or invalid * @throws Error - For API failures, network issues, or unexpected server responses * * @example * // Input: * const exists = await organization.exists("accountId", "98765"); * console.log(exists) * * * // Expected Output: * true */ exists(idType: OrganizationIdType, id: string): Promise; /** * Registers a new Organization. * * This function registers a new organization using the provided organization data. * * @param {AddOrganizationDTO} organization - The organization data required for registration. * * @returns {Promise} A promise that resolves to a string containing a message indicating * whether the organization was successfully created or if an error occurred. * * @throws {Error} Throws an error if the validation or API call fails. * * @example * // Input: * const response = await organization.create({ * basicInformation: { * address: "123 Main Street, Hyderabad", * state: "Telangana", * pincode: "500001", * contactNumber: "+919876543210" * }, * // ... other organization fields * }); * console.log(message); * * * // Expected Output: * "Facility added successfully. Your facility ID is IN6778" */ create(organization: AddOrganizationDTO): Promise; /** * Updates an existing Organization's Spoc details. * * @param updateOrganizationData - Object containing updated organization information - mandatory * Fields of `UpdateOrganizationDTO` include: * - id - Unique ID of the organization to be updated - mandatory * - spocName - Name of the SPOC (Single Point of Contact) - mandatory * - spocId - Unique identifier of the SPOC - mandatory * - consentManagerName - Name of the Consent Manager - optional * - consentManagerId - Unique ID of the Consent Manager - optional * * @returns {Promise} - A promise that resolves to a success message if the update is successful. * * @throws ValidationError - If the provided data is invalid or missing. * @throws Error - For any API or network-related issues. * * @example * // Input: * const response = await organization.update({ * id: "org-123", * spocName: "Dr. Sneha", * spocId: "spoc-001", * consentManagerName: "Health Consent Inc.", * consentManagerId: "cm-001" * }); * * * // Expected Output: * "Spoc and Consent Manager added Successfully" */ update(updateOrganizationData: UpdateOrganizationDTO): Promise; /** * Searches for Organizations based on provided filters and pagination info. * * Validates the input search data and sends a request to the `/search-organization` endpoint. * * @param {SearchOrganizationDTO} searchOrganizationData - Filters and pagination info used for searching organizations. * * Fields of `SearchOrganizationDTO` include: * - ownershipCode (optional) - Type of ownership (e.g., "GOVT", "PVT", etc.). * - stateLGDCode (optional) - State code as per LGD standards. * - districtLGDCode (optional) - District code as per LGD. * - subDistrictLGDCode (optional) - Sub-district code as per LGD. * - pincode (optional) - 6-digit postal code. * - facilityName (optional) - Organization name (3 to 200 characters). Maps to `organizationName`. * - facilityId (optional) - Unique ID of the organization. Maps to `organizationId`. * - page (required) - Page number to fetch (minimum 1). * - resultsPerPage (required) - Number of results per page (1–100). * * @returns {Promise} - Resolves with: * - organizations - List of matched organizations. * - message - Response message. * - totalOrganizations - Total number of organizations matched. * - numberOfPages - Total pages available. * * @throws {ValidationError} - If searchOrganizationData is null, empty, or fails schema validation. * @throws {Error} - If the API call fails or a network issue occurs. * * @example * // Input: * const response = await organization.search({ * ownershipCode: "GOVT", * stateLGDCode: "28", * pincode: "500032", * facilityName: "Primary Health Center", * page: 1, * resultsPerPage: 10 * }); * * * // Expected Output: * { * "data": [ * { * "organizationName": "Andheri West Clinic", * // other fields... * } * ], * "total": 1, * "page": 1 * } */ search(searchOrganizationData: SearchOrganizationDTO): Promise; /** * Delete an organization * @param id - organization's unique identifier */ delete(id: string): Promise; /** * Fetches a list of all available master data categories from the demographic service. * These types can then be used to fetch specific master data lists. * * * @returns {Promise>} A promise that resolves with an object containing: * - {Array<{type: string, desc: string}>} masterTypes - List of available master data types. * * @throws {Error} Propagates errors returned by the underlying demographic service. * * @example * // Input: * const masterTypes = await organization.getMasterTypes(); * console.log("Available Master Data Types:"); * masterTypes.masterTypes.forEach(type => { * console.log(`- ${type.type}: ${type.desc}`); * }); * * * // Expected Output: * { * "masterTypes": [ * { "type": "ownership", "desc": "Facility Ownership" }, * { "type": "speciality", "desc": "Medical Specialities" } * // ... * ] * } */ getMasterTypes(): Promise>; /** * Fetches a list of code-value pairs for a specific master data type (e.g., all "ownership" types). * * @param {string} type - The master data type to fetch (e.g., "ownership"). * @throws {ValidationError} If the `type` parameter is null or an empty string. * @throws {Error} If the API call fails due to network or server-side errors. * * @returns { Promise> } A promise that resolves to an object containing: * - {string} type - The name of the master type requested. * - {Array<{code: string, value: string}>} data - List of code-value pairs under the specified master type. * * @example * // Input: * const result = await organization.getMasterData("ownership"); * console.log("Ownership Types:"); * result.data.forEach(item => { * console.log(`- Code: ${item.code}, Value: ${item.value}`); * }); * * * // Expected Output: * { * "type": "ownership", * "data": [ * { "code": "PVT", "value": "Private" }, * { "code": "GOV", "value": "Government" } * ] * } */ getMasterData(type: string): Promise>; /** * Fetches a complete list of all states and their associated districts from the LGD (Local Government Directory) API. * * @returns {Promise>} A promise that resolves to an array of `StateDTO` objects. * Each `StateDTO` includes: * - {string} code - The LGD code of the state. * - {string} name - The name of the state. * - {Array} districts - A list of districts belonging to the state. * * @throws {Error} If an API error occurs during the fetch operation. * * @example * // Input: * const states = await organizationService.getLgdStates(); * console.log("Total states found:", states.length); * states.forEach(state => { * console.log("- " + state.name); * }); * * * // Expected Output: * [ * { "code": "27", "name": "MAHARASHTRA", "districts": [ ... ] }, * { "code": "29", "name": "KARNATAKA", "districts": [ ... ] }, * ... * ] */ getStates(): Promise>; /** * Extracts districts for a specific state from a pre-fetched list of states. * This is a client-side filtering operation and does not make an API call. * * @param {string} stateCode - The LGD code of the state for which to get districts (e.g., "27" for Maharashtra). * Must be a valid, non-null string. * * @param {Array>} states - The complete list of states (typically fetched via `getLgdStates()`). * Must be a non-null array of StateDTO objects. * * @returns {Promise>} A promise that resolves to an array of `DistrictDTO` objects for the given state. * If the state code is not found, returns an empty array. * * @example * // Input: * // First, fetch all states * const allStates = await organization.getStates(); * * // Then, extract districts for a specific state * const districts = await organization.getDistrictsByState("27", allStates); * console.log("Districts in Maharashtra:", districts); * * * // Expected Output: * [ * { "code": "519", "name": "Mumbai" }, * { "code": "520", "name": "Pune" }, * ... * ] */ getDistrictsByState(stateCode: string): Promise>; /** * Fetches a list of sub-districts (talukas/tehsils) that belong to a specific district, identified by its LGD code. * * @param {number} districtCode - The LGD code of the district. Must not be null. * * @returns {Promise>} A promise that resolves to a list of sub-districts, each represented as a `DistrictDTO` object with its own code and name. * * @throws {Error} Propagates any API errors encountered during the demographic service call. * * @example * // Input: * const puneDistrictCode = 520; * organization.getSubDistricts(puneDistrictCode) * .then(subDistricts => { * console.log("Sub-districts in Pune:", subDistricts); * }); * * * // Expected Output: * [ * { "code": "4185", "name": "Haveli" }, * { "code": "4186", "name": "Maval" }, * ... * ] */ getSubDistricts(districtCode: string): Promise>; /** * Fetches the latitude and longitude for a given location using the Google Maps Geocoding API. * * @param {string} location - The location (address, city, etc.) to geocode. Must be a valid non-empty string. * * @returns {Promise} A promise that resolves to a `LocationDTO` * containing geolocation data such as latitude and longitude. * * @throws {NotFoundError} If no results are found for the provided location. * @throws {ValidationError} If the request to the Google Maps API is invalid (e.g., malformed or missing location). * @throws {InternalServerError} If the Google Maps API returns a server-side error (5xx). * @throws {ConnectionError} If there are network issues or unexpected failures during the API call. * * @example * // Input: * const result = await organization.getLatitudeAndLongitude("Bengaluru, India"); * console.log(result.results[0].geometry.location); // { lat: ..., lng: ... } * * * // Expected Output: * { * "results": [ * { * "geometry": { * "location": { * "lat": 37.4224764, * "lng": -122.0842499 * } * }, * ... * } * ], * "status": "OK" * } */ getLatitudeAndLongitude(location: string): Promise<{ lat: number; lng: number; }>; /** * Fetches organization type data based on the provided request. * * This function validates the input `organizationType` data before making a request to retrieve organization type information. * If the validation fails or if an error occurs during the API call, an error is thrown. * * @param {OrganizationTypeRequest} organizationType - The data required to fetch the organization type information. * @returns {Promise>} A promise that resolves to an object containing the organization type data, * or an error message if the request fails. * @throws {ValidationError} Throws a `ValidationError` if the provided organization type data is invalid. * @throws {Error} Throws an error if the API request fails or any other error occurs during the process. * * @example * // Input: * const result = await orgganization.getOrganizationType("PVT"); * console.log("Organization Types for Private Ownership:"); * result.data.forEach(item => console.log("- " + item.value)); * * * // Expected Output: * { * "type": "facilityType", * "data": [ * { "code": "HOSP", "value": "Hospital" }, * { "code": "CLIN", "value": "Clinic" } * ] * } */ getOrganizationType(organizationType: OrganizationTypeRequest): Promise>; /** * Fetches organization sub-type data based on the provided request. * * This function validates the input `organizationSubType` data before making a request to retrieve * organization sub-type information. If validation fails or if an error occurs during the API call, an error is thrown. * * @param {OrganizationSubTypeRequest} organizationSubType - An object containing the data needed to fetch organization sub-types. * @param {string} organizationSubType.code - The parent organization type code (e.g., "HOSP"). * * @returns {Promise<{ * type: string, * data: Array<{ code: string, value: string }> * }>} A promise that resolves to an object containing the type and an array of organization sub-type entries. * * @throws {ValidationError} If the input data is invalid or missing required fields. * @throws {Error} If the API call fails or any other runtime error occurs. * * @example * // Input: * const result = await organization.getOrganizationSubType({ code: "HOSP" }); * console.log("Hospital Subtypes:"); * result.data.forEach(item => console.log("- " + item.value)); * * * // Expected Output: * { * type: "facilitySubType", * data: [ * { code: "GEN", value: "General Hospital" }, * { code: "SUP", value: "Super Speciality Hospital" } * ] * } */ getOrganizationSubType(organizationSubType: OrganizationSubTypeRequest): Promise>; /** * Fetches a list of ownership subtypes based on a parent ownership type code. * * For example, if the parent type is "Government", the subtypes might include "State Government" or "Central Government". * * @param {string} ownershipTypeCode - The code of the parent ownership type (e.g., "GOV"). * * @returns {Promise<{ * type: string, * data: Array<{ code: string, value: string }> * }>} A promise that resolves to an object containing the ownership subtype list. * * @throws {ValidationError} If the `ownershipTypeCode` is null or an empty string. * @throws {Error} If the API call fails or an unexpected error occurs. * * @example * // Input: * const result = await organization.getOwnershipSubType("GOV"); * console.log("Government Ownership Subtypes:"); * result.data.forEach(item => console.log("- " + item.value)); * * * // Expected Output: * { * type: "ownershipSubType", * data: [ * { code: "SG", value: "State Government" }, * { code: "CG", value: "Central Government" } * ] * } */ getOwnershipSubType(ownershipSubType: OwnershipSubTypeRequest): Promise>; /** * Fetches a list of medical specialities available for a given system of medicine. * * For example, for "Allopathy", it may return specialities like "General Medicine", "Pediatrics", etc. * * @param {string} specialities - The code representing the system of medicine (e.g., "AYUSH", "ALLO"). * * @returns {Promise<{ * type: string, * data: Array<{ code: string, value: string }> * }>} A promise that resolves to an object containing the list of specialities. * * @throws {ValidationError} If the `systemOfMedicineCode` is null or empty. * @throws {Error} If the API request fails or another unexpected error occurs. * * @example * // Input: * const specialities = await organization.getSpecialitiesForMedicine("AYUSH"); * console.log("AYUSH Specialities:"); * specialities.data.forEach(item => console.log("- " + item.value)); * * * // Expected Output: * { * type: "speciality", * data: [ * { code: "AYUR", value: "Ayurveda" }, * { code: "YOGA", value: "Yoga & Naturopathy" } * ] * } */ getSpecialitiesForMedicine(specialities: SpecialitiesRequest): Promise>; }