CareStack EHR Node.js SDK Documentation
    Preparing search index...

    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.

    Hierarchy

    • BaseService
      • OrganizationService
    Index

    Constructors

    • Parameters

      • clientConfig: ClientConfig

      Returns OrganizationService

    Methods

    • Registers a new Organization.

      This function registers a new organization using the provided organization data.

      Parameters

      • organization: AddOrganizationDTO

        The organization data required for registration.

      Returns Promise<string>

      A promise that resolves to a string containing a message indicating whether the organization was successfully created or if an error occurred.

      Throws an error if the validation or API call fails.

      // 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"
    • Delete an organization

      Parameters

      • id: string

        organization's unique identifier

      Returns Promise<any>

    • Checks if an organization exists for the given identifier and ID type.

      Parameters

      • idType: OrganizationIdType

        Type of identifier used to check the organization (e.g., accountId, facilityId, id) - mandatory
        Accepted values: OrganizationIdType.ACCOUNT_ID | OrganizationIdType.FACILITY_ID | OrganizationIdType.ID

      • id: string

        Unique identifier value of the organization corresponding to the given idType - mandatory

      Returns Promise<boolean>

      • Returns:
        • true if the organization exists

      ValidationError - If idType or id is missing or invalid

      Error - For API failures, network issues, or unexpected server responses

      // Input:
      const exists = await organization.exists("accountId", "98765");
      console.log(exists)


      // Expected Output:
      true
    • Retrieves a paginated list of all organizations.

      Parameters

      • OptionalnextPage: string

        Token to fetch the next set of organizations (optional).
        Use the value from the previous response's nextPageLink for pagination.

      Returns Promise<GetOrganizationsResponse>

      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 an error if:

      • The API request fails
      • There is a network issue
      • The response is invalid or incomplete
      // 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
      }
    • Retrieves an organization by its identifier and ID type.

      Parameters

      • idType: OrganizationIdType

        Type of identifier used to fetch the organization (e.g., "accountId", "facilityId", "id") - mandatory
        Accepted values: OrganizationIdType.ACCOUNT_ID | OrganizationIdType.FACILITY_ID | OrganizationIdType.ID

      • id: string

        Unique identifier value for the organization based on the provided idType - mandatory

      Returns Promise<GetOrganizationsResponse>

      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)

      If idType or id is missing or invalid

      For any API or network-related issues

      // Input:
      const response = await organization.findById("accountId", "12345");
      console.log(response)
      // 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
      }
    • 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.

      Parameters

      • stateCode: string

        The LGD code of the state for which to get districts (e.g., "27" for Maharashtra). Must be a valid, non-null string.

      Returns Promise<Record<string, any>>

      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.

      // 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" },
      ...
      ]
    • Fetches the latitude and longitude for a given location using the Google Maps Geocoding API.

      Parameters

      • location: string

        The location (address, city, etc.) to geocode. Must be a valid non-empty string.

      Returns Promise<LocationDTO>

      A promise that resolves to a LocationDTO containing geolocation data such as latitude and longitude.

      If no results are found for the provided location.

      If the request to the Google Maps API is invalid (e.g., malformed or missing location).

      If the Google Maps API returns a server-side error (5xx).

      If there are network issues or unexpected failures during the API call.

      // 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"
      }
    • Fetches a list of code-value pairs for a specific master data type (e.g., all "ownership" types).

      Parameters

      • type: string

        The master data type to fetch (e.g., "ownership").

      Returns Promise<Record<string, any>>

      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.

      If the type parameter is null or an empty string.

      If the API call fails due to network or server-side errors.

      // 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" }
      ]
      }
    • 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<Record<string, any>>

      A promise that resolves with an object containing:

      • {Array<{type: string, desc: string}>} masterTypes - List of available master data types.

      Propagates errors returned by the underlying demographic service.

      // 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" }
      // ...
      ]
      }
    • 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.

      Parameters

      • organizationSubType: OrganizationSubTypeRequest

        An object containing the data needed to fetch organization sub-types.

        • code

          The parent organization type code (e.g., "HOSP").

      Returns Promise<Record<string, any>>

      A promise that resolves to an object containing the type and an array of organization sub-type entries.

      If the input data is invalid or missing required fields.

      If the API call fails or any other runtime error occurs.

      // 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" }
      ]
      }
    • 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.

      Parameters

      • organizationType: OrganizationTypeRequest

        The data required to fetch the organization type information.

      Returns Promise<Record<string, any>>

      A promise that resolves to an object containing the organization type data, or an error message if the request fails.

      Throws a ValidationError if the provided organization type data is invalid.

      Throws an error if the API request fails or any other error occurs during the process.

      // 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" }
      ]
      }
    • 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".

      Parameters

      • ownershipSubType: OwnershipSubTypeRequest

      Returns Promise<Record<string, any>>

      A promise that resolves to an object containing the ownership subtype list.

      If the ownershipTypeCode is null or an empty string.

      If the API call fails or an unexpected error occurs.

      // 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" }
      ]
      }
    • 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.

      Parameters

      • specialities: SpecialitiesRequest

        The code representing the system of medicine (e.g., "AYUSH", "ALLO").

      Returns Promise<Record<string, any>>

      A promise that resolves to an object containing the list of specialities.

      If the systemOfMedicineCode is null or empty.

      If the API request fails or another unexpected error occurs.

      // 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" }
      ]
      }
    • Fetches a complete list of all states and their associated districts from the LGD (Local Government Directory) API.

      Returns Promise<Record<string, any>>

      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.

      If an API error occurs during the fetch operation.

      // 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": [ ... ] },
      ...
      ]
    • Fetches a list of sub-districts (talukas/tehsils) that belong to a specific district, identified by its LGD code.

      Parameters

      • districtCode: string

        The LGD code of the district. Must not be null.

      Returns Promise<Record<string, any>>

      A promise that resolves to a list of sub-districts, each represented as a DistrictDTO object with its own code and name.

      Propagates any API errors encountered during the demographic service call.

      // 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" },
      ...
      ]
    • Searches for Organizations based on provided filters and pagination info.

      Validates the input search data and sends a request to the /search-organization endpoint.

      Parameters

      • searchOrganizationData: SearchOrganizationDTO

        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<SearchOrganizationResponse>

      • Resolves with:
      • organizations - List of matched organizations.
      • message - Response message.
      • totalOrganizations - Total number of organizations matched.
      • numberOfPages - Total pages available.
      • If searchOrganizationData is null, empty, or fails schema validation.
      • If the API call fails or a network issue occurs.
      // 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
      }
    • Updates an existing Organization's Spoc details.

      Parameters

      • updateOrganizationData: UpdateOrganizationDTO

        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<string>

      • A promise that resolves to a success message if the update is successful.

      ValidationError - If the provided data is invalid or missing.

      Error - For any API or network-related issues.

      // 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"