{ "cells": [ { "cell_type": "code", "execution_count": 6, "id": "e0a3cde9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import openai\n", "from langchain_openai import ChatOpenAI, OpenAIEmbeddings\n", "import tiktoken\n", "from langchain.prompts.few_shot import FewShotPromptTemplate\n", "from langchain.prompts.prompt import PromptTemplate\n", "from operator import itemgetter\n", "from langchain.schema import StrOutputParser\n", "from langchain_core.output_parsers import StrOutputParser\n", "from langchain_core.runnables import RunnablePassthrough\n", "\n", "import langchain_community.embeddings.huggingface\n", "# help(langchain_community.embeddings.huggingface)\n", "from langchain_community.embeddings.huggingface import HuggingFaceBgeEmbeddings\n", "from langchain_community.vectorstores import FAISS\n", "\n", "from langchain.chains import LLMChain\n", "from langchain.chains.conversation.memory import ConversationBufferMemory, ConversationBufferWindowMemory, ConversationSummaryMemory, ConversationSummaryBufferMemory\n", "\n", "import os, dotenv\n", "from dotenv import load_dotenv\n", "load_dotenv()" ] }, { "cell_type": "code", "execution_count": 7, "id": "bf5aac26", "metadata": {}, "outputs": [], "source": [ "# embeddings = OpenAIEmbeddings(deployment=\"textembedding\", chunk_size = 16, api_key = os.environ[\"OPENAI_API_KEY\"])\n", "# index_name = \"SCLC\"\n", "\n", "model_name = \"bge-large-en-v1.5\"\n", "model_kwargs = {\"device\": \"cpu\"}\n", "# model_kwargs = {\"device\": \"cuda\"}\n", "encode_kwargs = {\"normalize_embeddings\": True}\n", "embeddings = HuggingFaceBgeEmbeddings(\n", " # model_name=model_name, \n", " model_kwargs = model_kwargs,\n", " encode_kwargs = encode_kwargs)\n", "\n", "index_name = \"indexes/ChestPainRubrics\"\n", "\n", "# store = FAISS.load_local(index_name, embeddings)\n", "import db_firestore as db\n", "store = db.get_store(index_name, embeddings=embeddings)" ] }, { "cell_type": "code", "execution_count": 42, "id": "2d75b44a", "metadata": {}, "outputs": [], "source": [ "TEMPLATE = \"\"\"You are a teacher for medical students. Your task is to provide an overall assessment of a student's diagnosis, based on the \n", "You will be provided with the following information:\n", "1. The rubrics that the student should be judged based upon.\n", "2. The conversation history between the medical student and the patient.\n", "3. The final diagnosis that the student will make.\n", "\n", "=================================================================\n", "\n", "Your task is as follows:\n", "1. Your grading should touch on every part of the rubrics, and grade the student holistically.\n", "Finally, provide an overall grade for the student.\n", "\n", "Some additional information that is useful to understand the rubrics:\n", "- The rubrics are segmented, with each area separated by dashes, such as \"----------\" \n", "- There will be multiple segments on History Taking. For each segment, the rubrics and corresponding grades will be provided below the required history taking.\n", "- For History Taking, you are to grade the student based on the rubrics, by checking the chat history between the patients and the medical student.\n", "- There is an additional segment on Presentation, differentials, and diagnosis. The \n", "\n", "\n", "=================================================================\n", "\n", "\n", "Here are the rubrics for grading the student:\n", "\n", "\n", "{context}\n", "\n", "\n", "\n", "=================================================================\n", "You are to give a comprehensive judgement based on the student's diagnosis, with reference to the above rubrics.\n", "\n", "Here is the chat history between the medical student and the patient:\n", "\n", "\n", "\n", "{history}\n", "\n", "\n", "=================================================================\n", "\n", "\n", "Student's final diagnosis:\n", "\n", " {question}\n", "\n", "\n", "=================================================================\n", "\n", "Your grade:\n", "\"\"\"\n", "\n", "prompt = PromptTemplate(\n", " input_variables = [\"question\", \"context\", \"history\"],\n", " template = TEMPLATE\n", ")\n", "retriever = store.as_retriever(search_type=\"similarity\", search_kwargs={\"k\":2})\n", "def format_docs(docs):\n", " return \"\\n--------------------\\n\".join(doc.page_content for doc in docs)\n", "\n", "\n", "llm = ChatOpenAI(model_name=\"gpt-3.5-turbo\", temperature=0)\n", "\n" ] }, { "cell_type": "code", "execution_count": 43, "id": "738e7e65", "metadata": {}, "outputs": [], "source": [ "\n", "# llm_gpt4 = ChatOpenAI(model_name=\"gpt-4-0125-preview\", temperature=0)\n", "llm_gpt4 = ChatOpenAI(model_name=\"gpt-4-1106-preview\", temperature=0)" ] }, { "cell_type": "markdown", "id": "bd14b945", "metadata": {}, "source": [ "## some code to generate the fake history easier" ] }, { "cell_type": "code", "execution_count": 10, "id": "e7fcc9e5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[]\n" ] } ], "source": [ "fake_history = []\n", "i = \" \"\n", "\n", "### Send no message to end it\n", "while i:\n", " i = input()\n", " if i:\n", " fake_history.append(i)\n", "\n", "print(fake_history)" ] }, { "cell_type": "code", "execution_count": 11, "id": "df09e0dc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "student: How are you mr tan?\n", "patient: I am not feeling well...\n", "student: oh, that's terrible! tell me more about what happened to you\n", "patient: well I got this chest pain\n", "student: I'm sorry to hear that. How long has your chest pain been?\n", "patient: I can't remember\n" ] } ], "source": [ "## Sample history:\n", "\n", "# fake_history = [\n", "# \"student: How are you mr tan?\",\n", "# \"patient: I am not feeling well...\",\n", "# \"student: oh, that's terrible! tell me more about what happened to you\",\n", "# \"patient: well I got this chest pain\",\n", "# \"student: I'm sorry to hear that. How long has your chest pain been?\",\n", "# \"patient: I can't remember\",\n", "# ]\n", "\n", "fake_history = \"\"\"\n", "student: How are you mr tan?\n", "patient: I am not feeling well...\n", "student: oh, that's terrible! tell me more about what happened to you\n", "patient: well I got this chest pain\n", "student: I'm sorry to hear that. How long has your chest pain been?\n", "patient: I can't remember\n", "\"\"\".strip().split(\"\\n\")\n", "\n", "for i in fake_history: print(i)" ] }, { "cell_type": "code", "execution_count": 44, "id": "72fd86fc", "metadata": {}, "outputs": [], "source": [ "fake_history = \"\"\"student: Are you okay?\n", "patient: No, I'm not okay.\n", "student: What happened to you\n", "patient: I suddenly had very bad chest pain that came suddenly.\n", "student: Oh no, that's terrible! tell me more about your chest pain?\n", "patient: I suddenly had very bad chest pain that came suddenly. It's a tearing pain and it radiates to my back. It started 1-2 hours ago this morning and hasn't improved.\n", "student: how bad is the pain, on a scale of 1 to 5?\n", "patient: The pain is a 4.\n", "student: did you have any history of chest pain in the past?\n", "patient: Yes, I had severe pain before due to cholangitis.\n", "student: how does it compare to that?\n", "patient: It's the same.\n", "student: how does it compare to that? is the pain worse?\n", "patient: Yes, the pain is worse.\n", "student: have you ever had any headaches before this?\n", "patient: No, I haven't had any headaches before this.\n", "student: how about fainting?\n", "patient: I fainted once.\n", "student: can you tell me more about that time you fainted?\n", "patient: I fainted once, but I didn't hit my head or anything.\n", "student: okay great... how about nausea? do you feel like vomiting?\n", "patient: No, I don't feel like vomiting.\n", "student: any blood in the poop?\n", "patient: No blood in poop.\n", "student: alright that's great! can I know if you have any pains anywhere else?\n", "patient: No, I don't have any other pains.\n", "student: So only head pain?\n", "patient: No, chest pain too.\n", "student: ok. let me take a look at your skin. do you have rashes?\n", "patient: No, I don't have rashes.\n", "student: did you get the flu recently? any fever or cough so far?\n", "patient: No, I didn't get the flu recently. No fever or cough.\n", "student: good. Can I know a bit more about your health history?\n", "patient: I have high blood pressure, high cholesterol, and type 2 diabetes. I also had gallstones and biliary colic. I was recently hospitalized for acute cholangitis and had a procedure to remove the stones. My father had a heart attack, and my mother had a collagen tissue disorder.\n", "student: that's very detailed, thank you! do you have any allergies?\n", "patient: No, I don't have any allergies.\n", "student: great. what medication are you taking now for the high blood pressure and cholestrol?\n", "patient: I take Enalapril for high blood pressure and Rosuvastatin for cholesterol.\n", "student: do you take them regularly?\n", "patient: No, I'm not good at taking them regularly.\n", "student: can you tell me what are the doses, and when do you take them?\n", "patient: I don't know the doses or when to take them.\n", "student: that's not good! you should take them at regular intervals okay?\n", "patient: Okay, I will take them regularly.\n", "student: other than these medication, do you take anything else?\n", "patient: No, I don't take anything else.\n", "student: for diabetes?\n", "patient: Yes, I have diabetes.\n", "student: what medication do you take for diabetes?\n", "patient: Metformin.\n", "student: do you smoke?\n", "patient: Yes, I smoke.\n", "student: ok, how many packets do you usually smoke a day?\n", "patient: I smoke 10 sticks a day.\n", "student: smoking for how long already?\n", "patient: 30 years.\n", "student: any sexual activity? STDs?\n", "patient: No recent sexual activity. No STDs.\n", "student: ok. how about your parents? do they have history of chest pains as well\n", "patient: Yes, both parents have chest pains.\n", "student: ok, I will write you some medication for your pain. You wait here first okay?\n", "patient: Okay, thank you.\"\"\"" ] }, { "cell_type": "code", "execution_count": 45, "id": "e6e21890", "metadata": {}, "outputs": [], "source": [ "## RESET MEMORY\n", "## To reset the memory (if it screws up), rerun this cell\n", "memory = ConversationSummaryBufferMemory(llm=llm, memory_key=\"chat_history\", input_key=\"question\" )\n", "\n", "def x(_): \n", " return fake_history\n", "chain = (\n", " {\n", " \"context\": retriever | format_docs, \n", " \"history\": x,\n", " \"question\": RunnablePassthrough(),\n", " } | \n", "\n", " # prompt # | \n", " LLMChain(llm=llm, prompt=prompt, memory=memory, verbose=True) #|\n", " # LLMChain(llm=llm_gpt4, prompt=prompt, memory=memory, verbose=True) #| ## GPT4\n", " \n", " # StrOutputParser()\n", ")" ] }, { "cell_type": "code", "execution_count": 46, "id": "f443e8c7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\u001b[1m> Entering new LLMChain chain...\u001b[0m\n", "Prompt after formatting:\n", "\u001b[32;1m\u001b[1;3mYou are a teacher for medical students. Your task is to provide an overall assessment of a student's diagnosis, based on the \n", "You will be provided with the following information:\n", "1. The rubrics that the student should be judged based upon.\n", "2. The conversation history between the medical student and the patient.\n", "3. The final diagnosis that the student will make.\n", "\n", "=================================================================\n", "\n", "Your task is as follows:\n", "1. Your grading should touch on every part of the rubrics, and grade the student holistically.\n", "Finally, provide an overall grade for the student.\n", "\n", "Some additional information that is useful to understand the rubrics:\n", "- The rubrics are segmented, with each area separated by dashes, such as \"----------\" \n", "- There will be multiple segments on History Taking. For each segment, the rubrics and corresponding grades will be provided below the required history taking.\n", "- For History Taking, you are to grade the student based on the rubrics, by checking the chat history between the patients and the medical student.\n", "- There is an additional segment on Presentation, differentials, and diagnosis. The \n", "\n", "\n", "=================================================================\n", "\n", "\n", "Here are the rubrics for grading the student:\n", "\n", "\n", " \n", "Diagnosis: Aortic Dissection \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", "History taking: Presenting complaint \n", "● Volunteered information: “I suddenly had this very bad chest pain that came suddenly.” \n", "● Explores history of chest pain \n", "o Site: central, diffuse \n", "o Onset: started 1 -2 hours ago this morning. No particular trigger, happened very suddenly while I \n", "was at home. \n", "o Character: acute tearing pain \n", "o Radiation: To the back \n", "o Duration: 1 -2 hours, rushed by family to hospital \n", "o Severity: onset 10/10, not improving \n", "o Associated symptoms: (1) diaphoresis; (2) some breathlessness (not excessive) (3) syncope, one \n", "episode while at home calling for help; (4) dysarthria, family noted his speech was unclear when \n", "shouting for help \n", "o Exacerbating or relieving factors: NIL \n", "o Timing: Does not occur in relation to meals or exertion, no triggers \n", "o Episodes: previously experienced severe pain also due to cholangitis, unsure if it is a repeat but \n", "this pain seems worse \n", "● Looks for red flags \n", "o Severity of pain and acuity of onset \n", "o Makes an attempt to ask questions TRO the big 6 causes of chest pain \n", "o Associated symptoms that come with the pain (mentioned above, specifically pertaining to the \n", "neurologic symptoms that came with the pain: syncope, dysarthria) \n", " \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", "Rubrics \n", "Grade A : Elicits all of the above points in detail \n", "Grade B : Explores both presenting complaints in almost full detail and rules out red flags \n", "Grade C : Explores both presenting complaints incompletely and looks out for red flags \n", "Grade D : Explores both presenting complaints incompletely but does not rule out any red flags/ explores one \n", "complaint and rules out at least one red flag \n", "Grade E : Only explores one of the two presenting complaints \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", " \n", " \n", "History taking: Associated symptoms \n", "● CVM : chest pain, diaphoresis, some dyspnoea, NIL LL swelling \n", "● Neuro : \n", "o Syncope (one episode), dysarthria \n", "o NIL headaches or vision changes \n", "o NIL weakness or numbness \n", "o NIL head trauma/falls (did not sustain injury during syncopal episode) \n", "● Gastro : \n", "o NIL nausea or vomiting \n", "o NIL abdo pain \n", "o NIL changes to bowel habit or blood in stool, constipation or diarrhoea \n", "● Respi : \n", "o Some breathlessness, not excessive \n", "o NIL cough or haemoptysis \n", "● Renal/Uro : \n", "o NIL urinary Sx - dysuria, haematuria \n", "● MSK/Derm \n", "o NIL joint or muscle pains \n", "o NIL rash or skin changes \n", "● Constitutional : NIL fever, weight loss, loss of appetite, night sweats \n", "----------------------------------------------------------------------------------------------------------------------------- ---------------------- \n", "Rubrics \n", "Grade A : Explores all (5) of the above systems in detail and elicits all * (8) points \n", "Grade B: Explores most (4) of the above systems and elicits all (8) * points \n", "Grade C: Explores most (4) of the above systems and elicits most (4 -7) * points \n", "Grade D: Explores more than half (3) of the above systems and elicits most (4 -7) * points \n", "Grade E: Explores only 1 -2 of the above systems or asks less than half (1 -3) * points \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", " \n", " \n", "History taking: Others \n", "● PMHx/Shx * \n", "o HTN, HLD, T2DM, diagnosed 7 years ago, poorly compliant with meds \n", "o History of biliary colic and gallstones, diagnosed 2 years ago \n", "o Recent hospitalisation and procedure done \n", "▪ Acute cholangitis 1 month ago, s/p ERCP for stone removal, NIL complications intra op or \n", "post op \n", "o No previous chest pain of similar severity \n", "● Drug Hx , NKDA * \n", "o Enalapril for HTN, Rosuvastatin for HLD, metformin for T2DM, misses doses, poorly compliant, unsure \n", "which one and time to take, lazy to check and feels he is ‘ok so far’ \n", "o Does not measure home BP or blood sugar \n", "o NIL vitamins, supplements, TCM or OTC pills \n", "● Family history * \n", "o Father: Acute coronary syndrome (STEMI) at 50 years old, underwent PCI and stent \n", "o Mother: Some collagen tissue disorder, not sure what it was \n", "o Both parents have HTN and HLD, well controlled \n", "● Social history * \n", "o Smoker, 10 sticks a day for the past 30 years \n", "o Drinker, can of beer every dinner and weekend binge drinking with friends \n", "o Diet, normally likes eating char kuay teow or fried carrot cake, doesn’t take much fruits or \n", "vegetables \n", "o Occupation: Retired, former taxi driver \n", "o NIL exercise \n", "o Sexual hx unremarkable \n", "o NIL recent travel \n", "● Ideas, concerns and expectations \n", "o Worried if he is having a heart attack, scared because his father had one \n", "o Wants the pain to stop \n", " \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", "Rubrics \n", "Grade A : Elicits all (5) of the * points and travel & family history in detail \n", "Grade B: Elicits all (5) of the * points and travel & family history, but did not go into important details in \n", "Grade C: Elicits most (2 -4) of the * points and travel & family history in adequate detail \n", "Grade D: Elicits most (2 -4) of the * points and travel & family history but not in detail \n", "Grade E: Elicits 0 -1 of the * points or did not take a travel & family history (not taking a alcohol & family history \n", "will give the candidate this score for the domain) \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", " \n", " \n", "Presentation of findings, diagnosis and \n", "differentials \n", "● Findings: This is a 65 year old gentleman who presents with an acute onset* of a severe tearing chest pain \n", "that was maximal on onset and radiates to the back* . This was associated with diaphoresis*, one episode of \n", "syncope*, dysarthria* and some breathlessness*. \n", "● The patient has a history of poorly controlled hypertension*, hyperlipidaemia* diabetes*, and biliary colic \n", "and gallstones . He was recently admitted for an episode of acute cholangitis one month ago for which he \n", "underwent ERCP . \n", "● His family history is also significant for cardiovascular risk factors in both parents, and a history of acute \n", "coronary syndrome in his father, and possible connective tissue disease in his mother. \n", "● Significant negatives include no severe dyspnoea/hypoxia/features of respiratory distress*, no pleuritic chest \n", "pain*, no recent trauma or violent vomiting . \n", " \n", "Differentials \n", " \n", "1) Aortic dissection \n", "● Intensity of pain on onset, radiation to back, quality described as tearing pain. When all 3 features \n", "present, 91% accuracy in making diagnosis of dissection \n", "● Risk factors: HTN, smoking, ?connective tissue disease in mother \n", "● Chest pain associated with neurologic symptoms: Syncope, CN deficits (dysarthria) \n", " \n", "2) Acute coronary syndrome \n", "● Patient is a vasculopath with known CVRF (smoking, HTN, HLD, DM) \n", "● Strong family history (father had ACS) and both parents are vasculopaths \n", "● Severe chest pain accompanied by diaphoresis and some dyspnoea \n", "● Poorly compliant with his chronic meds and unhealthy diet \n", " \n", "3) Acute pancreatitis \n", "● Severe pain radiating to back \n", "● History of gallstones, ERCP for cholangitis and heavy alcohol consumption \n", "○ Could be gallstone pancreatitis, ERCP pancreatitis, or due to alcohol abuse \n", "● Less likely as no nausea and vomiting, pain character is described as tearing also, and other stronger \n", "supportive features for aortic dissection \n", " \n", "Other less likely differentials \n", "- From the big 6 causes of chest pain (ACS and aortic dissection already covered) \n", "- Pneumothorax and PE less likely as the chest pain is not pleuritic, and the patient is not \n", "excessively dyspnoeic/hypoxic \n", "- Cardiac tamponade: Possible but less likely and given stronger supportive features for the \n", "main 3 differentials mentioned above \n", "- Oesophageal rupture: No history of violent vomiting \n", "- Less serious acute causes of chest pain \n", "- Stable angina, myocarditis, pericarditis, pneumonia, cholecystitis (possible since he has a \n", "history of gallstones but much less likely due to severity, location, character and radiation of \n", "pain) \n", " \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", "Rubrics \n", "Grade A : Presents all (3) of the * points, has SAH, meningitis and migraine as top differentials with justification, \n", "and at least one other differentials with adequate justification \n", "Grade B: Presents most (2 -3) of the * points, has SAH and meningitis as top differentials but inadequate \n", "justification \n", "Grade C: Presents most (2 -3) of the * points, has either SAH or meningitis as top differential with at least one \n", "other differential \n", "Grade D: Presents most (2 -3) of the *points OR only able to have 1 diagnosis without differential diagnosis \n", "Grade E: Presents few (0 -1) of * points OR unable to have any diagnosis or differentials \n", "----------------------------------------------------------------------------------------------------------------------------- --------- \n", " \n", "\n", "\n", "\n", "\n", "=================================================================\n", "You are to give a comprehensive judgement based on the student's diagnosis, with reference to the above rubrics.\n", "\n", "Here is the chat history between the medical student and the patient:\n", "\n", "\n", "\n", "student: Are you okay?\n", "patient: No, I'm not okay.\n", "student: What happened to you\n", "patient: I suddenly had very bad chest pain that came suddenly.\n", "student: Oh no, that's terrible! tell me more about your chest pain?\n", "patient: I suddenly had very bad chest pain that came suddenly. It's a tearing pain and it radiates to my back. It started 1-2 hours ago this morning and hasn't improved.\n", "student: how bad is the pain, on a scale of 1 to 5?\n", "patient: The pain is a 4.\n", "student: did you have any history of chest pain in the past?\n", "patient: Yes, I had severe pain before due to cholangitis.\n", "student: how does it compare to that?\n", "patient: It's the same.\n", "student: how does it compare to that? is the pain worse?\n", "patient: Yes, the pain is worse.\n", "student: have you ever had any headaches before this?\n", "patient: No, I haven't had any headaches before this.\n", "student: how about fainting?\n", "patient: I fainted once.\n", "student: can you tell me more about that time you fainted?\n", "patient: I fainted once, but I didn't hit my head or anything.\n", "student: okay great... how about nausea? do you feel like vomiting?\n", "patient: No, I don't feel like vomiting.\n", "student: any blood in the poop?\n", "patient: No blood in poop.\n", "student: alright that's great! can I know if you have any pains anywhere else?\n", "patient: No, I don't have any other pains.\n", "student: So only head pain?\n", "patient: No, chest pain too.\n", "student: ok. let me take a look at your skin. do you have rashes?\n", "patient: No, I don't have rashes.\n", "student: did you get the flu recently? any fever or cough so far?\n", "patient: No, I didn't get the flu recently. No fever or cough.\n", "student: good. Can I know a bit more about your health history?\n", "patient: I have high blood pressure, high cholesterol, and type 2 diabetes. I also had gallstones and biliary colic. I was recently hospitalized for acute cholangitis and had a procedure to remove the stones. My father had a heart attack, and my mother had a collagen tissue disorder.\n", "student: that's very detailed, thank you! do you have any allergies?\n", "patient: No, I don't have any allergies.\n", "student: great. what medication are you taking now for the high blood pressure and cholestrol?\n", "patient: I take Enalapril for high blood pressure and Rosuvastatin for cholesterol.\n", "student: do you take them regularly?\n", "patient: No, I'm not good at taking them regularly.\n", "student: can you tell me what are the doses, and when do you take them?\n", "patient: I don't know the doses or when to take them.\n", "student: that's not good! you should take them at regular intervals okay?\n", "patient: Okay, I will take them regularly.\n", "student: other than these medication, do you take anything else?\n", "patient: No, I don't take anything else.\n", "student: for diabetes?\n", "patient: Yes, I have diabetes.\n", "student: what medication do you take for diabetes?\n", "patient: Metformin.\n", "student: do you smoke?\n", "patient: Yes, I smoke.\n", "student: ok, how many packets do you usually smoke a day?\n", "patient: I smoke 10 sticks a day.\n", "student: smoking for how long already?\n", "patient: 30 years.\n", "student: any sexual activity? STDs?\n", "patient: No recent sexual activity. No STDs.\n", "student: ok. how about your parents? do they have history of chest pains as well\n", "patient: Yes, both parents have chest pains.\n", "student: ok, I will write you some medication for your pain. You wait here first okay?\n", "patient: Okay, thank you.\n", "\n", "\n", "=================================================================\n", "\n", "\n", "Student's final diagnosis:\n", "\n", " \n", "From the sudden chest pain, it is likely it's aortic dissection. The radiation and intensity signifies it. \n", "Also possible to be acute pancreatitis, since there's back pain, and history of problems.\n", "Doubtful it's oesophageal rupture, since there was no vomiting or nausea. \n", "\n", "\n", "\n", "=================================================================\n", "\n", "Your grade:\n", "\u001b[0m\n", "\n", "\u001b[1m> Finished chain.\u001b[0m\n", "Based on the rubrics provided, here is the assessment of the student's performance:\n", "\n", "History taking: Presenting complaint\n", "Grade: B\n", "The student explored the presenting complaint of chest pain in detail, including the site, onset, character, radiation, duration, severity, and associated symptoms. However, the student did not ask about exacerbating or relieving factors, timing, or previous episodes of similar pain. The student also did not ask about red flags such as the severity of pain and acuity of onset or the big 6 causes of chest pain.\n", "\n", "History taking: Associated symptoms\n", "Grade: C\n", "The student explored most of the associated symptoms in detail, including cardiovascular, neurological, gastrointestinal, respiratory, renal/urological, musculoskeletal/dermatological, and constitutional symptoms. However, the student did not ask about headaches or vision changes, weakness or numbness, urinary symptoms, joint or muscle pains, rash or skin changes, or fever, weight loss, loss of appetite, or night sweats.\n", "\n", "History taking: Others\n", "Grade: C\n", "The student obtained a detailed past medical and surgical history, including hypertension, hyperlipidemia, type 2 diabetes, biliary colic and gallstones, recent hospitalization and procedure for acute cholangitis, and medication history. However, the student did not ask about the patient's drug allergies or measure home blood pressure or blood sugar. The student also obtained a detailed family history, including a father with acute coronary syndrome and a mother with a collagen tissue disorder. The student obtained a social history, including smoking, alcohol consumption, diet, occupation, exercise, and sexual history. The student also explored the patient's ideas, concerns, and expectations.\n", "\n", "Presentation of findings, diagnosis, and differentials\n", "Grade: B\n", "The student presented the findings of a 65-year-old gentleman with an acute onset of severe tearing chest pain that radiates to the back, associated with diaphoresis, syncope, dysarthria, and some breathlessness. The student also presented the patient's medical history, including poorly controlled hypertension, hyperlipidemia, diabetes, and biliary colic and gallstones, as well as recent hospitalization and procedure for acute cholangitis. The student mentioned the patient's family history of cardiovascular risk factors and acute coronary syndrome in the father and possible connective tissue disease in the mother. The student also mentioned the absence of severe dyspnea/hypoxia or pleuritic chest pain and recent trauma or violent vomiting. The student provided three differentials: aortic dissection, acute coronary syndrome, and acute pancreatitis, and mentioned other less likely differentials.\n", "\n", "Overall grade: B\n", "The student demonstrated good performance in history taking, exploring the presenting complaint and associated symptoms in detail. However, there were some gaps in exploring red flags and other aspects of the history. The student also presented the findings, diagnosis, and differentials adequately, but with some room for improvement in providing more detailed justifications for the differentials.\n", "\n", "Overall, the student's performance is commendable, but there is room for improvement in certain areas. The student's grade is a B.\n" ] } ], "source": [ "diagnosis = \"\"\"\n", "From the sudden chest pain, it is likely it's aortic dissection. The radiation and intensity signifies it. \n", "Also possible to be acute pancreatitis, since there's back pain, and history of problems.\n", "Doubtful it's oesophageal rupture, since there was no vomiting or nausea. \n", "\"\"\"\n", "\n", "results = chain.invoke(diagnosis)\n", "print(results.get(\"text\"))" ] }, { "cell_type": "code", "execution_count": 48, "id": "b2093b18", "metadata": {}, "outputs": [], "source": [ "# print(results.text)" ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 5 }