[ab5bfb]: / data_explore.ipynb

Download this file

1528 lines (1527 with data), 123.9 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e3355dbf-ff95-485a-adac-1f0caa30331c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from med_terms import LABS, VITALS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "56af6c4a-beec-4c4d-a0f9-cfb42f81ae05",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import glob\n",
    "text_data = glob.glob(\"./data/text/*.txt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "51aa264e-802b-4ccc-aa12-4e3028f25897",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['./data/text/Adan_Kovacek_0b192bcb-a1b7-2920-f6b7-d8bc33884418.txt',\n",
       " './data/text/Adelia_Sherrie_Ferry_08dc1470-064d-8ba3-05f3-cd208e880152.txt',\n",
       " './data/text/Adina_Dorthea_Armstrong_a5043d78-bb20-5a7e-bfc7-9ac23ee42b9e.txt',\n",
       " './data/text/Alaine_Shakia_Jerde_755046a6-c8f6-efef-ea5c-d40afcbdbc6e.txt',\n",
       " './data/text/Alease_Olson_fae63085-40db-c80d-a2f0-ed93f1e95951.txt']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text_data[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "02f86767-3c9a-4001-be21-27a550c24ba4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adan Kovacek\n",
      "============\n",
      "Race:                White\n",
      "Ethnicity:           Non-Hispanic\n",
      "Gender:              M\n",
      "Age:                 28\n",
      "Birth Date:          1994-01-08\n",
      "Marital Status:      M\n",
      "--------------------------------------------------------------------------------\n",
      "ALLERGIES:\n",
      "  1994-10-09 -            : Wheat (substance)\n",
      "--------------------------------------------------------------------------------\n",
      "MEDICATIONS:\n",
      "  1994-10-09[CURRENT] : NDA020800 0.3 ML Epinephrine 1 MG/ML Auto-Injector\n",
      "  1994-10-09[CURRENT] : Loratadine 5 MG Chewable Tablet\n",
      "--------------------------------------------------------------------------------\n",
      "CONDITIONS:\n",
      "  2022-03-19 -            : Not in labor force (finding)\n",
      "  2022-03-19 -            : Anemia (disorder)\n",
      "  2022-03-19 -            : Prediabetes\n",
      "  2019-03-16 - 2022-03-19 : Unhealthy alcohol drinking behavior (finding)\n",
      "  2019-03-16 - 2022-03-19 : Reports of violence in the environment (finding)\n",
      "  2019-03-16 -            : Stress (finding)\n",
      "  2019-03-16 - 2022-03-19 : Part-time employment (finding)\n",
      "  2013-03-09 - 2022-03-19 : Limited social contact (finding)\n",
      "  2013-03-09 -            : Lack of access to transportation (finding)\n",
      "  2012-03-03 - 2013-03-09 : Stress (finding)\n",
      "  2012-03-03 -            : Social isolation (finding)\n",
      "  2012-03-03 -            : Transport problems (finding)\n",
      "  2012-03-03 -            : Received higher education (finding)\n",
      "--------------------------------------------------------------------------------\n",
      "CARE PLANS:\n",
      "  2022-03-19[CURRENT] : Diabetes self management plan\n",
      "                         Reason: Prediabetes\n",
      "                         Activity: Diabetic diet\n",
      "                         Activity: Exercise therapy\n",
      "  1994-09-26[CURRENT] : Self-care interventions (procedure)\n",
      "                         Activity: Food allergy diet\n",
      "                         Activity: Allergy education\n",
      "                         Activity: Allergy education\n",
      "--------------------------------------------------------------------------------\n",
      "REPORTS:\n",
      "  2022-03-19 : Alcohol Use Disorder Identification Test - Consumption [AUDIT-C]\n",
      "           - Total score [AUDIT-C]                    2.0 {score}\n",
      "  2022-03-19 : Patient Health Questionnaire 2 item (PHQ-2) [Reported]\n",
      "           - Patient Health Questionnaire 2 item (PHQ-2) total score [Reported] 2.0 {score}\n",
      "  2022-03-19 : Complete blood count (hemogram) panel - Blood by Automated count\n",
      "           - Hemoglobin [Mass/volume] in Blood        11.6 g/dL\n",
      "           - Hematocrit [Volume Fraction] of Blood    30.9 %\n",
      "           - WBC Auto (Bld) [#/Vol]                   5.2 10*3/uL\n",
      "           - RBC Auto (Bld) [#/Vol]                   4.1 10*6/uL\n",
      "           - MCV [Entitic volume] by Automated count  92.1 fL\n",
      "           - MCH [Entitic mass] by Automated count    30.3 pg\n",
      "           - MCHC [Mass/volume] by Automated count    34.9 g/dL\n",
      "           - RDW - Erythrocyte distribution width Auto (RBC) [Entitic vol] 43.8 fL\n",
      "           - Platelets [#/volume] in Blood by Automated count 288.5 10*3/uL\n",
      "           - Platelet distribution width [Entitic volume] in Blood by Automated count 312.7 fL\n",
      "           - Platelet mean volume [Entitic volume] in Blood by Automated count 11.7 fL\n",
      "  2022-03-19 : Complete blood count (hemogram) panel - Blood by Automated count\n",
      "           - Leukocytes [#/volume] in Blood by Automated count 5.5 10*3/uL\n",
      "           - Erythrocytes [#/volume] in Blood by Automated count 5.4 10*6/uL\n",
      "           - Hemoglobin [Mass/volume] in Blood        14.2 g/dL\n",
      "           - Hematocrit [Volume Fraction] of Blood by Automated count 42.6 %\n",
      "           - MCV [Entitic volume] by Automated count  83.8 fL\n",
      "           - MCH [Entitic mass] by Automated count    32.1 pg\n",
      "           - MCHC [Mass/volume] by Automated count    35.1 g/dL\n",
      "           - Erythrocyte distribution width [Entitic volume] by Automated count 39.2 fL\n",
      "           - Platelets [#/volume] in Blood by Automated count 228.0 10*3/uL\n",
      "           - Platelet distribution width [Entitic volume] in Blood by Automated count 276.8 fL\n",
      "           - Platelet mean volume [Entitic volume] in Blood by Automated count 9.5 fL\n",
      "--------------------------------------------------------------------------------\n",
      "OBSERVATIONS:\n",
      "  2022-03-19 : Total score [AUDIT-C]                    2.0 {score}\n",
      "  2022-03-19 : Patient Health Questionnaire 2 item (PHQ-2) total score [Reported] 2.0 {score}\n",
      "  2022-03-19 : Protocol for Responding to and Assessing Patients' Assets, Risks, and Experiences [PRAPARE]\n",
      "           - In the past year, have you been afraid of your partner or ex-partner? No \n",
      "           - Do you feel physically and emotionally safe where you currently live? Yes \n",
      "           - Are you a refugee?                       No \n",
      "           - In the past year, have you spent more than 2 nights in a row in a jail, prison, detention center, or juvenile correctional facility? No \n",
      "           - Stress is when someone feels tense, nervous, anxious or can't sleep at night because their mind is troubled. How stressed are you? A little bit \n",
      "           - How often do you see or talk to people that you care about and feel close to (For example: talking to friends on the phone, visiting friends or family, going to church or club meetings)? 5 or more times a week \n",
      "           - Has lack of transportation kept you from medical appointments, meetings, work, or from getting things needed for daily living? Yes, it has kept me from medical appointments or from getting my medications \n",
      "           - In the past year, have you or any family members you live with been unable to get any of the following when it was really needed? Childcare \n",
      "           - During the past year, what was the total combined income for you and the family members you live with? This information will help us determine if you are eligible for any benefits. 6610 /a\n",
      "           - What is your main insurance?             Medicaid \n",
      "           - What is your current work situation?     Otherwise unemployed but not seeking work \n",
      "           - What is the highest level of school that you have finished? More than high school \n",
      "           - What address do you live at?             468 Champlin Parade Suite 96 \n",
      "           - Are you worried about losing your housing? No \n",
      "           - What is your housing situation today?    I have housing \n",
      "           - How many family members, including yourself, do you currently live with? 7.0 {#}\n",
      "           - What language are you most comfortable speaking? English \n",
      "           - Have you been discharged from the armed forces of the United States? No \n",
      "           - At any point in the past 2 years, has season or migrant farm work been your or your family's main source of income? No \n",
      "           - Which race(s) are you?                   White \n",
      "           - Are you Hispanic or Latino?              No \n",
      "  2022-03-19 : Platelet mean volume [Entitic volume] in Blood by Automated count 11.7 fL\n",
      "  2022-03-19 : Platelet distribution width [Entitic volume] in Blood by Automated count 312.7 fL\n",
      "  2022-03-19 : Platelets [#/volume] in Blood by Automated count 288.5 10*3/uL\n",
      "  2022-03-19 : RDW - Erythrocyte distribution width Auto (RBC) [Entitic vol] 43.8 fL\n",
      "  2022-03-19 : MCHC [Mass/volume] by Automated count    34.9 g/dL\n",
      "  2022-03-19 : MCH [Entitic mass] by Automated count    30.3 pg\n",
      "  2022-03-19 : MCV [Entitic volume] by Automated count  92.1 fL\n",
      "  2022-03-19 : RBC Auto (Bld) [#/Vol]                   4.1 10*6/uL\n",
      "  2022-03-19 : WBC Auto (Bld) [#/Vol]                   5.2 10*3/uL\n",
      "  2022-03-19 : Hematocrit [Volume Fraction] of Blood    30.9 %\n",
      "  2022-03-19 : Hemoglobin [Mass/volume] in Blood        11.6 g/dL\n",
      "  2022-03-19 : Hemoglobin A1c/Hemoglobin.total in Blood 6.4 %\n",
      "  2022-03-19 : Tobacco smoking status                   Never smoked tobacco (finding) \n",
      "  2022-03-19 : Platelet mean volume [Entitic volume] in Blood by Automated count 9.5 fL\n",
      "  2022-03-19 : Platelet distribution width [Entitic volume] in Blood by Automated count 276.8 fL\n",
      "  2022-03-19 : Platelets [#/volume] in Blood by Automated count 228.0 10*3/uL\n",
      "  2022-03-19 : Erythrocyte distribution width [Entitic volume] by Automated count 39.2 fL\n",
      "  2022-03-19 : MCHC [Mass/volume] by Automated count    35.1 g/dL\n",
      "  2022-03-19 : MCH [Entitic mass] by Automated count    32.1 pg\n",
      "  2022-03-19 : MCV [Entitic volume] by Automated count  83.8 fL\n",
      "  2022-03-19 : Hematocrit [Volume Fraction] of Blood by Automated count 42.6 %\n",
      "  2022-03-19 : Hemoglobin [Mass/volume] in Blood        14.2 g/dL\n",
      "  2022-03-19 : Erythrocytes [#/volume] in Blood by Automated count 5.4 10*6/uL\n",
      "  2022-03-19 : Leukocytes [#/volume] in Blood by Automated count 5.5 10*3/uL\n",
      "  2022-03-19 : Respiratory rate                         15.0 /min\n",
      "  2022-03-19 : Heart rate                               74.0 /min\n",
      "  2022-03-19 : Blood Pressure\n",
      "           - Diastolic Blood Pressure                 80.0 mm[Hg]\n",
      "           - Systolic Blood Pressure                  119.0 mm[Hg]\n",
      "  2022-03-19 : Body Mass Index                          26.8 kg/m2\n",
      "  2022-03-19 : Body Weight                              71.6 kg\n",
      "  2022-03-19 : Pain severity - 0-10 verbal numeric rating [Score] - Reported 4.0 {score}\n",
      "  2022-03-19 : Body Height                              163.3 cm\n",
      "--------------------------------------------------------------------------------\n",
      "PROCEDURES:\n",
      "  2022-03-19 : Brief general examination (procedure)\n",
      "  2022-03-19 : Medication Reconciliation (procedure)\n",
      "  2022-03-19 : Review of systems (procedure)\n",
      "  2022-03-19 : Assessment using Alcohol Use Disorders Identification Test - Consumption (procedure)\n",
      "  2022-03-19 : Assessment of substance use (procedure)\n",
      "  2022-03-19 : Depression screening using Patient Health Questionnaire Two-Item score (procedure)\n",
      "  2022-03-19 : Depression screening (procedure)\n",
      "  2022-03-19 : Peripheral blood smear interpretation\n",
      "  2022-03-19 : Assessment of health and social care needs (procedure)\n",
      "--------------------------------------------------------------------------------\n",
      "IMMUNIZATIONS:\n",
      "  2022-03-19 : Influenza, seasonal, injectable, preservative free\n",
      "  2021-08-28 : SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose\n",
      "  2021-08-07 : SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose\n",
      "--------------------------------------------------------------------------------\n",
      "ENCOUNTERS:\n",
      "2022-03-19 (Dr. Chu Weber) : Encounter at STURDY MEMORIAL HOSPITAL INC : Encounter for Anemia (disorder)\n",
      "2022-03-19 (Dr. Wynell Mayert) : Encounter at WELLNESS ON WHEELS,PC\n",
      "2021-08-28 (Dr. Chu Weber) : Encounter at STURDY MEMORIAL HOSPITAL INC\n",
      "2021-08-07 (Dr. Chu Weber) : Encounter at STURDY MEMORIAL HOSPITAL INC\n",
      "2019-03-16 (Dr. Wynell Mayert) : Encounter at WELLNESS ON WHEELS,PC\n",
      "2013-03-09 (Dr. Wynell Mayert) : Encounter at WELLNESS ON WHEELS,PC\n",
      "2012-03-03 (Dr. Wynell Mayert) : Encounter at WELLNESS ON WHEELS,PC\n",
      "1994-10-09 (Dr. Chu Weber) : Encounter at STURDY MEMORIAL HOSPITAL INC\n",
      "1994-09-26 (Dr. Chu Weber) : Encounter at STURDY MEMORIAL HOSPITAL INC\n",
      "--------------------------------------------------------------------------------\n",
      "IMAGING STUDIES:\n",
      "--------------------------------------------------------------------------------\n",
      "\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    txt = open(text_data[0], encoding = 'utf-8')\n",
    "    t = txt.read()\n",
    "    print(t)\n",
    "finally:\n",
    "    txt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "16195f06-69a1-4839-b626-8d9c3ae1f4a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "def isnumber(num):\n",
    "    try:\n",
    "        float(num)\n",
    "        return True\n",
    "    except ValueError:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d5af7b20-5fbe-451e-ba0b-2ff63ba2f633",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'to': 'Tree nut', 'type': 'substance'}, {'to': 'Tree pollen', 'type': 'substance'}, {'to': 'Grass pollen', 'type': 'substance'}, {'to': 'Animal dander', 'type': 'substance'}, {'to': 'House dust mite', 'type': 'organism'}, {'to': 'Mold', 'type': 'organism'}, {'to': 'Latex', 'type': 'substance'}]\n"
     ]
    }
   ],
   "source": [
    "# allergy = ['ALLERGIES:', '  1994-10-09 -            : Wheat (substance)']\n",
    "# allergy = ['ALLERGIES:', 'No Known Allergies']\n",
    "allergy = ['ALLERGIES:', '  1973-01-20 -            : Tree nut (substance)', '  1973-01-20 -            : Tree pollen (substance)', '  1973-01-20 -            : Grass pollen (substance)', '  1973-01-20 -            : Animal dander (substance)', '  1973-01-20 -            : House dust mite (organism)', '  1973-01-20 -            : Mold (organism)', '  1973-01-20 -            : Latex (substance)']\n",
    "def get_allergies(raw_allergies):\n",
    "    if raw_allergies[1] == 'No Known Allergies':\n",
    "        return None\n",
    "    allergies = []\n",
    "    for allergy in raw_allergies[1:]:\n",
    "        A = allergy.split(\": \")[1].strip().split(\" (\")\n",
    "        try:\n",
    "            allergies.append({\"to\": A[0], \"type\": A[1][:-1]})\n",
    "        except Exception:\n",
    "            allergies.append({\"to\": A[0], \"type\": 'medicine'})\n",
    "    return allergies\n",
    "\n",
    "print(get_allergies(allergy))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ac8232ce-18b7-49f7-8d1b-79c92fb2d655",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_name(filepath):\n",
    "    try:\n",
    "        txt = open(filepath, encoding = 'utf-8')\n",
    "        return txt.readlines()[0].strip()\n",
    "    finally:\n",
    "        txt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a28edd88-701f-47a9-8af0-18c9e7051a7e",
   "metadata": {},
   "outputs": [],
   "source": [
    "medications = ['MEDICATIONS:', '  2022-09-15[CURRENT] : Simvastatin 10 MG Oral Tablet for Hyperlipidemia', '  2022-09-06[CURRENT] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2021-09-15[STOPPED] : Simvastatin 10 MG Oral Tablet for Hyperlipidemia', '  2021-08-31[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2020-12-29[STOPPED] : Acetaminophen 325 MG / HYDROcodone Bitartrate 7.5 MG Oral Tablet', '  2020-12-21[STOPPED] : Acetaminophen 325 MG Oral Tablet', '  2020-09-15[STOPPED] : Simvastatin 10 MG Oral Tablet for Hyperlipidemia', '  2020-08-25[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2019-08-20[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2018-08-14[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2017-08-08[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2016-08-02[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2015-07-28[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2014-07-22[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2013-07-16[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2012-07-10[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2011-07-05[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2010-06-29[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2009-06-23[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2008-06-17[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2007-06-12[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2006-06-06[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2005-05-31[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2004-05-25[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2004-02-17[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2003-05-20[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2002-05-14[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2001-05-08[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2000-05-02[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2000-05-02[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  2000-05-02[STOPPED] : amLODIPine 2.5 MG Oral Tablet for Hypertension', '  1976-10-13[CURRENT] : Chlorpheniramine Maleate 2 MG/ML Oral Solution']\n",
    "def get_medications(raw_medications):\n",
    "    medications = []\n",
    "    for medication in raw_medications[1:]:\n",
    "        if '[CURRENT]' in medication:\n",
    "            M = medication.split(\" : \")\n",
    "            medications.append({'medicine': M[1], 'from': M[0][2:12]})\n",
    "    return medications"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ce3576fe-1fa5-46ea-8f92-27b05e295baf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'condition': 'Viral sinusitis (disorder)',\n",
       "  'from': '2021-09-25',\n",
       "  'to': '2021-10-02'},\n",
       " {'condition': 'Hypertension', 'from': '2008-04-05', 'to': ''},\n",
       " {'condition': 'History of appendectomy', 'from': '1994-12-15', 'to': ''},\n",
       " {'condition': 'Appendicitis', 'from': '1994-12-15', 'to': ''}]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conditions = ['CONDITIONS:', '  2022-06-25 -            : Full-time employment (finding)', '  2021-09-25 - 2022-06-25 : Full-time employment (finding)', '  2021-09-25 -            : Body mass index 30+ - obesity (finding)', '  2021-09-25 - 2021-10-02 : Viral sinusitis (disorder)', '  2021-06-19 - 2021-09-25 : Full-time employment (finding)', '  2020-06-13 - 2021-06-19 : Stress (finding)', '  2020-06-13 - 2021-06-19 : Full-time employment (finding)', '  2019-06-08 - 2020-06-13 : Full-time employment (finding)', '  2018-07-28 - 2019-06-08 : Full-time employment (finding)', '  2018-06-02 - 2022-06-25 : Social isolation (finding)', '  2018-06-02 - 2018-07-28 : Full-time employment (finding)', '  2015-05-16 - 2016-05-21 : Full-time employment (finding)', '  2014-05-10 - 2015-05-16 : Full-time employment (finding)', '  2013-05-04 - 2014-05-10 : Full-time employment (finding)', '  2012-04-28 - 2013-05-04 : Full-time employment (finding)', '  2011-04-23 - 2012-04-28 : Full-time employment (finding)', '  2010-06-26 - 2011-04-23 : Full-time employment (finding)', '  2010-04-17 - 2010-06-26 : Full-time employment (finding)', '  2009-04-11 - 2010-04-17 : Full-time employment (finding)', '  2008-04-05 - 2009-04-11 : Full-time employment (finding)', '  2008-04-05 -            : Received certificate of high school equivalency (finding)', '  2008-04-05 -            : Hypertension', '  1994-12-15 -            : History of appendectomy', '  1994-12-15 -            : Appendicitis']\n",
    "def get_conditions(raw_conditions):\n",
    "    conditions = []\n",
    "    for condition in raw_conditions[1:]:\n",
    "        if not '(finding)' in condition:\n",
    "            C = condition.split(\" : \")\n",
    "            condition = C[1]\n",
    "            date = C[0].split(\" - \")\n",
    "            conditions.append(\n",
    "                {'condition': condition, 'from': date[0].strip(), 'to': date[1].strip()}\n",
    "            )\n",
    "    return conditions\n",
    "get_conditions(conditions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "44edfa6e-eb93-4ece-81a3-1777042b3c17",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'careplan': 'Routine antenatal care',\n",
       "  'date': '2014-06-19',\n",
       "  'activities': ['Antenatal education',\n",
       "   'Antenatal risk assessment',\n",
       "   'Antenatal blood tests'],\n",
       "  'status': '[CURRENT]'},\n",
       " {'careplan': 'Diabetes self management plan',\n",
       "  'date': '2006-04-27',\n",
       "  'activities': ['Diabetic diet', 'Exercise therapy'],\n",
       "  'status': '[CURRENT]',\n",
       "  'reason': 'Prediabetes'},\n",
       " {'careplan': 'Routine antenatal care',\n",
       "  'date': '2006-04-27',\n",
       "  'activities': ['Antenatal education',\n",
       "   'Antenatal risk assessment',\n",
       "   'Antenatal blood tests'],\n",
       "  'status': '[STOPPED]'},\n",
       " {'careplan': 'Lifestyle education regarding hypertension',\n",
       "  'date': '2001-03-29',\n",
       "  'activities': ['Prescribed activity/exercise education',\n",
       "   'Counseling about alcohol consumption',\n",
       "   'Dietary approaches to stop hypertension diet',\n",
       "   'Smoking cessation education'],\n",
       "  'status': '[CURRENT]',\n",
       "  'reason': 'Hypertension'},\n",
       " {'careplan': 'Routine antenatal care',\n",
       "  'date': '1998-03-12',\n",
       "  'activities': ['Antenatal education',\n",
       "   'Antenatal risk assessment',\n",
       "   'Antenatal blood tests'],\n",
       "  'status': '[STOPPED]'},\n",
       " {'careplan': 'Routine antenatal care',\n",
       "  'date': '1994-01-06',\n",
       "  'activities': ['Antenatal education',\n",
       "   'Antenatal risk assessment',\n",
       "   'Antenatal blood tests'],\n",
       "  'status': '[STOPPED]'},\n",
       " {'careplan': 'Routine antenatal care',\n",
       "  'date': '1990-06-07',\n",
       "  'activities': ['Antenatal education',\n",
       "   'Antenatal risk assessment',\n",
       "   'Antenatal blood tests'],\n",
       "  'status': '[STOPPED]'},\n",
       " {'careplan': 'Routine antenatal care',\n",
       "  'date': '1988-03-10',\n",
       "  'activities': ['Antenatal education',\n",
       "   'Antenatal risk assessment',\n",
       "   'Antenatal blood tests'],\n",
       "  'status': '[STOPPED]'},\n",
       " {'careplan': 'Routine antenatal care',\n",
       "  'date': '1984-05-10',\n",
       "  'activities': ['Antenatal education',\n",
       "   'Antenatal risk assessment',\n",
       "   'Antenatal blood tests'],\n",
       "  'status': '[STOPPED]'}]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# care_plan = ['CARE PLANS:', '  2020-12-21[STOPPED] : Physiotherapy care plan (record artifact)', '                         Reason: Injury of anterior cruciate ligament', '                         Activity: Rest, ice, compression and elevation treatment programme', '                         Activity: Stretching exercises', '  2020-09-15[CURRENT] : Hyperlipidemia clinical management plan', '                         Reason: Hyperlipidemia', '                         Activity: low salt diet education', '                         Activity: physical exercise', '  2000-05-02[CURRENT] : Lifestyle education regarding hypertension', '                         Reason: Hypertension', '                         Activity: Prescribed activity/exercise education', '                         Activity: Counseling about alcohol consumption', '                         Activity: Dietary approaches to stop hypertension diet', '                         Activity: Smoking cessation education', '  1994-04-26[CURRENT] : Diabetes self management plan', '                         Reason: Prediabetes', '                         Activity: Diabetic diet', '                         Activity: Exercise therapy', '  1973-01-07[CURRENT] : Self-care interventions (procedure)', '                         Activity: Food allergy diet', '                         Activity: Allergy education', '                         Activity: Allergy education']\n",
    "care_plan = ['CARE PLANS:', '  2014-06-19[CURRENT] : Routine antenatal care', '                         Activity: Antenatal education', '                         Activity: Antenatal risk assessment', '                         Activity: Antenatal blood tests', '  2006-04-27[CURRENT] : Diabetes self management plan', '                         Reason: Prediabetes', '                         Activity: Diabetic diet', '                         Activity: Exercise therapy', '  2006-04-27[STOPPED] : Routine antenatal care', '                         Activity: Antenatal education', '                         Activity: Antenatal risk assessment', '                         Activity: Antenatal blood tests', '  2001-03-29[CURRENT] : Lifestyle education regarding hypertension', '                         Reason: Hypertension', '                         Activity: Prescribed activity/exercise education', '                         Activity: Counseling about alcohol consumption', '                         Activity: Dietary approaches to stop hypertension diet', '                         Activity: Smoking cessation education', '  1998-03-12[STOPPED] : Routine antenatal care', '                         Activity: Antenatal education', '                         Activity: Antenatal risk assessment', '                         Activity: Antenatal blood tests', '  1994-01-06[STOPPED] : Routine antenatal care', '                         Activity: Antenatal education', '                         Activity: Antenatal risk assessment', '                         Activity: Antenatal blood tests', '  1990-06-07[STOPPED] : Routine antenatal care', '                         Activity: Antenatal education', '                         Activity: Antenatal risk assessment', '                         Activity: Antenatal blood tests', '  1988-03-10[STOPPED] : Routine antenatal care', '                         Activity: Antenatal education', '                         Activity: Antenatal risk assessment', '                         Activity: Antenatal blood tests', '  1984-05-10[STOPPED] : Routine antenatal care', '                         Activity: Antenatal education', '                         Activity: Antenatal risk assessment', '                         Activity: Antenatal blood tests']\n",
    "def get_care_plans(raw_care_plans):\n",
    "    care_plans = []\n",
    "    for care_plan in raw_care_plans[1:]:\n",
    "        care_plan = care_plan.strip()\n",
    "        if '[CURRENT]' in care_plan or '[STOPPED]' in care_plan:\n",
    "            care_plans.append({'careplan': care_plan.split(\" : \")[1], 'date': care_plan.split(\" : \")[0][:10], 'activities':[], 'status': care_plan.split(\" : \")[0][10:]})\n",
    "        elif care_plan.strip().startswith(\"Reason: \"):\n",
    "            care_plans[-1]['reason'] = care_plan.replace(\"Reason: \", '')\n",
    "        elif care_plan.strip().startswith(\"Activity: \"):\n",
    "            care_plans[-1]['activities'].append(care_plan.replace(\"Activity: \", ''))\n",
    "    return care_plans\n",
    "\n",
    "get_care_plans(care_plan)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bf4f787c-6f04-4824-ac50-cde214fb6cc6",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'description': 'Glucose', 'units': 'mg/dL', 'value': '2.4'},\n",
       " {'description': 'Glucose [Mass/volume] in Urine by Test strip',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '2.4'},\n",
       " {'description': 'Bilirubin.total [Mass/volume] in Urine by Test strip',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '1.3'},\n",
       " {'description': 'Ketones [Mass/volume] in Urine by Test strip',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '19.7'},\n",
       " {'description': 'Specific gravity of Urine by Test strip',\n",
       "  'units': '{nominal}',\n",
       "  'value': '1.0'},\n",
       " {'description': 'Protein [Mass/volume] in Urine by Test strip',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '285.6'},\n",
       " {'description': 'Urea Nitrogen', 'units': 'mg/dL', 'value': '15.3'},\n",
       " {'description': 'Creatinine', 'units': 'mg/dL', 'value': '2.0'},\n",
       " {'description': 'Calcium', 'units': 'mg/dL', 'value': '9.0'},\n",
       " {'description': 'Sodium', 'units': 'mmol/L', 'value': '137.6'},\n",
       " {'description': 'Potassium', 'units': 'mmol/L', 'value': '4.5'},\n",
       " {'description': 'Chloride', 'units': 'mmol/L', 'value': '104.2'},\n",
       " {'description': 'Carbon Dioxide', 'units': 'mmol/L', 'value': '28.6'},\n",
       " {'description': 'Glomerular filtration rate/1.73 sq M.predicted',\n",
       "  'units': 'mL/min',\n",
       "  'value': '80.5'},\n",
       " {'description': 'Total Cholesterol', 'units': 'mg/dL', 'value': '104.9'},\n",
       " {'description': 'Triglycerides', 'units': 'mg/dL', 'value': '138.0'},\n",
       " {'description': 'Low Density Lipoprotein Cholesterol',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '25.5'},\n",
       " {'description': 'High Density Lipoprotein Cholesterol',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '51.9'},\n",
       " {'description': 'Glucose [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '77.4'},\n",
       " {'description': 'Urea nitrogen [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '10.1'},\n",
       " {'description': 'Creatinine [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '2.6'},\n",
       " {'description': 'Calcium [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '9.4'},\n",
       " {'description': 'Sodium [Moles/volume] in Serum or Plasma',\n",
       "  'units': 'mmol/L',\n",
       "  'value': '141.5'},\n",
       " {'description': 'Potassium [Moles/volume] in Serum or Plasma',\n",
       "  'units': 'mmol/L',\n",
       "  'value': '3.9'},\n",
       " {'description': 'Chloride [Moles/volume] in Serum or Plasma',\n",
       "  'units': 'mmol/L',\n",
       "  'value': '108.7'},\n",
       " {'description': 'Protein [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'g/dL',\n",
       "  'value': '6.5'},\n",
       " {'description': 'Albumin [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'g/dL',\n",
       "  'value': '4.4'},\n",
       " {'description': 'Bilirubin.total [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'mg/dL',\n",
       "  'value': '6.3'},\n",
       " {'description': 'Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma',\n",
       "  'units': 'U/L',\n",
       "  'value': '81.1'},\n",
       " {'description': 'Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma',\n",
       "  'units': 'U/L',\n",
       "  'value': '21.2'},\n",
       " {'description': 'Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma',\n",
       "  'units': 'U/L',\n",
       "  'value': '0.4'},\n",
       " {'description': 'Neutrophils/100 leukocytes in Blood by Automated count',\n",
       "  'units': '%',\n",
       "  'value': '43.5'},\n",
       " {'description': 'Lymphocytes/100 leukocytes in Blood by Automated count',\n",
       "  'units': '%',\n",
       "  'value': '10.5'},\n",
       " {'description': 'Monocytes/100 leukocytes in Blood by Automated count',\n",
       "  'units': '%',\n",
       "  'value': '5.7'},\n",
       " {'description': 'Eosinophils/100 leukocytes in Blood by Automated count',\n",
       "  'units': '%',\n",
       "  'value': '3.9'},\n",
       " {'description': 'Basophils/100 leukocytes in Blood by Automated count',\n",
       "  'units': '%',\n",
       "  'value': '3.9'},\n",
       " {'description': 'Neutrophils [#/volume] in Blood by Automated count',\n",
       "  'units': '10*3/uL',\n",
       "  'value': '2.6'},\n",
       " {'description': 'Lymphocytes [#/volume] in Blood by Automated count',\n",
       "  'units': '10*3/uL',\n",
       "  'value': '1.0'},\n",
       " {'description': 'Monocytes [#/volume] in Blood by Automated count',\n",
       "  'units': '10*3/uL',\n",
       "  'value': '1.0'},\n",
       " {'description': 'Eosinophils [#/volume] in Blood by Automated count',\n",
       "  'units': '10*3/uL',\n",
       "  'value': '0.5'},\n",
       " {'description': 'Basophils [#/volume] in Blood by Automated count',\n",
       "  'units': '10*3/uL',\n",
       "  'value': '0.2'},\n",
       " {'description': 'Leukocytes [#/volume] in Blood by Automated count',\n",
       "  'units': '10*3/uL',\n",
       "  'value': '3.3'},\n",
       " {'description': 'Erythrocytes [#/volume] in Blood by Automated count',\n",
       "  'units': '10*6/uL',\n",
       "  'value': '5.0'},\n",
       " {'description': 'Hemoglobin [Mass/volume] in Blood',\n",
       "  'units': 'g/dL',\n",
       "  'value': '11.1'},\n",
       " {'description': 'Hematocrit [Volume Fraction] of Blood by Automated count',\n",
       "  'units': '%',\n",
       "  'value': '38.6'},\n",
       " {'description': 'Hematocrit [Volume Fraction] of Blood',\n",
       "  'units': '%',\n",
       "  'value': '38.6'},\n",
       " {'description': 'MCV [Entitic volume] by Automated count',\n",
       "  'units': 'fL',\n",
       "  'value': '85.1'},\n",
       " {'description': 'MCH [Entitic mass] by Automated count',\n",
       "  'units': 'pg',\n",
       "  'value': '30.8'},\n",
       " {'description': 'MCHC [Mass/volume] by Automated count',\n",
       "  'units': 'g/dL',\n",
       "  'value': '31.8'},\n",
       " {'description': 'Erythrocyte distribution width [Ratio] by Automated count',\n",
       "  'units': '%',\n",
       "  'value': '14.5'},\n",
       " {'description': 'Platelets [#/volume] in Blood by Automated count',\n",
       "  'units': '10*3/uL',\n",
       "  'value': '104.6'},\n",
       " {'description': 'Prothrombin time (PT)', 'units': 's', 'value': '11.0'},\n",
       " {'description': 'INR in Platelet poor plasma by Coagulation assay',\n",
       "  'units': '{INR}',\n",
       "  'value': '2.8'},\n",
       " {'description': 'Troponin I.cardiac [Mass/volume] in Serum or Plasma by High sensitivity method',\n",
       "  'units': 'pg/mL',\n",
       "  'value': '2.9'},\n",
       " {'description': 'Ferritin [Mass/volume] in Serum or Plasma',\n",
       "  'units': 'ug/L',\n",
       "  'value': '463.4'}]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vital = ['REPORTS:', '  2022-06-10 : Drug Abuse Screening Test-10 [DAST-10]', '           - Total score [DAST-10]                    1.0 {score}', '  2022-06-10 : Patient Health Questionnaire 2 item (PHQ-2) [Reported]', '           - Patient Health Questionnaire 2 item (PHQ-2) total score [Reported] 2.0 {score}', '  2022-06-10 : Generalized anxiety disorder 7 item (GAD-7)', '           - Generalized anxiety disorder 7 item (GAD-7) total score [Reported.PHQ] 3.0 {score}', '  2022-06-10 : Urinalysis macro (dipstick) panel - Urine', '           - Appearance of Urine                      Cloudy urine (finding) {nominal}', '           - Odor of Urine                            Urine smell ammoniacal (finding) {nominal}', '           - Clarity of Urine                         Translucent (qualifier value) {nominal}', '           - Color of Urine                           Brown color (qualifier value) {nominal}', '           - Glucose [Mass/volume] in Urine by Test strip 2.4 mg/dL', '           - Glucose [Presence] in Urine by Test strip Urine glucose test = ++ (finding) {nominal}', '           - Bilirubin.total [Mass/volume] in Urine by Test strip 1.3 mg/dL', '           - Bilirubin.total [Presence] in Urine by Test strip Finding of bilirubin in urine (finding) {nominal}', '           - Ketones [Mass/volume] in Urine by Test strip 19.7 mg/dL', '           - Ketones [Presence] in Urine by Test strip Urine ketone test = + (finding) {nominal}', '           - Specific gravity of Urine by Test strip  1.0 {nominal}', '           - pH of Urine by Test strip                5.0 pH', '           - Protein [Mass/volume] in Urine by Test strip 285.6 mg/dL', '           - Protein [Presence] in Urine by Test strip Urine protein test = ++ (finding) {nominal}', '           - Nitrite [Presence] in Urine by Test strip Urine nitrite negative (finding) {nominal}', '           - Hemoglobin [Presence] in Urine by Test strip Urine blood test = negative (finding) {nominal}', '           - Leukocyte esterase [Presence] in Urine by Test strip Urine leukocyte test negative (finding) {nominal}', '  2022-06-10 : Basic Metabolic 2000 Panel', '           - Glucose                                  69.5 mg/dL', '           - Urea Nitrogen                            15.3 mg/dL', '           - Creatinine                               2.0 mg/dL', '           - Calcium                                  9.0 mg/dL', '           - Sodium                                   137.6 mmol/L', '           - Potassium                                4.5 mmol/L', '           - Chloride                                 104.2 mmol/L', '           - Carbon Dioxide                           28.6 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 80.5 mL/min', '  2022-05-06 : Patient Health Questionnaire 2 item (PHQ-2) [Reported]', '           - Patient Health Questionnaire 2 item (PHQ-2) total score [Reported] 1.0 {score}', '  2022-05-06 : Generalized anxiety disorder 7 item (GAD-7)', '           - Generalized anxiety disorder 7 item (GAD-7) total score [Reported.PHQ] 0.0 {score}', '  2022-05-06 : Urinalysis macro (dipstick) panel - Urine', '           - Appearance of Urine                      Cloudy urine (finding) {nominal}', '           - Odor of Urine                            Urine smell ammoniacal (finding) {nominal}', '           - Clarity of Urine                         Translucent (qualifier value) {nominal}', '           - Color of Urine                           Brown color (qualifier value) {nominal}', '           - Glucose [Mass/volume] in Urine by Test strip 2.3 mg/dL', '           - Glucose [Presence] in Urine by Test strip Urine glucose test = ++ (finding) {nominal}', '           - Bilirubin.total [Mass/volume] in Urine by Test strip 0.4 mg/dL', '           - Bilirubin.total [Presence] in Urine by Test strip Finding of bilirubin in urine (finding) {nominal}', '           - Ketones [Mass/volume] in Urine by Test strip 7.7 mg/dL', '           - Ketones [Presence] in Urine by Test strip Urine ketone test = + (finding) {nominal}', '           - Specific gravity of Urine by Test strip  1.0 {nominal}', '           - pH of Urine by Test strip                5.8 pH', '           - Protein [Mass/volume] in Urine by Test strip 342.9 mg/dL', '           - Protein [Presence] in Urine by Test strip Urine protein test = ++ (finding) {nominal}', '           - Nitrite [Presence] in Urine by Test strip Urine nitrite negative (finding) {nominal}', '           - Hemoglobin [Presence] in Urine by Test strip Urine blood test = negative (finding) {nominal}', '           - Leukocyte esterase [Presence] in Urine by Test strip Urine leukocyte test negative (finding) {nominal}', '  2022-05-06 : Basic Metabolic 2000 Panel', '           - Glucose                                  81.9 mg/dL', '           - Urea Nitrogen                            19.1 mg/dL', '           - Creatinine                               1.9 mg/dL', '           - Calcium                                  9.2 mg/dL', '           - Sodium                                   138.6 mmol/L', '           - Potassium                                5.1 mmol/L', '           - Chloride                                 108.4 mmol/L', '           - Carbon Dioxide                           28.5 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 83.5 mL/min', '  2022-05-06 : Lipid Panel', '           - Total Cholesterol                        104.9 mg/dL', '           - Triglycerides                            138.0 mg/dL', '           - Low Density Lipoprotein Cholesterol      25.5 mg/dL', '           - High Density Lipoprotein Cholesterol     51.9 mg/dL', '  2022-03-11 : Alcohol Use Disorder Identification Test - Consumption [AUDIT-C]', '           - Total score [AUDIT-C]                    11.0 {score}', '  2022-03-11 : Patient Health Questionnaire 2 item (PHQ-2) [Reported]', '           - Patient Health Questionnaire 2 item (PHQ-2) total score [Reported] 1.0 {score}', '  2022-03-11 : Generalized anxiety disorder 7 item (GAD-7)', '           - Generalized anxiety disorder 7 item (GAD-7) total score [Reported.PHQ] 8.0 {score}', '  2022-03-11 : Urinalysis macro (dipstick) panel - Urine', '           - Appearance of Urine                      Cloudy urine (finding) {nominal}', '           - Odor of Urine                            Urine smell ammoniacal (finding) {nominal}', '           - Clarity of Urine                         Translucent (qualifier value) {nominal}', '           - Color of Urine                           Brown color (qualifier value) {nominal}', '           - Glucose [Mass/volume] in Urine by Test strip 2.0 mg/dL', '           - Glucose [Presence] in Urine by Test strip Urine glucose test = ++ (finding) {nominal}', '           - Bilirubin.total [Mass/volume] in Urine by Test strip 0.5 mg/dL', '           - Bilirubin.total [Presence] in Urine by Test strip Finding of bilirubin in urine (finding) {nominal}', '           - Ketones [Mass/volume] in Urine by Test strip 4.9 mg/dL', '           - Ketones [Presence] in Urine by Test strip Urine ketone test = + (finding) {nominal}', '           - Specific gravity of Urine by Test strip  1.0 {nominal}', '           - pH of Urine by Test strip                6.4 pH', '           - Protein [Mass/volume] in Urine by Test strip 183.2 mg/dL', '           - Protein [Presence] in Urine by Test strip Urine protein test = ++ (finding) {nominal}', '           - Nitrite [Presence] in Urine by Test strip Urine nitrite negative (finding) {nominal}', '           - Hemoglobin [Presence] in Urine by Test strip Urine blood test = negative (finding) {nominal}', '           - Leukocyte esterase [Presence] in Urine by Test strip Urine leukocyte test negative (finding) {nominal}', '  2022-03-11 : Basic Metabolic 2000 Panel', '           - Glucose                                  86.5 mg/dL', '           - Urea Nitrogen                            11.4 mg/dL', '           - Creatinine                               2.0 mg/dL', '           - Calcium                                  8.8 mg/dL', '           - Sodium                                   136.2 mmol/L', '           - Potassium                                4.7 mmol/L', '           - Chloride                                 108.6 mmol/L', '           - Carbon Dioxide                           21.1 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 70.0 mL/min', '  2021-04-30 : Drug Abuse Screening Test-10 [DAST-10]', '           - Total score [DAST-10]                    0.0 {score}', '  2021-04-30 : Generalized anxiety disorder 7 item (GAD-7)', '           - Generalized anxiety disorder 7 item (GAD-7) total score [Reported.PHQ] 1.0 {score}', '  2021-04-30 : Urinalysis macro (dipstick) panel - Urine', '           - Appearance of Urine                      Cloudy urine (finding) {nominal}', '           - Odor of Urine                            Urine smell ammoniacal (finding) {nominal}', '           - Clarity of Urine                         Translucent (qualifier value) {nominal}', '           - Color of Urine                           Brown color (qualifier value) {nominal}', '           - Glucose [Mass/volume] in Urine by Test strip 1.9 mg/dL', '           - Glucose [Presence] in Urine by Test strip Urine glucose test = ++ (finding) {nominal}', '           - Bilirubin.total [Mass/volume] in Urine by Test strip 0.3 mg/dL', '           - Bilirubin.total [Presence] in Urine by Test strip Finding of bilirubin in urine (finding) {nominal}', '           - Ketones [Mass/volume] in Urine by Test strip 14.4 mg/dL', '           - Ketones [Presence] in Urine by Test strip Urine ketone test = trace (finding) {nominal}', '           - Specific gravity of Urine by Test strip  1.0 {nominal}', '           - pH of Urine by Test strip                7.0 pH', '           - Protein [Mass/volume] in Urine by Test strip 89.1 mg/dL', '           - Protein [Presence] in Urine by Test strip Urine protein test = + (finding) {nominal}', '           - Nitrite [Presence] in Urine by Test strip Urine nitrite negative (finding) {nominal}', '           - Hemoglobin [Presence] in Urine by Test strip Urine blood test = negative (finding) {nominal}', '           - Leukocyte esterase [Presence] in Urine by Test strip Urine leukocyte test negative (finding) {nominal}', '  2021-04-30 : Basic Metabolic 2000 Panel', '           - Glucose                                  64.7 mg/dL', '           - Urea Nitrogen                            14.3 mg/dL', '           - Creatinine                               1.8 mg/dL', '           - Calcium                                  9.7 mg/dL', '           - Sodium                                   136.0 mmol/L', '           - Potassium                                4.9 mmol/L', '           - Chloride                                 108.8 mmol/L', '           - Carbon Dioxide                           26.5 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 112.3 mL/min', '  2020-12-26 : SARS-CoV-2 RNA Pnl Resp NAA+probe', '           - SARS-CoV-2 RNA Pnl Resp NAA+probe        Not detected (qualifier value) ', '  2020-12-25 : SARS-CoV-2 RNA Pnl Resp NAA+probe', '           - SARS-CoV-2 RNA Pnl Resp NAA+probe        Not detected (qualifier value) ', '  2020-12-25 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.4 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 10.1 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.6 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 9.4 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.5 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 3.9 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 108.7 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 27.1 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 12.3 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 6.5 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 4.4 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 6.3 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 81.1 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 21.2 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 0.4 U/L', '  2020-12-25 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 43.5 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 10.5 %', '           - Monocytes/100 leukocytes in Blood by Automated count 5.7 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 3.9 %', '           - Basophils/100 leukocytes in Blood by Automated count 3.9 %', '           - Neutrophils [#/volume] in Blood by Automated count 2.6 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 1.0 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 1.0 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.5 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.2 10*3/uL', '  2020-12-25 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.3 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 5.0 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        11.1 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 38.6 %', '           - MCV [Entitic volume] by Automated count  85.1 fL', '           - MCH [Entitic mass] by Automated count    30.8 pg', '           - MCHC [Mass/volume] by Automated count    31.8 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 14.5 %', '           - Platelets [#/volume] in Blood by Automated count 104.6 10*3/uL', '  2020-12-24 : PT panel - Platelet poor plasma by Coagulation assay', '           - Prothrombin time (PT)                    11.0 s', '           - INR in Platelet poor plasma by Coagulation assay 2.8 {INR}', '  2020-12-24 : Troponin I.cardiac panel - Serum or Plasma by High sensitivity method', '           - Troponin I.cardiac [Mass/volume] in Serum or Plasma by High sensitivity method 2.9 pg/mL', '  2020-12-24 : Iron panel - Serum or Plasma', '           - Ferritin [Mass/volume] in Serum or Plasma 463.4 ug/L', '  2020-12-24 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.0 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 8.0 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.7 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.6 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.0 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.6 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.6 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 22.7 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 7.9 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 6.2 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 4.8 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 14.4 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 93.0 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 13.4 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 27.4 U/L', '  2020-12-24 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 27.7 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 10.7 %', '           - Monocytes/100 leukocytes in Blood by Automated count 7.3 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 5.2 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.7 %', '           - Neutrophils [#/volume] in Blood by Automated count 2.8 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 0.9 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 1.3 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.2 10*3/uL', '  2020-12-24 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.9 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 4.6 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        11.4 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 44.1 %', '           - MCV [Entitic volume] by Automated count  83.4 fL', '           - MCH [Entitic mass] by Automated count    27.4 pg', '           - MCHC [Mass/volume] by Automated count    34.3 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 14.3 %', '           - Platelets [#/volume] in Blood by Automated count 118.5 10*3/uL', '  2020-12-23 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.0 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 8.0 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.6 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.6 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.0 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.6 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.6 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 22.7 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 12.5 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 7.4 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 4.8 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 12.9 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 95.9 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 0.2 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 36.0 U/L', '  2020-12-23 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 31.4 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 13.8 %', '           - Monocytes/100 leukocytes in Blood by Automated count 10.3 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 4.4 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.2 %', '           - Neutrophils [#/volume] in Blood by Automated count 3.6 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 0.9 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 1.3 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.4 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '  2020-12-23 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.2 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 5.6 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        11.4 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 45.2 %', '           - MCV [Entitic volume] by Automated count  89.8 fL', '           - MCH [Entitic mass] by Automated count    31.5 pg', '           - MCHC [Mass/volume] by Automated count    35.1 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 12.4 %', '           - Platelets [#/volume] in Blood by Automated count 133.5 10*3/uL', '  2020-12-22 : PT panel - Platelet poor plasma by Coagulation assay', '           - Prothrombin time (PT)                    10.1 s', '           - INR in Platelet poor plasma by Coagulation assay 2.0 {INR}', '  2020-12-22 : Troponin I.cardiac panel - Serum or Plasma by High sensitivity method', '           - Troponin I.cardiac [Mass/volume] in Serum or Plasma by High sensitivity method 2.2 pg/mL', '  2020-12-22 : Iron panel - Serum or Plasma', '           - Ferritin [Mass/volume] in Serum or Plasma 474.9 ug/L', '  2020-12-22 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.0 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 8.0 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.7 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.6 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.0 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.6 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.6 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 22.7 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 8.3 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 6.6 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 4.0 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 13.7 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 110.5 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 37.1 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 9.8 U/L', '  2020-12-22 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 40.2 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 23.6 %', '           - Monocytes/100 leukocytes in Blood by Automated count 10.0 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 3.3 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.7 %', '           - Neutrophils [#/volume] in Blood by Automated count 3.7 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 0.9 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 1.3 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.4 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.4 10*3/uL', '  2020-12-22 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.5 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 5.2 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        13.6 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 43.2 %', '           - MCV [Entitic volume] by Automated count  95.0 fL', '           - MCH [Entitic mass] by Automated count    32.5 pg', '           - MCHC [Mass/volume] by Automated count    33.4 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 13.9 %', '           - Platelets [#/volume] in Blood by Automated count 131.8 10*3/uL', '  2020-12-21 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.0 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 8.0 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 3.0 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.6 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.0 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.6 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.6 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 22.7 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 11.0 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 6.7 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 4.1 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 10.2 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 116.9 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 15.4 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 1.8 U/L', '  2020-12-21 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 43.8 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 6.3 %', '           - Monocytes/100 leukocytes in Blood by Automated count 10.1 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 4.5 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.8 %', '           - Neutrophils [#/volume] in Blood by Automated count 3.2 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 1.1 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 0.8 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.6 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '  2020-12-21 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.2 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 5.6 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        13.7 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 37.7 %', '           - MCV [Entitic volume] by Automated count  94.0 fL', '           - MCH [Entitic mass] by Automated count    32.0 pg', '           - MCHC [Mass/volume] by Automated count    32.5 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 14.0 %', '           - Platelets [#/volume] in Blood by Automated count 118.3 10*3/uL', '  2020-12-20 : PT panel - Platelet poor plasma by Coagulation assay', '           - Prothrombin time (PT)                    10.4 s', '           - INR in Platelet poor plasma by Coagulation assay 1.4 {INR}', '  2020-12-20 : Troponin I.cardiac panel - Serum or Plasma by High sensitivity method', '           - Troponin I.cardiac [Mass/volume] in Serum or Plasma by High sensitivity method 3.1 pg/mL', '  2020-12-20 : Iron panel - Serum or Plasma', '           - Ferritin [Mass/volume] in Serum or Plasma 494.7 ug/L', '  2020-12-20 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.0 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 8.0 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.8 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.6 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.0 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.6 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.6 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 22.7 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 8.9 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 5.7 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 5.2 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 6.3 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 53.1 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 24.0 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 5.2 U/L', '  2020-12-20 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 33.7 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 20.3 %', '           - Monocytes/100 leukocytes in Blood by Automated count 7.5 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 3.8 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.1 %', '           - Neutrophils [#/volume] in Blood by Automated count 2.0 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 1.1 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 0.7 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '  2020-12-20 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.4 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 5.1 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        11.4 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 42.3 %', '           - MCV [Entitic volume] by Automated count  89.0 fL', '           - MCH [Entitic mass] by Automated count    30.7 pg', '           - MCHC [Mass/volume] by Automated count    32.3 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 14.9 %', '           - Platelets [#/volume] in Blood by Automated count 141.8 10*3/uL', '  2020-12-19 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.0 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 8.0 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.6 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.6 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.0 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.6 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.6 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 22.7 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 7.3 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 5.7 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 4.7 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 6.7 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 78.7 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 21.9 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 7.7 U/L', '  2020-12-19 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 10.2 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 9.5 %', '           - Monocytes/100 leukocytes in Blood by Automated count 14.5 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 4.3 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.9 %', '           - Neutrophils [#/volume] in Blood by Automated count 3.9 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 1.0 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 0.7 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '  2020-12-19 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.7 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 3.8 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        11.3 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 42.2 %', '           - MCV [Entitic volume] by Automated count  79.9 fL', '           - MCH [Entitic mass] by Automated count    31.8 pg', '           - MCHC [Mass/volume] by Automated count    33.0 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 15.4 %', '           - Platelets [#/volume] in Blood by Automated count 115.4 10*3/uL', '  2020-12-18 : PT panel - Platelet poor plasma by Coagulation assay', '           - Prothrombin time (PT)                    12.0 s', '           - INR in Platelet poor plasma by Coagulation assay 1.7 {INR}', '  2020-12-18 : Troponin I.cardiac panel - Serum or Plasma by High sensitivity method', '           - Troponin I.cardiac [Mass/volume] in Serum or Plasma by High sensitivity method 1.7 pg/mL', '  2020-12-18 : Iron panel - Serum or Plasma', '           - Ferritin [Mass/volume] in Serum or Plasma 394.4 ug/L', '  2020-12-18 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 77.0 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 8.0 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.8 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.6 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 141.0 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.6 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.6 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 22.7 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 6.2 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 7.9 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 3.8 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 14.4 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 67.7 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 41.7 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 1.0 U/L', '  2020-12-18 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 42.5 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 6.3 %', '           - Monocytes/100 leukocytes in Blood by Automated count 13.2 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 3.4 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.4 %', '           - Neutrophils [#/volume] in Blood by Automated count 2.7 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 1.1 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 0.9 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.4 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '  2020-12-18 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.9 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 5.0 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        13.1 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 39.0 %', '           - MCV [Entitic volume] by Automated count  87.5 fL', '           - MCH [Entitic mass] by Automated count    32.9 pg', '           - MCHC [Mass/volume] by Automated count    32.4 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 14.6 %', '           - Platelets [#/volume] in Blood by Automated count 122.1 10*3/uL', '  2020-12-17 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 76.9 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 11.9 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.9 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.9 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 136.9 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.5 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.8 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 27.5 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 10.4 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 6.1 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 3.9 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 8.4 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 82.3 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 27.7 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 30.4 U/L', '  2020-12-17 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 13.8 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 6.4 %', '           - Monocytes/100 leukocytes in Blood by Automated count 13.8 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 5.3 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.0 %', '           - Neutrophils [#/volume] in Blood by Automated count 2.5 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 1.1 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 1.3 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.4 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.3 10*3/uL', '  2020-12-17 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.8 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 3.8 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        11.2 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 44.8 %', '           - MCV [Entitic volume] by Automated count  87.6 fL', '           - MCH [Entitic mass] by Automated count    28.8 pg', '           - MCHC [Mass/volume] by Automated count    32.3 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 15.1 %', '           - Platelets [#/volume] in Blood by Automated count 141.4 10*3/uL', '  2020-12-16 : PT panel - Platelet poor plasma by Coagulation assay', '           - Prothrombin time (PT)                    11.3 s', '           - INR in Platelet poor plasma by Coagulation assay 2.6 {INR}', '  2020-12-16 : Troponin I.cardiac panel - Serum or Plasma by High sensitivity method', '           - Troponin I.cardiac [Mass/volume] in Serum or Plasma by High sensitivity method 3.3 pg/mL', '  2020-12-16 : Iron panel - Serum or Plasma', '           - Ferritin [Mass/volume] in Serum or Plasma 391.4 ug/L', '  2020-12-16 : Comprehensive metabolic 2000 panel - Serum or Plasma', '           - Glucose [Mass/volume] in Serum or Plasma 76.9 mg/dL', '           - Urea nitrogen [Mass/volume] in Serum or Plasma 11.9 mg/dL', '           - Creatinine [Mass/volume] in Serum or Plasma 2.8 mg/dL', '           - Calcium [Mass/volume] in Serum or Plasma 8.9 mg/dL', '           - Sodium [Moles/volume] in Serum or Plasma 136.9 mmol/L', '           - Potassium [Moles/volume] in Serum or Plasma 4.5 mmol/L', '           - Chloride [Moles/volume] in Serum or Plasma 101.8 mmol/L', '           - Carbon dioxide, total [Moles/volume] in Serum or Plasma 27.5 mmol/L', '           - Glomerular filtration rate/1.73 sq M.predicted 13.3 mL/min', '           - Protein [Mass/volume] in Serum or Plasma 5.7 g/dL', '           - Albumin [Mass/volume] in Serum or Plasma 4.3 g/dL', '           - Bilirubin.total [Mass/volume] in Serum or Plasma 11.4 mg/dL', '           - Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma 67.4 U/L', '           - Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma 0.7 U/L', '           - Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma 3.2 U/L', '  2020-12-16 : Auto Differential panel - Blood', '           - Neutrophils/100 leukocytes in Blood by Automated count 20.8 %', '           - Lymphocytes/100 leukocytes in Blood by Automated count 7.4 %', '           - Monocytes/100 leukocytes in Blood by Automated count 13.1 %', '           - Eosinophils/100 leukocytes in Blood by Automated count 4.2 %', '           - Basophils/100 leukocytes in Blood by Automated count 2.2 %', '           - Neutrophils [#/volume] in Blood by Automated count 1.4 10*3/uL', '           - Lymphocytes [#/volume] in Blood by Automated count 1.1 10*3/uL', '           - Monocytes [#/volume] in Blood by Automated count 1.1 10*3/uL', '           - Eosinophils [#/volume] in Blood by Automated count 0.5 10*3/uL', '           - Basophils [#/volume] in Blood by Automated count 0.4 10*3/uL', '  2020-12-16 : Complete blood count (hemogram) panel - Blood by Automated count', '           - Leukocytes [#/volume] in Blood by Automated count 3.1 10*3/uL', '           - Erythrocytes [#/volume] in Blood by Automated count 5.0 10*6/uL', '           - Hemoglobin [Mass/volume] in Blood        12.3 g/dL', '           - Hematocrit [Volume Fraction] of Blood by Automated count 37.8 %', '           - MCV [Entitic volume] by Automated count  84.1 fL', '           - MCH [Entitic mass] by Automated count    31.4 pg', '           - MCHC [Mass/volume] by Automated count    32.9 g/dL', '           - Erythrocyte distribution width [Ratio] by Automated count 14.9 %', '           - Platelets [#/volume] in Blood by Automated count 138.8 10*3/uL', '  2020-12-16 : SARS-CoV-2 RNA Pnl Resp NAA+probe', '           - SARS-CoV-2 RNA Pnl Resp NAA+probe        Detected (qualifier value) ', '  2020-12-16 : Respiratory pathogens DNA and RNA panel - Respiratory specimen by NAA with probe detection', '           - Influenza virus A RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Influenza virus B RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Respiratory syncytial virus RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Parainfluenza virus 1 RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Parainfluenza virus 2 RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Parainfluenza virus 3 RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Rhinovirus RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Human metapneumovirus RNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value) ', '           - Adenovirus A+B+C+D+E DNA [Presence] in Respiratory specimen by NAA with probe detection Negative (qualifier value)']\n",
    "def get_vitals(raw_vitals, category='VITALS'):\n",
    "    A = VITALS if category == 'VITALS' else LABS\n",
    "    vitals = []\n",
    "    for vital in raw_vitals[1:]:\n",
    "        vital = vital.strip()\n",
    "        for V in A:\n",
    "            if V[\"DESCRIPTION\"] in vital:\n",
    "                val = vital.split(V[\"UNITS\"])[0].strip().split()[-1]\n",
    "                if isnumber(val):\n",
    "                    try:\n",
    "                        if not any([V[\"DESCRIPTION\"] == v['description'] for v in vitals]):\n",
    "                            vitals.append({'description': V[\"DESCRIPTION\"], 'units': V[\"UNITS\"]})\n",
    "                            vitals[-1][\"value\"] = vital.split(V[\"UNITS\"])[0].strip().split()[-1]\n",
    "                    except KeyError:\n",
    "                        vitals.append({'description': V[\"DESCRIPTION\"], 'units': V[\"UNITS\"]})\n",
    "                        vitals[-1][\"value\"] = vital.split(V[\"UNITS\"])[0].strip().split()[-1]\n",
    "    return vitals\n",
    "\n",
    "get_vitals(vital, category='LABS')\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0e7e4746-cd61-4fcb-ab0c-b8903f6026b4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'immunization': 'meningococcal MCV4P', 'date': '2021-09-30'},\n",
       " {'immunization': 'Hep B, adult', 'date': '2021-09-30'},\n",
       " {'immunization': 'Td (adult) preservative free', 'date': '2021-09-30'},\n",
       " {'immunization': 'Influenza, seasonal, injectable, preservative free',\n",
       "  'date': '2021-09-30'},\n",
       " {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 100 mcg/0.5mL dose',\n",
       "  'date': '2021-02-18'},\n",
       " {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 100 mcg/0.5mL dose',\n",
       "  'date': '2021-01-21'}]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "imm = ['IMMUNIZATIONS:', '  2021-09-30 : meningococcal MCV4P', '  2021-09-30 : Hep B, adult', '  2021-09-30 : Td (adult) preservative free', '  2021-09-30 : Influenza, seasonal, injectable, preservative free', '  2021-02-18 : SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 100 mcg/0.5mL dose', '  2021-01-21 : SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 100 mcg/0.5mL dose']\n",
    "def get_immunization(raw_immunization):\n",
    "    immunizations = []\n",
    "    for imm in raw_immunization[1:]:\n",
    "        imm = imm.strip()\n",
    "        date, immunization = imm.split(\" : \")\n",
    "        immunizations.append({'immunization': immunization, 'date':date})\n",
    "    return immunizations\n",
    "        \n",
    "get_immunization(imm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "211aac5f-19b1-4320-ae0b-e1594a17039a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'imaging': 'Computed Radiography, Thoracic structure (body structure)',\n",
       "  'date': '2021-05-23'},\n",
       " {'imaging': 'Computed Radiography, Thoracic structure (body structure)',\n",
       "  'date': '2021-05-22'},\n",
       " {'imaging': 'Ultrasound, Heart structure (body structure)',\n",
       "  'date': '2021-05-18'},\n",
       " {'imaging': 'Computed Radiography, Thoracic structure (body structure)',\n",
       "  'date': '2021-05-18'}]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "imaging = ['IMAGING STUDIES:', '  2021-05-23 : Computed Radiography, Thoracic structure (body structure)', '  2021-05-22 : Computed Radiography, Thoracic structure (body structure)', '  2021-05-18 : Ultrasound, Heart structure (body structure)', '  2021-05-18 : Computed Radiography, Thoracic structure (body structure)']\n",
    "def get_imaging_studies(raw_imaging):\n",
    "    imagings = []\n",
    "    for imm in raw_imaging[1:]:\n",
    "        imm = imm.strip()\n",
    "        date, imaging = imm.split(\" : \")\n",
    "        imagings.append({'imaging': imaging, 'date':date})\n",
    "    return imagings\n",
    "\n",
    "get_imaging_studies(imaging)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "beaba0cf-0306-42f8-a5f5-ea2933583e3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def wrangle(filepath:str):\n",
    "    data = {}\n",
    "    data[\"patient_name\"] = get_name(filepath)\n",
    "    try:\n",
    "        txt = open(filepath, encoding = 'utf-8')\n",
    "\n",
    "        # Name\n",
    "        data[\"patient_name\"] = get_name(filepath)\n",
    "        \n",
    "        t = txt.read()\n",
    "        split1 = t.split(\"=\"*len(data[\"patient_name\"]))\n",
    "        split2 = split1[1].split('--------------------------------------------------------------------------------')\n",
    "        # print(split2[0].strip().split(\"\\n\"))\n",
    "        # Demographics\n",
    "        data[\"demographics\"] = { d.split(':')[0].lower():d.split(':')[1].strip() for d in split2[0].strip().split(\"\\n\")}\n",
    "        \n",
    "        # Allergies\n",
    "        # print(split2[1].strip().split(\"\\n\"))\n",
    "        data[\"allergies\"] = get_allergies(split2[1].strip().split(\"\\n\"))\n",
    "        \n",
    "        # Medications\n",
    "        # print(split2[2].strip().split(\"\\n\"))\n",
    "        data[\"medications\"] = get_medications(split2[2].strip().split(\"\\n\"))\n",
    "        \n",
    "        # Conditions\n",
    "        # assert split2[3].strip().split(\"\\n\")[0] == 'CONDITIONS:'\n",
    "        # print(split2[3].strip().split(\"\\n\"))\n",
    "        data[\"conditions\"] = get_conditions(split2[3].strip().split(\"\\n\"))\n",
    "        \n",
    "        # Care plans\n",
    "        # print(split2[4].strip().split(\"\\n\"))\n",
    "        data[\"care_plans\"] = get_care_plans(split2[4].strip().split(\"\\n\"))\n",
    "        \n",
    "        # Vitals\n",
    "        raw_vitals = split2[5].strip().split(\"\\n\")\n",
    "        raw_vitals.extend(split2[6].strip().split(\"\\n\"))\n",
    "        \n",
    "        data[\"vitals\"] = get_vitals(raw_vitals)\n",
    "        # assert all([isnumber(v[\"value\"]) for v in data[\"vitals\"]])\n",
    "        \n",
    "        # Lab\n",
    "        data[\"labs\"] = get_vitals(raw_vitals, category='LABS')\n",
    "        # assert all([isnumber(v[\"value\"]) for v in data[\"labs\"]])\n",
    "        \n",
    "        # Immunization\n",
    "        raw_immunization = split2[8].strip().split(\"\\n\")\n",
    "        # print(raw_immunization)\n",
    "        data[\"immunization\"] = get_immunization(raw_immunization)\n",
    "        \n",
    "        # Imaging\n",
    "        raw_imaging = split2[10].strip().split(\"\\n\")\n",
    "        # print(raw_imaging)\n",
    "        data[\"imaging_studies\"] = get_imaging_studies(raw_imaging)\n",
    "        \n",
    "        return data\n",
    "    finally:\n",
    "        txt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "553df029-2180-4311-b4cd-042004522bc0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'patient_name': 'Adan Kovacek',\n",
       " 'demographics': {'race': 'White',\n",
       "  'ethnicity': 'Non-Hispanic',\n",
       "  'gender': 'M',\n",
       "  'age': '28',\n",
       "  'birth date': '1994-01-08',\n",
       "  'marital status': 'M'},\n",
       " 'allergies': [{'to': 'Wheat', 'type': 'substance'}],\n",
       " 'medications': [{'medicine': 'NDA020800 0.3 ML Epinephrine 1 MG/ML Auto-Injector',\n",
       "   'from': '1994-10-09'},\n",
       "  {'medicine': 'Loratadine 5 MG Chewable Tablet', 'from': '1994-10-09'}],\n",
       " 'conditions': [{'condition': 'Anemia (disorder)',\n",
       "   'from': '2022-03-19',\n",
       "   'to': ''},\n",
       "  {'condition': 'Prediabetes', 'from': '2022-03-19', 'to': ''}],\n",
       " 'care_plans': [{'careplan': 'Diabetes self management plan',\n",
       "   'date': '2022-03-19',\n",
       "   'activities': ['Diabetic diet', 'Exercise therapy'],\n",
       "   'status': '[CURRENT]',\n",
       "   'reason': 'Prediabetes'},\n",
       "  {'careplan': 'Self-care interventions (procedure)',\n",
       "   'date': '1994-09-26',\n",
       "   'activities': ['Food allergy diet',\n",
       "    'Allergy education',\n",
       "    'Allergy education'],\n",
       "   'status': '[CURRENT]'}],\n",
       " 'vitals': [{'description': 'Respiratory rate',\n",
       "   'units': '/min',\n",
       "   'value': '15.0'},\n",
       "  {'description': 'Heart rate', 'units': '/min', 'value': '74.0'},\n",
       "  {'description': 'Diastolic Blood Pressure',\n",
       "   'units': 'mm[Hg]',\n",
       "   'value': '80.0'},\n",
       "  {'description': 'Systolic Blood Pressure',\n",
       "   'units': 'mm[Hg]',\n",
       "   'value': '119.0'},\n",
       "  {'description': 'Body Mass Index', 'units': 'kg/m2', 'value': '26.8'},\n",
       "  {'description': 'Body Weight', 'units': 'kg', 'value': '71.6'},\n",
       "  {'description': 'Pain severity - 0-10 verbal numeric rating [Score] - Reported',\n",
       "   'units': '{score}',\n",
       "   'value': '4.0'},\n",
       "  {'description': 'Body Height', 'units': 'cm', 'value': '163.3'}],\n",
       " 'labs': [{'description': 'Hemoglobin [Mass/volume] in Blood',\n",
       "   'units': 'g/dL',\n",
       "   'value': '11.6'},\n",
       "  {'description': 'Hematocrit [Volume Fraction] of Blood',\n",
       "   'units': '%',\n",
       "   'value': '30.9'},\n",
       "  {'description': 'WBC Auto (Bld) [#/Vol]',\n",
       "   'units': '10*3/uL',\n",
       "   'value': '5.2'},\n",
       "  {'description': 'RBC Auto (Bld) [#/Vol]',\n",
       "   'units': '10*6/uL',\n",
       "   'value': '4.1'},\n",
       "  {'description': 'MCV [Entitic volume] by Automated count',\n",
       "   'units': 'fL',\n",
       "   'value': '92.1'},\n",
       "  {'description': 'MCH [Entitic mass] by Automated count',\n",
       "   'units': 'pg',\n",
       "   'value': '30.3'},\n",
       "  {'description': 'MCHC [Mass/volume] by Automated count',\n",
       "   'units': 'g/dL',\n",
       "   'value': '34.9'},\n",
       "  {'description': 'RDW - Erythrocyte distribution width Auto (RBC) [Entitic vol]',\n",
       "   'units': 'fL',\n",
       "   'value': '43.8'},\n",
       "  {'description': 'Platelets [#/volume] in Blood by Automated count',\n",
       "   'units': '10*3/uL',\n",
       "   'value': '288.5'},\n",
       "  {'description': 'Platelet distribution width [Entitic volume] in Blood by Automated count',\n",
       "   'units': 'fL',\n",
       "   'value': '312.7'},\n",
       "  {'description': 'Platelet mean volume [Entitic volume] in Blood by Automated count',\n",
       "   'units': 'fL',\n",
       "   'value': '11.7'},\n",
       "  {'description': 'Leukocytes [#/volume] in Blood by Automated count',\n",
       "   'units': '10*3/uL',\n",
       "   'value': '5.5'},\n",
       "  {'description': 'Erythrocytes [#/volume] in Blood by Automated count',\n",
       "   'units': '10*6/uL',\n",
       "   'value': '5.4'},\n",
       "  {'description': 'Hematocrit [Volume Fraction] of Blood by Automated count',\n",
       "   'units': '%',\n",
       "   'value': '42.6'},\n",
       "  {'description': 'Erythrocyte distribution width [Entitic volume] by Automated count',\n",
       "   'units': 'fL',\n",
       "   'value': '39.2'},\n",
       "  {'description': 'Hemoglobin A1c/Hemoglobin.total in Blood',\n",
       "   'units': '%',\n",
       "   'value': '6.4'},\n",
       "  {'description': 'Diastolic Blood Pressure',\n",
       "   'units': 'mm[Hg]',\n",
       "   'value': '80.0'}],\n",
       " 'immunization': [{'immunization': 'Influenza, seasonal, injectable, preservative free',\n",
       "   'date': '2022-03-19'},\n",
       "  {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose',\n",
       "   'date': '2021-08-28'},\n",
       "  {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose',\n",
       "   'date': '2021-08-07'}],\n",
       " 'imaging_studies': []}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wrangle(text_data[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "70f9c0ef-291c-4e75-9eae-1c9fe0555a7c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "for i in range(len(text_data)):\n",
    "    try:\n",
    "        r = wrangle(text_data[i])\n",
    "    except Exception as e:\n",
    "        print(e)\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "98eb31b0-25a7-4f3c-b45c-ab39ad8833a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list = [wrangle(data) for data in text_data]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7a53c86b-9bd5-4dca-b1cc-804ee0bde03f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'patient_name': 'Adan Kovacek',\n",
       "  'demographics': {'race': 'White',\n",
       "   'ethnicity': 'Non-Hispanic',\n",
       "   'gender': 'M',\n",
       "   'age': '28',\n",
       "   'birth date': '1994-01-08',\n",
       "   'marital status': 'M'},\n",
       "  'allergies': [{'to': 'Wheat', 'type': 'substance'}],\n",
       "  'medications': [{'medicine': 'NDA020800 0.3 ML Epinephrine 1 MG/ML Auto-Injector',\n",
       "    'from': '1994-10-09'},\n",
       "   {'medicine': 'Loratadine 5 MG Chewable Tablet', 'from': '1994-10-09'}],\n",
       "  'conditions': [{'condition': 'Anemia (disorder)',\n",
       "    'from': '2022-03-19',\n",
       "    'to': ''},\n",
       "   {'condition': 'Prediabetes', 'from': '2022-03-19', 'to': ''}],\n",
       "  'care_plans': [{'careplan': 'Diabetes self management plan',\n",
       "    'date': '2022-03-19',\n",
       "    'activities': ['Diabetic diet', 'Exercise therapy'],\n",
       "    'status': '[CURRENT]',\n",
       "    'reason': 'Prediabetes'},\n",
       "   {'careplan': 'Self-care interventions (procedure)',\n",
       "    'date': '1994-09-26',\n",
       "    'activities': ['Food allergy diet',\n",
       "     'Allergy education',\n",
       "     'Allergy education'],\n",
       "    'status': '[CURRENT]'}],\n",
       "  'vitals': [{'description': 'Respiratory rate',\n",
       "    'units': '/min',\n",
       "    'value': '15.0'},\n",
       "   {'description': 'Heart rate', 'units': '/min', 'value': '74.0'},\n",
       "   {'description': 'Diastolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '80.0'},\n",
       "   {'description': 'Systolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '119.0'},\n",
       "   {'description': 'Body Mass Index', 'units': 'kg/m2', 'value': '26.8'},\n",
       "   {'description': 'Body Weight', 'units': 'kg', 'value': '71.6'},\n",
       "   {'description': 'Pain severity - 0-10 verbal numeric rating [Score] - Reported',\n",
       "    'units': '{score}',\n",
       "    'value': '4.0'},\n",
       "   {'description': 'Body Height', 'units': 'cm', 'value': '163.3'}],\n",
       "  'labs': [{'description': 'Hemoglobin [Mass/volume] in Blood',\n",
       "    'units': 'g/dL',\n",
       "    'value': '11.6'},\n",
       "   {'description': 'Hematocrit [Volume Fraction] of Blood',\n",
       "    'units': '%',\n",
       "    'value': '30.9'},\n",
       "   {'description': 'WBC Auto (Bld) [#/Vol]',\n",
       "    'units': '10*3/uL',\n",
       "    'value': '5.2'},\n",
       "   {'description': 'RBC Auto (Bld) [#/Vol]',\n",
       "    'units': '10*6/uL',\n",
       "    'value': '4.1'},\n",
       "   {'description': 'MCV [Entitic volume] by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '92.1'},\n",
       "   {'description': 'MCH [Entitic mass] by Automated count',\n",
       "    'units': 'pg',\n",
       "    'value': '30.3'},\n",
       "   {'description': 'MCHC [Mass/volume] by Automated count',\n",
       "    'units': 'g/dL',\n",
       "    'value': '34.9'},\n",
       "   {'description': 'RDW - Erythrocyte distribution width Auto (RBC) [Entitic vol]',\n",
       "    'units': 'fL',\n",
       "    'value': '43.8'},\n",
       "   {'description': 'Platelets [#/volume] in Blood by Automated count',\n",
       "    'units': '10*3/uL',\n",
       "    'value': '288.5'},\n",
       "   {'description': 'Platelet distribution width [Entitic volume] in Blood by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '312.7'},\n",
       "   {'description': 'Platelet mean volume [Entitic volume] in Blood by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '11.7'},\n",
       "   {'description': 'Leukocytes [#/volume] in Blood by Automated count',\n",
       "    'units': '10*3/uL',\n",
       "    'value': '5.5'},\n",
       "   {'description': 'Erythrocytes [#/volume] in Blood by Automated count',\n",
       "    'units': '10*6/uL',\n",
       "    'value': '5.4'},\n",
       "   {'description': 'Hematocrit [Volume Fraction] of Blood by Automated count',\n",
       "    'units': '%',\n",
       "    'value': '42.6'},\n",
       "   {'description': 'Erythrocyte distribution width [Entitic volume] by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '39.2'},\n",
       "   {'description': 'Hemoglobin A1c/Hemoglobin.total in Blood',\n",
       "    'units': '%',\n",
       "    'value': '6.4'},\n",
       "   {'description': 'Diastolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '80.0'}],\n",
       "  'immunization': [{'immunization': 'Influenza, seasonal, injectable, preservative free',\n",
       "    'date': '2022-03-19'},\n",
       "   {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose',\n",
       "    'date': '2021-08-28'},\n",
       "   {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose',\n",
       "    'date': '2021-08-07'}],\n",
       "  'imaging_studies': []},\n",
       " {'patient_name': 'Adelia Sherrie Ferry',\n",
       "  'demographics': {'race': 'White',\n",
       "   'ethnicity': 'Non-Hispanic',\n",
       "   'gender': 'F',\n",
       "   'age': '55',\n",
       "   'birth date': '1967-01-12',\n",
       "   'marital status': 'M'},\n",
       "  'allergies': None,\n",
       "  'medications': [{'medicine': 'lisinopril 10 MG Oral Tablet for Hypertension',\n",
       "    'from': '2022-07-28'},\n",
       "   {'medicine': 'Hydrochlorothiazide 25 MG Oral Tablet for Hypertension',\n",
       "    'from': '2022-07-28'}],\n",
       "  'conditions': [{'condition': 'Severe anxiety (panic) (finding',\n",
       "    'from': '2021-07-22',\n",
       "    'to': ''},\n",
       "   {'condition': 'Miscarriage in first trimester',\n",
       "    'from': '2015-12-03',\n",
       "    'to': ''},\n",
       "   {'condition': 'Severe anxiety (panic) (finding',\n",
       "    'from': '2008-05-08',\n",
       "    'to': '2009-05-14'},\n",
       "   {'condition': 'Prediabetes', 'from': '2006-04-27', 'to': ''},\n",
       "   {'condition': 'Hypertension', 'from': '2001-03-29', 'to': ''},\n",
       "   {'condition': 'Chronic sinusitis (disorder)',\n",
       "    'from': '1990-08-06',\n",
       "    'to': ''}],\n",
       "  'care_plans': [{'careplan': 'Routine antenatal care',\n",
       "    'date': '2014-06-19',\n",
       "    'activities': ['Antenatal education',\n",
       "     'Antenatal risk assessment',\n",
       "     'Antenatal blood tests'],\n",
       "    'status': '[CURRENT]'},\n",
       "   {'careplan': 'Diabetes self management plan',\n",
       "    'date': '2006-04-27',\n",
       "    'activities': ['Diabetic diet', 'Exercise therapy'],\n",
       "    'status': '[CURRENT]',\n",
       "    'reason': 'Prediabetes'},\n",
       "   {'careplan': 'Routine antenatal care',\n",
       "    'date': '2006-04-27',\n",
       "    'activities': ['Antenatal education',\n",
       "     'Antenatal risk assessment',\n",
       "     'Antenatal blood tests'],\n",
       "    'status': '[STOPPED]'},\n",
       "   {'careplan': 'Lifestyle education regarding hypertension',\n",
       "    'date': '2001-03-29',\n",
       "    'activities': ['Prescribed activity/exercise education',\n",
       "     'Counseling about alcohol consumption',\n",
       "     'Dietary approaches to stop hypertension diet',\n",
       "     'Smoking cessation education'],\n",
       "    'status': '[CURRENT]',\n",
       "    'reason': 'Hypertension'},\n",
       "   {'careplan': 'Routine antenatal care',\n",
       "    'date': '1998-03-12',\n",
       "    'activities': ['Antenatal education',\n",
       "     'Antenatal risk assessment',\n",
       "     'Antenatal blood tests'],\n",
       "    'status': '[STOPPED]'},\n",
       "   {'careplan': 'Routine antenatal care',\n",
       "    'date': '1994-01-06',\n",
       "    'activities': ['Antenatal education',\n",
       "     'Antenatal risk assessment',\n",
       "     'Antenatal blood tests'],\n",
       "    'status': '[STOPPED]'},\n",
       "   {'careplan': 'Routine antenatal care',\n",
       "    'date': '1990-06-07',\n",
       "    'activities': ['Antenatal education',\n",
       "     'Antenatal risk assessment',\n",
       "     'Antenatal blood tests'],\n",
       "    'status': '[STOPPED]'},\n",
       "   {'careplan': 'Routine antenatal care',\n",
       "    'date': '1988-03-10',\n",
       "    'activities': ['Antenatal education',\n",
       "     'Antenatal risk assessment',\n",
       "     'Antenatal blood tests'],\n",
       "    'status': '[STOPPED]'},\n",
       "   {'careplan': 'Routine antenatal care',\n",
       "    'date': '1984-05-10',\n",
       "    'activities': ['Antenatal education',\n",
       "     'Antenatal risk assessment',\n",
       "     'Antenatal blood tests'],\n",
       "    'status': '[STOPPED]'}],\n",
       "  'vitals': [{'description': 'Respiratory rate',\n",
       "    'units': '/min',\n",
       "    'value': '16.0'},\n",
       "   {'description': 'Heart rate', 'units': '/min', 'value': '70.0'},\n",
       "   {'description': 'Diastolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '79.0'},\n",
       "   {'description': 'Systolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '125.0'},\n",
       "   {'description': 'Body Mass Index', 'units': 'kg/m2', 'value': '27.5'},\n",
       "   {'description': 'Body Weight', 'units': 'kg', 'value': '65.3'},\n",
       "   {'description': 'Pain severity - 0-10 verbal numeric rating [Score] - Reported',\n",
       "    'units': '{score}',\n",
       "    'value': '4.0'},\n",
       "   {'description': 'Body Height', 'units': 'cm', 'value': '154.2'}],\n",
       "  'labs': [{'description': 'Total Cholesterol',\n",
       "    'units': 'mg/dL',\n",
       "    'value': '119.0'},\n",
       "   {'description': 'Triglycerides', 'units': 'mg/dL', 'value': '123.3'},\n",
       "   {'description': 'Low Density Lipoprotein Cholesterol',\n",
       "    'units': 'mg/dL',\n",
       "    'value': '50.2'},\n",
       "   {'description': 'High Density Lipoprotein Cholesterol',\n",
       "    'units': 'mg/dL',\n",
       "    'value': '44.1'},\n",
       "   {'description': 'Glucose', 'units': 'mg/dL', 'value': '86.1'},\n",
       "   {'description': 'Urea Nitrogen', 'units': 'mg/dL', 'value': '15.9'},\n",
       "   {'description': 'Creatinine', 'units': 'mg/dL', 'value': '0.8'},\n",
       "   {'description': 'Calcium', 'units': 'mg/dL', 'value': '9.9'},\n",
       "   {'description': 'Sodium', 'units': 'mmol/L', 'value': '142.5'},\n",
       "   {'description': 'Potassium', 'units': 'mmol/L', 'value': '4.2'},\n",
       "   {'description': 'Chloride', 'units': 'mmol/L', 'value': '104.1'},\n",
       "   {'description': 'Carbon Dioxide', 'units': 'mmol/L', 'value': '25.0'},\n",
       "   {'description': 'Leukocytes [#/volume] in Blood by Automated count',\n",
       "    'units': '10*3/uL',\n",
       "    'value': '10.4'},\n",
       "   {'description': 'Erythrocytes [#/volume] in Blood by Automated count',\n",
       "    'units': '10*6/uL',\n",
       "    'value': '5.4'},\n",
       "   {'description': 'Hemoglobin [Mass/volume] in Blood',\n",
       "    'units': 'g/dL',\n",
       "    'value': '12.4'},\n",
       "   {'description': 'Hematocrit [Volume Fraction] of Blood by Automated count',\n",
       "    'units': '%',\n",
       "    'value': '39.0'},\n",
       "   {'description': 'Hematocrit [Volume Fraction] of Blood',\n",
       "    'units': '%',\n",
       "    'value': '39.0'},\n",
       "   {'description': 'MCV [Entitic volume] by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '88.8'},\n",
       "   {'description': 'MCH [Entitic mass] by Automated count',\n",
       "    'units': 'pg',\n",
       "    'value': '31.9'},\n",
       "   {'description': 'MCHC [Mass/volume] by Automated count',\n",
       "    'units': 'g/dL',\n",
       "    'value': '33.5'},\n",
       "   {'description': 'Erythrocyte distribution width [Entitic volume] by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '44.3'},\n",
       "   {'description': 'Platelets [#/volume] in Blood by Automated count',\n",
       "    'units': '10*3/uL',\n",
       "    'value': '261.8'},\n",
       "   {'description': 'Platelet distribution width [Entitic volume] in Blood by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '503.1'},\n",
       "   {'description': 'Platelet mean volume [Entitic volume] in Blood by Automated count',\n",
       "    'units': 'fL',\n",
       "    'value': '11.7'},\n",
       "   {'description': 'Hemoglobin A1c/Hemoglobin.total in Blood',\n",
       "    'units': '%',\n",
       "    'value': '6.2'},\n",
       "   {'description': 'Diastolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '79.0'}],\n",
       "  'immunization': [{'immunization': 'Influenza, seasonal, injectable, preservative free',\n",
       "    'date': '2022-07-28'},\n",
       "   {'immunization': 'Influenza, seasonal, injectable, preservative free',\n",
       "    'date': '2021-07-22'},\n",
       "   {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose',\n",
       "    'date': '2021-04-22'},\n",
       "   {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose',\n",
       "    'date': '2021-04-01'}],\n",
       "  'imaging_studies': []},\n",
       " {'patient_name': 'Adina Dorthea Armstrong',\n",
       "  'demographics': {'race': 'White',\n",
       "   'ethnicity': 'Non-Hispanic',\n",
       "   'gender': 'F',\n",
       "   'age': '50',\n",
       "   'birth date': '1972-02-22',\n",
       "   'marital status': 'M'},\n",
       "  'allergies': [{'to': 'Tree nut', 'type': 'substance'},\n",
       "   {'to': 'Tree pollen', 'type': 'substance'},\n",
       "   {'to': 'Grass pollen', 'type': 'substance'},\n",
       "   {'to': 'Animal dander', 'type': 'substance'},\n",
       "   {'to': 'House dust mite', 'type': 'organism'},\n",
       "   {'to': 'Mold', 'type': 'organism'},\n",
       "   {'to': 'Latex', 'type': 'substance'}],\n",
       "  'medications': [{'medicine': 'Simvastatin 10 MG Oral Tablet for Hyperlipidemia',\n",
       "    'from': '2022-09-15'},\n",
       "   {'medicine': 'amLODIPine 2.5 MG Oral Tablet for Hypertension',\n",
       "    'from': '2022-09-06'},\n",
       "   {'medicine': 'Chlorpheniramine Maleate 2 MG/ML Oral Solution',\n",
       "    'from': '1976-10-13'}],\n",
       "  'conditions': [{'condition': 'Severe anxiety (panic) (finding',\n",
       "    'from': '2022-09-06',\n",
       "    'to': ''},\n",
       "   {'condition': 'Injury of anterior cruciate ligament',\n",
       "    'from': '2020-12-21',\n",
       "    'to': '2021-05-01'},\n",
       "   {'condition': 'Hyperlipidemia', 'from': '2020-08-25', 'to': ''},\n",
       "   {'condition': 'Anemia (disorder)', 'from': '2000-05-02', 'to': ''},\n",
       "   {'condition': 'Hypertension', 'from': '2000-05-02', 'to': ''},\n",
       "   {'condition': 'Prediabetes', 'from': '1994-04-26', 'to': ''},\n",
       "   {'condition': 'Chronic sinusitis (disorder)',\n",
       "    'from': '1980-11-01',\n",
       "    'to': ''}],\n",
       "  'care_plans': [{'careplan': 'Physiotherapy care plan (record artifact)',\n",
       "    'date': '2020-12-21',\n",
       "    'activities': ['Rest, ice, compression and elevation treatment programme',\n",
       "     'Stretching exercises'],\n",
       "    'status': '[STOPPED]',\n",
       "    'reason': 'Injury of anterior cruciate ligament'},\n",
       "   {'careplan': 'Hyperlipidemia clinical management plan',\n",
       "    'date': '2020-09-15',\n",
       "    'activities': ['low salt diet education', 'physical exercise'],\n",
       "    'status': '[CURRENT]',\n",
       "    'reason': 'Hyperlipidemia'},\n",
       "   {'careplan': 'Lifestyle education regarding hypertension',\n",
       "    'date': '2000-05-02',\n",
       "    'activities': ['Prescribed activity/exercise education',\n",
       "     'Counseling about alcohol consumption',\n",
       "     'Dietary approaches to stop hypertension diet',\n",
       "     'Smoking cessation education'],\n",
       "    'status': '[CURRENT]',\n",
       "    'reason': 'Hypertension'},\n",
       "   {'careplan': 'Diabetes self management plan',\n",
       "    'date': '1994-04-26',\n",
       "    'activities': ['Diabetic diet', 'Exercise therapy'],\n",
       "    'status': '[CURRENT]',\n",
       "    'reason': 'Prediabetes'},\n",
       "   {'careplan': 'Self-care interventions (procedure)',\n",
       "    'date': '1973-01-07',\n",
       "    'activities': ['Food allergy diet',\n",
       "     'Allergy education',\n",
       "     'Allergy education'],\n",
       "    'status': '[CURRENT]'}],\n",
       "  'vitals': [{'description': 'Respiratory rate',\n",
       "    'units': '/min',\n",
       "    'value': '13.0'},\n",
       "   {'description': 'Heart rate', 'units': '/min', 'value': '99.0'},\n",
       "   {'description': 'Diastolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '76.0'},\n",
       "   {'description': 'Systolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '120.0'},\n",
       "   {'description': 'Body Mass Index', 'units': 'kg/m2', 'value': '30.2'},\n",
       "   {'description': 'Body Weight', 'units': 'kg', 'value': '76.8'},\n",
       "   {'description': 'Pain severity - 0-10 verbal numeric rating [Score] - Reported',\n",
       "    'units': '{score}',\n",
       "    'value': '0.0'},\n",
       "   {'description': 'Body Height', 'units': 'cm', 'value': '159.4'}],\n",
       "  'labs': [{'description': 'Total Cholesterol',\n",
       "    'units': 'mg/dL',\n",
       "    'value': '167.4'},\n",
       "   {'description': 'Triglycerides', 'units': 'mg/dL', 'value': '167.2'},\n",
       "   {'description': 'Low Density Lipoprotein Cholesterol',\n",
       "    'units': 'mg/dL',\n",
       "    'value': '146.0'},\n",
       "   {'description': 'High Density Lipoprotein Cholesterol',\n",
       "    'units': 'mg/dL',\n",
       "    'value': '70.7'},\n",
       "   {'description': 'Glucose', 'units': 'mg/dL', 'value': '92.0'},\n",
       "   {'description': 'Urea Nitrogen', 'units': 'mg/dL', 'value': '12.9'},\n",
       "   {'description': 'Creatinine', 'units': 'mg/dL', 'value': '3.5'},\n",
       "   {'description': 'Calcium', 'units': 'mg/dL', 'value': '8.8'},\n",
       "   {'description': 'Sodium', 'units': 'mmol/L', 'value': '139.5'},\n",
       "   {'description': 'Potassium', 'units': 'mmol/L', 'value': '4.6'},\n",
       "   {'description': 'Chloride', 'units': 'mmol/L', 'value': '105.1'},\n",
       "   {'description': 'Carbon Dioxide', 'units': 'mmol/L', 'value': '22.1'},\n",
       "   {'description': 'Glomerular filtration rate/1.73 sq M.predicted',\n",
       "    'units': 'mL/min',\n",
       "    'value': '84.3'},\n",
       "   {'description': 'Protein [Mass/volume] in Serum or Plasma',\n",
       "    'units': 'g/dL',\n",
       "    'value': '7.3'},\n",
       "   {'description': 'Albumin [Mass/volume] in Serum or Plasma',\n",
       "    'units': 'g/dL',\n",
       "    'value': '4.2'},\n",
       "   {'description': 'Globulin [Mass/volume] in Serum by calculation',\n",
       "    'units': 'g/L',\n",
       "    'value': '2.8'},\n",
       "   {'description': 'Bilirubin.total [Mass/volume] in Serum or Plasma',\n",
       "    'units': 'mg/dL',\n",
       "    'value': '0.1'},\n",
       "   {'description': 'Alkaline phosphatase [Enzymatic activity/volume] in Serum or Plasma',\n",
       "    'units': 'U/L',\n",
       "    'value': '27.0'},\n",
       "   {'description': 'Alanine aminotransferase [Enzymatic activity/volume] in Serum or Plasma',\n",
       "    'units': 'U/L',\n",
       "    'value': '42.4'},\n",
       "   {'description': 'Aspartate aminotransferase [Enzymatic activity/volume] in Serum or Plasma',\n",
       "    'units': 'U/L',\n",
       "    'value': '17.3'},\n",
       "   {'description': 'Hemoglobin A1c/Hemoglobin.total in Blood',\n",
       "    'units': '%',\n",
       "    'value': '6.2'},\n",
       "   {'description': 'Diastolic Blood Pressure',\n",
       "    'units': 'mm[Hg]',\n",
       "    'value': '76.0'}],\n",
       "  'immunization': [{'immunization': 'Influenza, seasonal, injectable, preservative free',\n",
       "    'date': '2022-09-06'},\n",
       "   {'immunization': 'zoster', 'date': '2022-09-06'},\n",
       "   {'immunization': 'Influenza, seasonal, injectable, preservative free',\n",
       "    'date': '2021-08-31'},\n",
       "   {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 100 mcg/0.5mL dose',\n",
       "    'date': '2021-05-11'},\n",
       "   {'immunization': 'SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 100 mcg/0.5mL dose',\n",
       "    'date': '2021-04-13'}],\n",
       "  'imaging_studies': [{'imaging': 'Digital Radiography, Knee',\n",
       "    'date': '2020-12-21'}]}]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_list[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "6720507a-4a2a-4d4d-8413-57e3e06125d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['patient_name', 'demographics', 'allergies', 'medications', 'conditions', 'care_plans', 'vitals', 'labs', 'immunization', 'imaging_studies']\n"
     ]
    }
   ],
   "source": [
    "print([keys for keys in data_list[0].keys()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0db3b904-0579-432b-a7c7-5da6c719e6be",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9172c2b6-1f9f-49f7-bd9c-883c25577c8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('./data/output/data.json', 'w') as fp:\n",
    "    json.dump(data_list, fp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b104752e-90f2-456f-bb44-67f0b80739b5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"patient_name\": \"Adan Kovacek\", \"demographics\": {\"race\": \"White\", \"ethnicity\": \"Non-Hispanic\", \"gender\": \"M\", \"age\": \"28\", \"birth date\": \"1994-01-08\", \"marital status\": \"M\"}, \"allergies\": [{\"to\": \"Wheat\", \"type\": \"substance\"}], \"medications\": [{\"medicine\": \"NDA020800 0.3 ML Epinephrine 1 MG/ML Auto-Injector\", \"from\": \"1994-10-09\"}, {\"medicine\": \"Loratadine 5 MG Chewable Tablet\", \"from\": \"1994-10-09\"}], \"conditions\": [{\"condition\": \"Anemia (disorder)\", \"from\": \"2022-03-19\", \"to\": \"\"}, {\"condition\": \"Prediabetes\", \"from\": \"2022-03-19\", \"to\": \"\"}], \"care_plans\": [{\"careplan\": \"Diabetes self management plan\", \"date\": \"2022-03-19\", \"activities\": [\"Diabetic diet\", \"Exercise therapy\"], \"status\": \"[CURRENT]\", \"reason\": \"Prediabetes\"}, {\"careplan\": \"Self-care interventions (procedure)\", \"date\": \"1994-09-26\", \"activities\": [\"Food allergy diet\", \"Allergy education\", \"Allergy education\"], \"status\": \"[CURRENT]\"}], \"vitals\": [{\"description\": \"Respiratory rate\", \"units\": \"/min\", \"value\": \"15.0\"}, {\"description\": \"Heart rate\", \"units\": \"/min\", \"value\": \"74.0\"}, {\"description\": \"Diastolic Blood Pressure\", \"units\": \"mm[Hg]\", \"value\": \"80.0\"}, {\"description\": \"Systolic Blood Pressure\", \"units\": \"mm[Hg]\", \"value\": \"119.0\"}, {\"description\": \"Body Mass Index\", \"units\": \"kg/m2\", \"value\": \"26.8\"}, {\"description\": \"Body Weight\", \"units\": \"kg\", \"value\": \"71.6\"}, {\"description\": \"Pain severity - 0-10 verbal numeric rating [Score] - Reported\", \"units\": \"{score}\", \"value\": \"4.0\"}, {\"description\": \"Body Height\", \"units\": \"cm\", \"value\": \"163.3\"}], \"labs\": [{\"description\": \"Hemoglobin [Mass/volume] in Blood\", \"units\": \"g/dL\", \"value\": \"11.6\"}, {\"description\": \"Hematocrit [Volume Fraction] of Blood\", \"units\": \"%\", \"value\": \"30.9\"}, {\"description\": \"WBC Auto (Bld) [#/Vol]\", \"units\": \"10*3/uL\", \"value\": \"5.2\"}, {\"description\": \"RBC Auto (Bld) [#/Vol]\", \"units\": \"10*6/uL\", \"value\": \"4.1\"}, {\"description\": \"MCV [Entitic volume] by Automated count\", \"units\": \"fL\", \"value\": \"92.1\"}, {\"description\": \"MCH [Entitic mass] by Automated count\", \"units\": \"pg\", \"value\": \"30.3\"}, {\"description\": \"MCHC [Mass/volume] by Automated count\", \"units\": \"g/dL\", \"value\": \"34.9\"}, {\"description\": \"RDW - Erythrocyte distribution width Auto (RBC) [Entitic vol]\", \"units\": \"fL\", \"value\": \"43.8\"}, {\"description\": \"Platelets [#/volume] in Blood by Automated count\", \"units\": \"10*3/uL\", \"value\": \"288.5\"}, {\"description\": \"Platelet distribution width [Entitic volume] in Blood by Automated count\", \"units\": \"fL\", \"value\": \"312.7\"}, {\"description\": \"Platelet mean volume [Entitic volume] in Blood by Automated count\", \"units\": \"fL\", \"value\": \"11.7\"}, {\"description\": \"Leukocytes [#/volume] in Blood by Automated count\", \"units\": \"10*3/uL\", \"value\": \"5.5\"}, {\"description\": \"Erythrocytes [#/volume] in Blood by Automated count\", \"units\": \"10*6/uL\", \"value\": \"5.4\"}, {\"description\": \"Hematocrit [Volume Fraction] of Blood by Automated count\", \"units\": \"%\", \"value\": \"42.6\"}, {\"description\": \"Erythrocyte distribution width [Entitic volume] by Automated count\", \"units\": \"fL\", \"value\": \"39.2\"}, {\"description\": \"Hemoglobin A1c/Hemoglobin.total in Blood\", \"units\": \"%\", \"value\": \"6.4\"}, {\"description\": \"Diastolic Blood Pressure\", \"units\": \"mm[Hg]\", \"value\": \"80.0\"}], \"immunization\": [{\"immunization\": \"Influenza, seasonal, injectable, preservative free\", \"date\": \"2022-03-19\"}, {\"immunization\": \"SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose\", \"date\": \"2021-08-28\"}, {\"immunization\": \"SARS-COV-2 (COVID-19) vaccine, mRNA, spike protein, LNP, preservative free, 30 mcg/0.3mL dose\", \"date\": \"2021-08-07\"}], \"imaging_studies\": []}'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json.dumps(data_list[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10d44613-b4df-4961-9a8e-3ae953038756",
   "metadata": {},
   "source": [
    "# Export to Mongo DB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "db30f202-576a-4ae5-80f3-e20fbe267dcb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from dotenv import load_dotenv\n",
    "import pymongo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "af22a4b5-1c13-4019-a25d-1caace781768",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "51d4c987-4017-406a-81f4-0a793caae194",
   "metadata": {},
   "outputs": [],
   "source": [
    "username = os.environ.get(\"USERNAME\")\n",
    "password = os.environ.get(\"PASSWORD\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b5d0618a-985d-49a0-8328-f28002914d7a",
   "metadata": {},
   "outputs": [],
   "source": [
    "client = pymongo.MongoClient(f\"mongodb+srv://{username}:{password}@cluster0.lxsbb.mongodb.net/?retryWrites=true&w=majority\")\n",
    "db = client.medical_record\n",
    "collection = db[\"report\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "1bd8131e-0f2d-4bc1-8baa-a34d1b871524",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "4091c4d8-11b7-40e5-9400-22cbe47ac02b",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('./data/output/data.json', 'r') as fp:\n",
    "    data_json = json.load(fp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "c80b19ca-7d4e-4622-b457-60748ff90e4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Uncomment the line below.\n",
    "# collection.insert_many(data_json)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}