# Patient

## Get count of patients for a specific HcParty or for the current HcParty

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/hcParty/{hcPartyId}/count`

Returns the count of patients

#### Path Parameters

| Name                                        | Type   | Description         |
| ------------------------------------------- | ------ | ------------------- |
| hcPartyId<mark style="color:red;">\*</mark> | String | Healthcare party id |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Create a patient

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient`

Name, last name, date of birth, and gender are required. After creation of the patient and obtaining the ID, you need to create an initial delegation.

#### Request Body

| Name                                   | Type    | Description |
| -------------------------------------- | ------- | ----------- |
| body<mark style="color:red;">\*</mark> | Patient |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Create patients in bulk

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient/batch`

Returns the id and \_rev of created patients

#### Request Body

| Name                                   | Type | Description |
| -------------------------------------- | ---- | ----------- |
| body<mark style="color:red;">\*</mark> | List |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Delete patients.

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient/delete/batch`

Response is an array containing the ID of deleted patient..

#### Request Body

| Name                                   | Type      | Description |
| -------------------------------------- | --------- | ----------- |
| body<mark style="color:red;">\*</mark> | ListOfIds |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Filter patients for the current user (HcParty)

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient/filter`

Returns a list of patients along with next start keys and Document ID. If the nextStartKey is Null it means that this is the last page.

#### Query Parameters

| Name            | Type    | Description                                               |
| --------------- | ------- | --------------------------------------------------------- |
| startKey        | String  | The start key for pagination, depends on the filters used |
| startDocumentId | String  | A patient document ID                                     |
| limit           | Integer | Number of rows                                            |
| skip            | Integer | Skip rows                                                 |
| sort            | String  | Sort key                                                  |
| desc            | Boolean | Descending                                                |

#### Request Body

| Name                                   | Type               | Description |
| -------------------------------------- | ------------------ | ----------- |
| body<mark style="color:red;">\*</mark> | FilterChainPatient |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Find deleted patients

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/deleted/byDate`

Returns a list of deleted patients, within the specified time period, if any.

#### Query Parameters

| Name            | Type    | Description                                              |
| --------------- | ------- | -------------------------------------------------------- |
| startDate       | Long    | Filter deletions after this date (unix epoch), included  |
| endDate         | Long    | Filter deletions before this date (unix epoch), included |
| desc            | Boolean | Descending                                               |
| startDocumentId | String  | A patient document ID                                    |
| limit           | Integer | Number of rows                                           |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Get Paginated List of Patients sorted by Access logs descending

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/byAccess/{userId}`

#### Path Parameters

| Name                                     | Type   | Description |
| ---------------------------------------- | ------ | ----------- |
| userId<mark style="color:red;">\*</mark> | String | A User ID   |

#### Query Parameters

| Name            | Type    | Description                           |
| --------------- | ------- | ------------------------------------- |
| accessType      | String  | The type of access (COMPUTER or USER) |
| startDate       | Long    | The start search epoch                |
| startKey        | String  | The start key for pagination          |
| startDocumentId | String  | A patient document ID                 |
| limit           | Integer | Number of rows                        |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## List patients for a specific HcParty

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient`

Returns a list of patients along with next start keys and Document ID. If the nextStartKey is Null it means that this is the last page.

#### Query Parameters

