@medic/cht-datasource
    Preparing search index...

    Interface Datasource

    Operations for working with people.

    interface Datasource {
        create: (input: PersonInput) => Promise<Person.v1.Person>;
        getByType: (personType: string) => AsyncGenerator<Person.v1.Person, null>;
        getByUuid: (uuid: string) => Promise<Nullable<Person.v1.Person>>;
        getByUuidWithLineage: (
            uuid: string,
        ) => Promise<Nullable<PersonWithLineage>>;
        getPageByType: (
            personType: string,
            cursor?: Nullable<string>,
            limit?: number | `${number}`,
        ) => Promise<Page<Person.v1.Person>>;
        update: <T extends PersonWithLineage | Person.v1.Person>(
            updated: T,
        ) => Promise<T>;
    }
    Index

    Properties

    create: (input: PersonInput) => Promise<Person.v1.Person>

    Creates a new person record.

    Type Declaration

    InvalidArgumentError if type is not provided or is not a supported person contact type

    InvalidArgumentError if name is not provided

    InvalidArgumentError if parent is not provided or is not the identifier of a valid contact. The parent contact's type must be one of the supported parent contact types for the new person.

    InvalidArgumentError if the provided reported_date is not in a valid format. Valid formats are 'YYYY-MM-DDTHH:mm:ssZ', 'YYYY-MM-DDTHH:mm:ss.SSSZ', or .

    getByType: (personType: string) => AsyncGenerator<Person.v1.Person, null>

    Returns a generator for fetching all people with the given type.

    Type Declaration

      • (personType: string): AsyncGenerator<Person.v1.Person, null>
      • Parameters

        • personType: string

          the type of people to return

        Returns AsyncGenerator<Person.v1.Person, null>

        a generator for fetching all people with the given type

    InvalidArgumentError if no type is provided or if the type is not for a person

    getByUuid: (uuid: string) => Promise<Nullable<Person.v1.Person>>

    Returns a person by their UUID.

    Type Declaration

    InvalidArgumentError if no UUID is provided

    getByUuidWithLineage: (uuid: string) => Promise<Nullable<PersonWithLineage>>

    Returns a person by their UUID along with the person's parent lineage.

    Type Declaration

    InvalidArgumentError if no UUID is provided

    getPageByType: (
        personType: string,
        cursor?: Nullable<string>,
        limit?: number | `${number}`,
    ) => Promise<Page<Person.v1.Person>>

    Returns an array of people for the provided page specifications.

    Type Declaration

      • (
            personType: string,
            cursor?: Nullable<string>,
            limit?: number | `${number}`,
        ): Promise<Page<Person.v1.Person>>
      • Parameters

        • personType: string

          the type of people to return

        • Optionalcursor: Nullable<string>

          the token identifying which page to retrieve. A null value indicates the first page should be returned. Subsequent pages can be retrieved by providing the cursor returned with the previous page.

        • Optionallimit: number | `${number}`

          the maximum number of people to return. Default is 100.

        Returns Promise<Page<Person.v1.Person>>

        a page of people for the provided specifications

    InvalidArgumentError if no type is provided or if the type is not for a person

    InvalidArgumentError if the provided limit is <= 0

    InvalidArgumentError if the provided cursor is not a valid page token or null

    getByType which provides the same data, but without having to manually account for paging

    update: <T extends PersonWithLineage | Person.v1.Person>(
        updated: T,
    ) => Promise<T>

    Updates an existing person to have the provided data.

    Type Declaration

      • <T extends PersonWithLineage | Person.v1.Person>(updated: T): Promise<T>
      • Type Parameters

        Parameters

        • updated: T

          the updated person data. The complete data for the person must be provided. Existing fields not included in the updated data will be removed from the person. If the provided parent lineage is hydrated (e.g. for a v1.PersonWithLineage), the lineage will be properly dehydrated before being stored.

        Returns Promise<T>

        the updated person with the new _rev value

    InvalidArgumentError if _id is not provided

    ResourceNotFoundError if _id does not identify an existing person contact

    InvalidArgumentError if _rev is not provided or does not match the person's current _rev value

    InvalidArgumentError if name is not provided

    InvalidArgumentError if any of the following read-only properties are changed: reported_date, parent, type, contact_type