# Clinic Project

Here is a tutorial for creating a "Clinic" project in Accelerator Platform -

* Sign-in as root user in the accelerator platform instance.
* As a root user, create a Clinic organization using the below code

<details>

<summary>Create Clinic Organization</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/Organizations

#### REQUEST HEADER

```json
{ 
        "Authorization": "bearer <Project-Admin-AuthToken>" 
}
```

#### RESPONSE

```json
200 
<Organization-Id> 
```

</details>

* Two user types will be created in the Clinic organization : Providers and Patients.
* Create Provider Object with fields like Name and Email using the below code -

<details>

<summary>Create Provider Object</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/CreateObject

#### REQUEST HEADERcode

```json
{ 
        "Authorization": "bearer <Project-Admin-AuthToken>" 
}
```

#### REQUEST BODY

```json
{ 
    "name": "Providers", 
    "containsUsers": true, 
    "fields":[ 
      { 
          "type": "text", 
          "name": "name", 
          "label": "Name", 
          "validators": { 
              "isRequired": true, 
              "minChars": 3, 
              "maxChars": 50 
          } 
      }, 
      { 
          "type": "email", 
          "name": "email", 
          "label": "Email", 
          "validators": { 
            "isRequired": true, 
            "isUnique": true, 
            "regex": "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$" 
          } 
      } 
    ] 
 }
```

#### RESPONSE

```json
200 
<Providers-object-id>  
```

</details>

* Create Patient Object with fields like name, email, provider using the below code -

<details>

<summary>Create Patient Object</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/CreateObject

#### REQUEST HEADER

```json
{ 
        "Authorization": "bearer <Project-Admin-AuthToken>" 
}
```

#### REQUEST BODY

```json
{ 
    "name": "Patients", 
    "containsUsers": true, 
    "fields":[ 
      { 
          "type": "text", 
          "name": "name", 
          "label": "Name", 
          "validators": { 
              "isRequired": true, 
              "minChars": 3, 
              "maxChars": 50 
          } 
      }, 
      { 
          "type": "email", 
          "name": "email", 
          "label": "Email", 
          "validators": { 
            "isRequired": true, 
            "isUnique": true, 
            "regex": "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$" 
          } 
      }, 
      { 
          "type": "reference", 
          "name": "provider", 
          "label": "Provider", 
          "validators": { 
              "isRequired": true 
          }, 
          "lookup":{ 
              "ObjectId": "<Providers-object-Id>", 
              "returnedFields": [ 
                  "name", 
                  "email" 
              ] 
          } 
      } 
    ] 
} 
```

#### RESPONSE

```json
200 
<Patients-object-id> 
```

</details>

* Both Providers and Patients will have different policies to accommodate their respective requirements. Create Provider's data access policy using the below code -

<details>

<summary>Create Provider's Data Access Policy</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/CreatePolicy

#### REQUEST HEADER

```json
{ 
        "Authorization": "bearer <Project-Admin-AuthToken>" 
}
```

#### REQUEST BODY

```json
{ 
  "name": "providerDataAccess", 
  "label": "Provider Data Access", 
  "version": "2023-01", 
  "type": "ObjectControl", 
  "object": "Providers", 
  "fields": { 
    "read": "*", 
    "write": ["name"] 
  }, 
  "condition": { 
    "stringEquals": { 
    "email": "{{user.email}}" 
    } 
  } 
} 
```

#### RESPONSE

```json
200 
<Provider-Data-Access-Policy-Id> 
```

</details>

* As Providers can access the data of Patient, create Provider's Access To Patients Data using the below code -

<details>

<summary>Create Policy for Provider's to Access Patients Data</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/CreatePolicy

#### REQUEST HEADER

```json
{ 
        "Authorization": "bearer <Project-Admin-AuthToken>" 
}
```

#### REQUEST BODY

<pre class="language-json"><code class="lang-json"><strong>{ 
</strong>  "name": "ProvidersAccessToPatientsData", 
  "label": "Providers Access To Patients Data", 
  "version": "2023-01", 
  "type": "ObjectControl", 
  "object": "Patients", 
  "fields": { 
    "read": "*" 
  }, 
  "condition": { 
    "stringEquals": { 
      "provider": "{{user.id}}" 
    } 
  } 
}  
</code></pre>

#### RESPONSE

```json
200 
<Providers-Access-To-Patients-Data-Policy-Id>  
```

</details>

* Create Patient's data access policy using the below code -

<details>

<summary>Create Patient's Data Access Policy</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/CreatePolicy

#### REQUEST HEADER

```json
{ 
        "Authorization": "bearer <Project-Admin-AuthToken>" 
}
```

#### REQUEST BODY

```json
{ 

  "name": "patientDataAccess", 
  "label": "Patient Data Access", 
  "version": "2023-01", 
  "type": "ObjectControl", 
  "object": "Patients", 
  "fields": { 
    "read": ["name", "email", "provider"], 
    "write": "*" 
  }, 
  "condition": { 
    "stringEquals": { 
      "email": "{{user.email}}" 
    } 
  } 
} 
```

