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

    Service for handling appointment-related operations.

    This class provides a comprehensive set of methods for managing appointments within the EHR system. It implements standardized CRUD (Create, Read, Update, Delete) and search functionalities for appointments.

    All operations are designed to be asynchronous and non-blocking, typically returning Promises (or reactive types like Mono in Java).

    Core Features:

    • Create new appointments
    • Retrieve appointment details
    • Update existing appointments
    • Delete or cancel appointments
    • Search appointments with filters

    This service ensures scalability by supporting non-blocking data operations.

    Hierarchy

    • BaseService
      • AppointmentService
    Index

    Constructors

    • Parameters

      • clientConfig: ClientConfig

      Returns AppointmentService

    Methods

    • Creates a new appointment record.

      This method validates the provided appointment data and sends a POST request to create an appointment.

      Parameters

      • appointment: AppointmentDTO

        The appointment data to be created. Fields include:

        • practitionerReference: (required) Reference ID of the practitioner.
        • patientReference: (required) Reference ID of the patient.
        • appointmentStartDate: (required) Start datetime of the appointment in ISO 8601 format (e.g., "2025-02-28T09:00:00Z").
        • appointmentEndDate: (required) End datetime of the appointment in ISO 8601 format (e.g., "2025-02-28T10:00:00Z").
        • appointmentPriority: (optional) Priority of the appointment, e.g., "EMERGENCY", "ROUTINE". Defaults to "EMERGENCY".
        • organizationId: (optional) ID of the organization the appointment is linked to.
        • appointmentSlot: (optional) ID of the specific slot booked.
        • reference: (optional) Appointment Resource ID.

      Returns Promise<CreateUpdateAppointmentResponse>

      A promise resolving to the appointment creation response object. The response includes:

      • type: Type of the response (e.g., "Appointment").
      • message: Response message string.
      • resourceId: ID of the newly created appointment resource (if successful).
      • validationErrors: An array of validation errors, if any occurred.
      • resource: The full appointment object created or relevant response content.

      If the input data is missing or invalid.

      If the API call fails or there’s a network/server issue.

      // Input:
      const appointment = {
      patientReference: "a8654878-4202-4b47-bcc4-868060a75254",
      practitionerReference: "3c7271bb-4212-4291-9f75-64d886d69893",
      appointmentStartDate: "2025-02-28T09:00:00Z",
      appointmentEndDate: "2025-02-28T10:00:00Z",
      appointmentPriority: "Emergency",
      organizationId: "org123",
      appointmentSlot: "slot123",
      reference: "ref123"
      };

      const result = await appointment.create(appointment);
      console.log(result);

      // Expected Output:
      {
      message: 'Successfully created the Appointment profile',
      type: 'Appointment',
      resourceId: '2d9f1cfb-3ab0-4697-907a-78431678df1e',
      validationErrors: [],
      fhirProfileId: '',
      resource: {
      reference: '2d9f1cfb-3ab0-4697-907a-78431678df1e',
      practitionerReference: '3c7271bb-4212-4291-9f75-64d886d69893',
      patientReference: 'a8654878-4202-4b47-bcc4-868060a75254',
      priority: 'Emergency',
      slot: '02:30 PM - 03:30 PM',
      start: '2025-02-28T09:00:00Z',
      end: '2025-02-28T10:00:00Z',
      organizationId: 'ACHALA_HEALTH_01'
      }
      }
    • Delete a Appointment

      Parameters

      • id: string

        Appointment's unique identifier

      Returns Promise<any>

    • Checks whether a appointment exists in the system using their unique identifier.

      Parameters

      • id: string

        Unique identifier (Resource ID) of the appointment to check - mandatory

      Returns Promise<boolean>

      A promise that resolves to:

      • true if the appointment exists

      If the id is null, undefined, or an empty string.

      If the API request fails or an unexpected error occurs.

      // Input:
      const doesExist = await appointment.exists("123e4567-e89b-12d3-a456-426614174000");
      console.log(doesExist);


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

      Parameters

      • OptionalpageSize: number

        Number of appointments to fetch in a single page - optional (Only effective in the first request. Default is 10 if not provided)

      • OptionalnextPage: string

        Cursor to fetch the next set appointments - optional (Use the value from the previous response's nextPage for pagination)

      Returns Promise<GetAppointmentResponse>

      Promise - Returns an object containing:

      • type: Type of the response (e.g., "success", "error")
      • message: Descriptive message or status of the operation
      • requestResource: Actual appointment data or list of appointments
      • totalNumberOfRecords: Total number of appointments in the system
      • nextPageLink: Token to retrieve the next page of results, if more records exist

      Throws an error if the request fails or response is invalid.

      // Input:
      const appointments = await appointment.findAll(20);
      const moreAppointments = await appointment.findAll(undefined, appointments.nextPage);

      // Expected Output:
      {
      data: {
      Entry: [
      {
      reference: '277eec90-04d4-4291-b578-a21c9f0563ba',
      practitionerReference: 'bb847118-135e-4c08-92a4-27506a3e807e',
      patientReference: '9a3ca20a-1bde-4e1f-b1cc-01fcd698aa42',
      priority: 'Emergency',
      slot: '03:30 PM - 02:15 PM',
      // ... other fields
      },
      {
      reference: '77907eec90-04d4-4291-b578-a21c9f0563ba',
      practitionerReference: 'bb9896578-135e-4c08-92a4-27506a3e807e',
      patientReference: '9a3ca20a-1bde-4e1f-b1cc-01fcd698aa42',
      priority: 'Emergency',
      // ... other fields
      }
      // ... more entries
      ],
      link: {
      nextPage: 'X2NvdW50PTEwJl9zb3J0PS1fb'
      },
      total: 900
      }
      }
    • Fetches a list of appointments based on specified filters.

      Validates and applies filters to retrieve appointment records. Useful for paginated search with filtering criteria.

      Parameters

      • filters: AppointmentFiltersDTO

        Filters to apply (used primarily on the first page of results):

        • practitionerReference: (optional) Reference ID of the practitioner.
        • patientReference: (optional) Reference ID of the patient.
        • slot: (optional) Appointment slot identifier.
        • appointmentDate: (optional) Date of appointment in ISO format (e.g., "2025-02-28").
        • organizationId: (optional) ID of the organization.
        • pageSize: (optional) Number of results to fetch per page.
        • appointmentPriority: (optional) Priority level of the appointment (e.g., "EMERGENCY", "ROUTINE").
      • OptionalnextPage: string

        Token or URL for fetching the next set of results (used for pagination).

      Returns Promise<GetAppointmentResponse>

      A promise that resolves with:

      • type: Type of the response (e.g., "Appointment")
      • message: Descriptive message or status of the operation
      • requestResource: Appointment data of the requested Resource ID
      • totalNumberOfRecords: Total number of appointments in the system
      • nextPageLink: Token to retrieve the next page of results, if more records exist.

      If filters are invalid or malformed.

      If the request fails or the server returns an error.

      // Input:
      const filters = {
      appointmentDate: "2025-02-28",
      pageSize: 10,
      organizationId: "IN3610001039"
      };

      const appointments = await appointment.findByFilters(filters);
      console.log(appointments);

      // Expected Output:
      {
      entry: [
      {
      reference: '332ca988-1e72-4a75-a252-5fc252460057',
      practitionerReference: '51a3e368-09a4-4398-bc19-405a6bfce0f2',
      patientReference: '4d92e619-6495-418f-9985-edd692e03436',
      priority: 'Emergency',
      slot: '02:30 PM - 03:30 PM',
      start: '2025-02-28T09:00:00Z',
      end: '2025-02-28T10:00:00Z',
      organizationId: 'IN3610001039'
      },
      {
      reference: 'f4ae6784-9469-4b8c-a487-9f9eec3b88e3',
      practitionerReference: '2cb4bb5d-8657-4c95-b547-579ee7b17f89',
      patientReference: '5e73f8d3-798d-4dd4-9989-a733e32be02d',
      priority: 'Routine',
      slot: '03:30 PM - 04:00 PM',
      start: '2025-02-28T10:30:00Z',
      end: '2025-02-28T11:00:00Z',
      organizationId: 'IN3610001039'
      }
      ],
      link: {
      nextPage: 'X2NvdW50PTEwJl9zb3J0PS1fb'
      },
      total: 25
      }
    • Fetches the details of an appointment using its unique identifier.

      Parameters

      • id: string

        Unique identifier (Resource ID) of the appointment to fetch (mandatory).

      Returns Promise<GetAppointmentResponse>

      Returns an object containing:

      • type: Type of the response (e.g., "Appointment")
      • message: Descriptive message or status of the operation
      • requestResource: Appointment data of the requested Resource ID
      • totalNumberOfRecords: Total number of appointments in the system
      • nextPageLink: Token to retrieve the next page of results, if more records exist

      If the id is null, undefined, or empty.

      If the API request fails.

      // Input:
      const appointment = await appointment.findById("d7d79e4c-a3db-4505-877d-f853610b7c4a");
      console.log(appointment);


      // Expected Output:
      {
      type: 'Appointment',
      message: 'Appointment Found !!!',
      requestResource: {
      reference: 'd7d79e4c-a3db-4505-877d-f853610b7c4a',
      practitionerReference: '3c7271bb-4212-4291-9f75-64d886d69893',
      patientReference: 'a8654878-4202-4b47-bcc4-868060a75254',
      priority: 'Emergency',
      slot: '02:30 PM - 03:30 PM',
      start: '2025-02-28T09:00:00Z',
      end: '2025-02-28T10:00:00Z',
      organizationId: 'ACHALA_HEALTH_01'
      },
      totalNumberOfRecords: 1
      }
    • Parameters

      • filters: Record<string, any>

      Returns Promise<Record<string, any>>

    • Updates an existing appointment record.

      Validates and sends the updated appointment data to the backend API.

      Parameters

      • updateAppointmentData: UpdateAppointmentDTO

        The updated appointment data. Fields include:

        • appointmentStartDate: (optional) Start datetime in ISO 8601 format (e.g., "2025-08-01T10:00:00Z").
        • appointmentEndDate: (optional) End datetime in ISO 8601 format (e.g., "2025-08-01T10:30:00Z").
        • appointmentPriority: (optional) Priority level, e.g., "EMERGENCY", "ROUTINE". Defaults to "EMERGENCY".
        • appointmentSlot: (optional) Identifier of the appointment slot booked.
        • reference: (mandatory) Appointment Resource ID.

      Returns Promise<CreateUpdateAppointmentResponse>

      A promise that resolves with:

      • type: (string) Response type, e.g., "success" or "error".
      • message: (string) Descriptive message about the operation outcome.
      • resourceId: (string, optional) ID of the updated appointment, if applicable.
      • validationErrors: (array, optional) Any validation issues encountered.
      • resource: (unknown) The updated appointment data or response payload.

      If the input data is missing or invalid.

      If the API request fails or there is a server/network error.

      const updateData = {
      appointmentStartDate: "2025-08-01T11:00:00Z",
      appointmentEndDate: "2025-08-01T11:30:00Z",
      appointmentPriority: "ROUTINE",
      appointmentSlot: "slot-456",
      reference: "updated-ref-001"
      };
      const updatedappointment = await appointment.update(updateData);
      console.log(updatedappointment)