| Name            | Type    | Description                                                                                                                                |
| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| hcPartyId       | String  | Healthcare party id                                                                                                                        |
| sortField       | String  | Optional value for sorting results by a given field ('name', 'ssin', 'dateOfBirth'). Specifying this deactivates filtering                 |
| startKey        | String  | The start key for pagination: a JSON representation of an array containing all the necessary components to form the Complex Key's startKey |
| startDocumentId | String  | A patient document ID                                                                                                                      |
| limit           | Integer | Number of rows                                                                                                                             |
| sortDirection   | String  | Optional value for providing a sorting direction ('asc', 'desc'). Set to 'asc' by default.                                                 |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Find patients for the current user (HcParty)

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/byNameBirthSsinAuto`

Returns a list of patients along with next start keys and Document ID. If the nextStartKey is Null it means that this is the last page.

#### Query Parameters

| Name              | Type    | Description                                                                                                                                |
| ----------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| healthcarePartyId | String  | HealthcareParty Id, if unset will user user's hcpId                                                                                        |
| filterValue       | String  | Optional value for filtering results                                                                                                       |
| startKey          | String  | The start key for pagination: a JSON representation of an array containing all the necessary components to form the Complex Key's startKey |
| startDocumentId   | String  | A patient document ID                                                                                                                      |
| limit             | Integer | Number of rows                                                                                                                             |
| sortDirection     | String  | Optional value for providing a sorting direction ('asc', 'desc'). Set to 'asc' by default.                                                 |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## List patients by pages for a specific HcParty

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/byHcPartyId`

Returns a list of patients along with next start keys and Document ID. If the nextStartKey is Null it means that this is the last page.

#### Query Parameters

| Name                                        | Type    | Description           |
| ------------------------------------------- | ------- | --------------------- |
| hcPartyId<mark style="color:red;">\*</mark> | String  | Healthcare party id   |
| startKey                                    | String  | The page first id     |
| startDocumentId                             | String  | A patient document ID |
| limit                                       | Integer | Page size             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## List patients that have been modified after the provided date

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/modifiedAfter/{date}`

Returns a list of patients that have been modified after the provided date

#### Path Parameters

| Name                                   | Type | Description |
| -------------------------------------- | ---- | ----------- |
| date<mark style="color:red;">\*</mark> | Long |             |

#### Query Parameters

| Name            | Type    | Description                                                                |
| --------------- | ------- | -------------------------------------------------------------------------- |
| startKey        | Long    | The start key for pagination the date of the first element of the new page |
| startDocumentId | String  | A patient document ID                                                      |
| limit           | Integer | Number of rows                                                             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Filter patients for the current user (HcParty)

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/fuzzy`

Returns a list of patients

#### Query Parameters

| Name        | Type    | Description       |
| ----------- | ------- | ----------------- |
| firstName   | String  | The first name    |
| lastName    | String  | The last name     |
| dateOfBirth | Integer | The date of birth |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Get patient

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/{patientId}`

It gets patient administrative data.

#### Path Parameters

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| patientId<mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Get the patient having the provided externalId

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/byExternalId/{externalId}`

#### Path Parameters

| Name                                         | Type   | Description   |
| -------------------------------------------- | ------ | ------------- |
| externalId<mark style="color:red;">\*</mark> | String | A external ID |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Get patient by identifier

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/{hcPartyId}/{id}`

It gets patient administrative data based on the identifier (root & extension) parameters.

#### Path Parameters

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| hcPartyId<mark style="color:red;">\*</mark> | String |             |
| id<mark style="color:red;">\*</mark>        | String |             |

#### Query Parameters

| Name   | Type   | Description |
| ------ | ------ | ----------- |
| system | String |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Get the patient (identified by patientId) hcparty keys. Those keys are AES keys (encrypted) used to share information between HCPs and a patient.

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/{patientId}/keys`

This endpoint is used to recover all keys that have already been created and that can be used to share information with this patient. It returns a map with the following structure: ID of the owner of the encrypted AES key -> encrypted AES key. The returned encrypted AES keys will have to be decrypted using the patient's private key.

#### Path Parameters

| Name                                        | Type   | Description                                    |
| ------------------------------------------- | ------ | ---------------------------------------------- |
| patientId<mark style="color:red;">\*</mark> | String | The patient Id for which information is shared |

{% tabs %}
{% tab title="200 " %}

{% endtab %}

{% tab title="401 " %}

{% endtab %}
{% endtabs %}

## Get patients by id

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient/byIds`

It gets patient administrative data.

#### Request Body

| Name                                   | Type      | Description |
| -------------------------------------- | --------- | ----------- |
| body<mark style="color:red;">\*</mark> | ListOfIds |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Find deleted patients

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/deleted/by_name`