#### RESPONSE

```json
200 
<Patients-Data-Access-Policy-Id> 
```

</details>

* As Patient's can access the basic information of the Provider, create Patient’s Access to Providers using the below code -&#x20;

<details>

<summary>Create Policy for Patient's to Access Provider Data</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/CreatePolicy

#### REQUEST HEADER

```json
{ 
        "Authorization": "bearer <Project-Admin-AuthToken>" 
}
```

#### REQUEST BODY

```json
{ 
  "name": " patientsAccessToProviders ", 
  "label": " Patients Access to Providers", 
  "version": "2023-01", 
  "type": "ObjectControl", 
  "object": "Providers", 
  "fields": { 
    "read": ["_id", "name", "email" ], 
  }, 
  "condition": {} 
  } 
}  
```

#### RESPONSE

```json
200 
<Patients-Access-to-Provider-Policy-Id>   
```

</details>

* As root user, add data into Provider's Object using below code -

<details>

<summary>Add Providers into Provider's Object</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/AddItems/Providers

#### REQUEST HEADER

```json
{ 
         "Authorization": "bearer <Provider -AuthToken>"
}
```

#### REQUEST BODY

```json
[ 
  { 
    "name": "[Name of the Provider]",  
    "email": "[Email of the Provider]" 
  } 
] 
```

#### RESPONSE

```json
200 
<n> of <n> items inserted successfully    
```

</details>

* View the list of providers in Provider's Object using the below code

<details>

<summary>List of all the providers into Provider's Object</summary>

#### GET

<https://api.accelerator-platform.com/\\><project-id>/v1/GetItems/Providers

#### REQUEST HEADER

```json
{ 
         "Authorization": "bearer <Provider-AuthToken>"
}
```

#### RESPONSE

```json
200 
<list of all Providers>  
```

</details>

* As root user, invite Providers who can later invite Patients using the below code&#x20;

<details>

<summary>Add Providers into the Accelerator Platform</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/InviteUser/\<Provider-Role-Id>?sendInvite=true\&sendInviteRole=\<Patient-Role-Id>

#### REQUEST HEADER

```json
{ 
         "Authentication": "bearer <Project-Admin-AuthToken>"
}
```

#### REQUEST BODY

```json
{ 

  "Type": "email", 
  "ContentType": "html", 
  "Subject": "Provider Invitation", 
  "SenderName": "[Name of the Email Sender]", 
  "SenderEmail": "[Email Address of the Sender]", 
  "RecipientList": [ "<Email of the Provider>" ], 
  "TemplateId": "user_invitation", 
  "Vars": { 
    "firstName": "[Name of the Provider]", 
    "role": "Provider", 
    "orgName": "Clinic.org" 
    } 
} 
```

#### RESPONSE

```json
200 
User with id <user-id> successfully invited     
```

</details>

* Once Provider receives the invite, they can register and login into the platform using the below code -

<details>

<summary>Provider Registration and Login</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/Register

#### REQUEST HEADER

```json
{ 
         "Authentication": "bearer <Project-Admin-AuthToken>"
}
```

#### REQUEST BODY

```json
{ 
  "email": "[Email of the Provider]", 
  "orgDomain": "clinic", 
  "invitationCode": "[Invitation Code for the Provider]", 
  "password": "[Password of the account]"   
} 
```

#### RESPONSE

```json
200 
<provider-id>      
```

</details>

* Once registration is complete, provider can authorize them using below code -

<details>

<summary>Authorize Provider</summary>

#### GET

<https://api.accelerator-platform.com/\\><project-id>/v1/Authorize?email=\<Email of the the Provider>\&password=\<Password>

#### REQUEST HEADER

```json
{ 
         "Authentication": "bearer <Project-Admin-AuthToken>"
}
```

#### RESPONSE

```json
200 
Access Token     
```

</details>

* Once Provider login into the platform, they can start adding patients data using the below code-

<details>

<summary>Add Patient into Patient's Object</summary>

#### POST

<https://api.accelerator-platform.com/\\><project-id>/v1/AddItems/Patients

#### REQUEST HEADER

```json
{ 
         " Authorization ": "bearer <Patient-AuthToken>"
}
```

#### REQUEST BODY

```json
[ 
    { 
        "name": "[Name of the Patient]",  
        "email": "[Email of the Patient]", 
        "provider": "<provider-item-Id>" 
    } 
] 
```

#### RESPONSE

```json
200 
<n> of <n> items inserted successfully     
```

</details>

* View the list of patient using the below code

<details>

<summary>List of all the patients into Provider's Object</summary>

#### GET

<https://api.accelerator-platform.com/\\><project-id>/v1/GetItems/Patients

#### REQUEST HEADER

```json
{ 
         "Authentication": "bearer <Patient-AuthToken>"
}
```

#### RESPONSE

```json
200 
<list of all Patients>  
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.accelerator-platform.com/start-here/how-to-guides/clinic-project.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
