# Lab Instructions 1

## Prerequisites

1. Checked out Lab Repo from [#github-cs595-lab-repo](https://leap-of-faith-technologies.gitbook.io/cs-595-digital-healthcare-informatics-and-ai/prerequisites#github-cs595-lab-repo "mention")Step
2. Pull the code to get the latest updates for GitHub Repo
3. Python version 3.10 or later
4. A Python virtual environment to link and use for the project
5. Do Git Pull on lab repo to make sure you have the latest updates

## Setup and Verify LOF Services

1. Open \<Project Root>
2. Activate the python virtual environment
3. Go to `lof` folder
4. Edit `.env file`\
   Update client\_id and client\_secret values with the credentials you have received

   ```
   client_id=
   client_secret=
   ```
5. Install Requirements `pip install -r requirements.txt`
6. Run `services.py`
   1. You should see the message : `LoF Services verified successfully`&#x20;

#### Possible Error Messages and resolution:

1. Missing or Incorrect client\_id
   1. `Failed to get LoF auth token: 400 : {"error":"Invalid client ID"}`
   2. `Resolution: Update correct client_id in .env file`&#x20;
2. Missing or Incorrect client\_secret
   1. `Failed to get LoF auth token: 401 : {"error":"Unauthorized: Client authentication failed","status":401}`
   2. `Resolution: Update correct client_secret in .env file`&#x20;

## HIN lab

In this lab we will be&#x20;

1. Retrieve two patients from Health Gorilla&#x20;
   1. Registering them with CCD using CCD patient register API
2. Retrieve patient conditions in HealthGorilla
   1. Populate them to CCD FHIR DB using python FHIRClient SDK

### Setup HIN lab

1. Open \<Project Root>
2. Activate the python virtual environment
3. Go to /labs/hin
4. Install Requirements `pip install -r requirements.txt`
5. Make sure CCD Services are running
6. Login to [CCD UI](http://localhost:4200)

### Instructions

**Note:** Anytime during the exercise if you need to delete patients and rerun the exercise, uncomment the `Delete the patient by MRN block` in main, update the MRN and delete the patient and patient FHIR data

1. Step 1 - Populating Patients
   1. Implement `retrieve_patient_from_hg` function
   2. Implement `transform_hg_to_ccd` function
   3. Uncomment `hg_etl_pipeline.create_patients()` code in the main block and run
   4. On a successful run&#x20;
      1. You should see the below logs

         ```
         1 match found in Health Gorilla for patient Rantdt Hotestead with HG ID: 1b7aca64e07d9a4b8ea0ff22
         Patient registration status code :  201

         1 match found in Health Gorilla for patient Angi Roftec with HG ID: 3e7aca64fa952e7abc670566
         Patient registration status code :  201
         ```
      2. You should the new patients on the CCD UI<br>

         <figure><img src="https://1416543717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsLrPphE1zKqQYozL5Ue3%2Fuploads%2FuGy7HAldx0LOrVv2oSNc%2Fimage.png?alt=media&#x26;token=98b70ca0-70a2-4149-8fdc-e9c6d1a3a316" alt=""><figcaption></figcaption></figure>

         Note: It may take few seconds  for the new patients to become visible. Refresh the page. Wait for sometime. If you don't see the new patients close CCD and re-login&#x20;
      3. Note down the MRN for the patients<br>
2. Step 2 - Update MRN
   1. Comment `hg_etl_pipeline.create_patients()` code in the main block
   2. Open patients.json file
   3. Update the corresponding MRN from Step 1 for each patient<br>
3. Step 3 - Populate Conditions

   1. Implement retrieve\_conditions\_from\_hg
   2. Implement create\_ccd\_condition
   3. Uncomment Step 3 code block in main and run
   4. The program should run successfully and should insert all the patient conditions from HealthGorilla
      1. Adding some conditions may fail due to some mismatch and missing values.
      2. You can ignore that
   5. Validating the patient conditions on FHIR
      1. <http://localhost:8080/fhir/Condition?subject=\\>\<your\_patient\_id>&\_pretty=true
   6. Validating the patient conditions on CCD Facesheet

   <figure><img src="https://1416543717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsLrPphE1zKqQYozL5Ue3%2Fuploads%2FpvwuXlp9ME9jgMa326UZ%2Fimage.png?alt=media&#x26;token=6bee6263-ef2a-4d54-9419-1fe4ec0d4b3d" alt=""><figcaption></figcaption></figure>

### Submission

1. Both Patient JSON files as per step 3.e
2. Both Patient Screenshots as per step 3.f