Returns a list of deleted patients, by name and/or firstname prefix, if any.

#### Query Parameters

| Name      | Type   | Description       |
| --------- | ------ | ----------------- |
| firstName | String | First name prefix |
| lastName  | String | Last name prefix  |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## List patients that have been merged towards another patient

<mark style="color:blue;">`GET`</mark> `https://demo.icure.cloud/rest/v2/patient/merges/{date}`

Returns a list of patients that have been merged after the provided date

#### Path Parameters

| Name                                   | Type | Description |
| -------------------------------------- | ---- | ----------- |
| date<mark style="color:red;">\*</mark> | Long |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Get ids of patients matching the provided filter for the current user (HcParty)

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient/match`

#### Request Body

| Name                                   | Type                  | Description |
| -------------------------------------- | --------------------- | ----------- |
| body<mark style="color:red;">\*</mark> | AbstractFilterPatient |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Merge a series of patients into another patient

<mark style="color:orange;">`PUT`</mark> `https://demo.icure.cloud/rest/v2/patient/mergeInto/{toId}/from/{fromIds}`

#### Path Parameters

| Name                                      | Type   | Description |
| ----------------------------------------- | ------ | ----------- |
| toId<mark style="color:red;">\*</mark>    | String |             |
| fromIds<mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Modify a patient

<mark style="color:orange;">`PUT`</mark> `https://demo.icure.cloud/rest/v2/patient`

No particular return value. It's just a message.

#### Request Body

| Name                                   | Type    | Description |
| -------------------------------------- | ------- | ----------- |
| body<mark style="color:red;">\*</mark> | Patient |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Set a patient referral doctor

<mark style="color:orange;">`PUT`</mark> `https://demo.icure.cloud/rest/v2/patient/{patientId}/referral/{referralId}`

#### Path Parameters

| Name                                         | Type   | Description                                          |
| -------------------------------------------- | ------ | ---------------------------------------------------- |
| patientId<mark style="color:red;">\*</mark>  | String |                                                      |
| referralId<mark style="color:red;">\*</mark> | String | The referal id. Accepts 'none' for referral removal. |

#### Query Parameters

| Name  | Type | Description                          |
| ----- | ---- | ------------------------------------ |
| start | Long | Optional value for start of referral |
| end   | Long | Optional value for end of referral   |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Modify patients in bulk

<mark style="color:orange;">`PUT`</mark> `https://demo.icure.cloud/rest/v2/patient/batch`

Returns the id and \_rev of modified patients

#### Request Body

| Name                                   | Type | Description |
| -------------------------------------- | ---- | ----------- |
| body<mark style="color:red;">\*</mark> | List |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Delegates a patients to a healthcare party

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient/{patientId}/delegate`

It delegates a patient to a healthcare party (By current healthcare party). A modified patient with new delegation gets returned.

#### Path Parameters

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| patientId<mark style="color:red;">\*</mark> | String |             |

#### Request Body

| Name                                   | Type | Description |
| -------------------------------------- | ---- | ----------- |
| body<mark style="color:red;">\*</mark> | List |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## Register a patient

<mark style="color:green;">`POST`</mark> `https://demo.icure.cloud/rest/v2/patient/register/forHcp/{hcPartyId}/inGroup/{groupId}`

Register a new patient into the system

#### Path Parameters

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| hcPartyId<mark style="color:red;">\*</mark> | String |             |
| groupId<mark style="color:red;">\*</mark>   | String |             |

#### Request Body

| Name                                   | Type    | Description |
| -------------------------------------- | ------- | ----------- |
| body<mark style="color:red;">\*</mark> | Patient |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}

## undelete previously deleted patients

<mark style="color:orange;">`PUT`</mark> `https://demo.icure.cloud/rest/v2/patient/undelete/{patientIds}`

Response is an array containing the ID of undeleted patient..

#### Path Parameters

| Name                                         | Type   | Description |
| -------------------------------------------- | ------ | ----------- |
| patientIds<mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200 " %}

{% endtab %}
{% endtabs %}
