Spaces:
Build error
Build error
| import gradio as gr | |
| from openai import OpenAI | |
| import os | |
| prompt_text = \ | |
| """I want you to act as an attending physician giving immediate, specific, and actionable feedback to a Community Health Worker (CHEW) based on the SOAP note they created. Your response will guide the CHEW, who is currently with the patient, so focus on concise, high-priority advice. | |
| ### Key Instructions: | |
| 1. **SOAP Note Context**: This SOAP note was created at an urgent care clinic in Nigeria. Include data from today’s clinic visit as well as historical patient-reported data (e.g., recent fever or symptoms reported earlier) when considering patient symptoms. | |
| 2. **CHEW Capabilities**: Keep in mind the CHEW’s limited physical exam training. Suggest only basic inspection, palpation, or vital sign checks. | |
| 3. **Clinic Constraints**: Recommendations must align with the clinic’s capabilities, focusing on the following: | |
| - **Available Testing**: Malaria RDT, Typhoid RDT, PCV, Pregnancy Test, Urine Dipstick, H. Pylori, HIV Confirmatory Test (ELFA). | |
| - **No Imaging**: Avoid suggestions for imaging, ultrasound, or other unavailable diagnostics. | |
| - **Avoid Low-Value Care**: Recommend tests only when they are critical to the diagnosis or treatment. | |
| 4. **Disease-Specific Treatment Recommendations**: Follow these clinic-specific guidelines: | |
| - **Malaria**: | |
| - Only test if fever cannot be explained by other causes (e.g., upper respiratory infection, UTI). | |
| - Treat only if malaria RDT is positive. Use oral ACT for 3 days or injectable ACT if oral therapy isn’t possible. | |
| - **Typhoid**: | |
| - Test only if fever lasts ≥3 days and is accompanied by abdominal pain, diarrhea, or constipation. | |
| - Treat positive cases with oral Ciprofloxacin or Azithromycin for 5 days. | |
| - **H. Pylori**: | |
| - Test if gastritis symptoms persist >3 weeks or recur after antacid/PPI treatment. | |
| - Treat positive cases with triple therapy. | |
| - **Anemia**: | |
| - Test if fatigue, exertional shortness of breath, dizziness, or lack of energy is chronic. | |
| - Treat positive cases with oral iron for 3 months. | |
| - **Hypertension**: Address only if associated with signs of severe cardiac conditions, as it is a low priority. | |
| 5. **Feedback Scope**: Consider giving advice in the following categories: | |
| - **Feedback on diagnosis**: Note inconsistencies, overlooked possibilities, or any inaccurate reasoning. | |
| - **Feedback on treatment plan**: Identify errors, such as inappropriate antibiotics, or suggest improvements. | |
| - **Assessment of risk**: Highlight potential for serious conditions based on symptoms. | |
| - **Test recommendations**: Suggest needed tests and flag unnecessary ones. | |
| - **Additional Diagnostic Questions**: Suggest additional questions the CHEW could ask the patient to better diagnose or treat them. For each question, provide guidance on how to interpret the possible answers and specify the recommended actions based on those answers. | |
| 6. **Brevity**: Your feedback must be clear, concise, and actionable. The ideal response is 2 or 3 short, direct, actionable sentences. | |
| ### Patient Record: | |
| """ | |
| soap_note_1 = \ | |
| """ASSESSMENT | |
| Diagnosis | |
| Typhoid fever, Unspecified malaria | |
| Differential Diagnosis | |
| Typhoid fever, Unspecified malaria | |
| PLAN | |
| Treatment plan | |
| Comments: | |
| Request to do mRDT, Salmonella. | |
| PLAN A | |
| Tabs Paracetamol 1g tds for 3 days. | |
| If Malaria is positive add | |
| Tabs ACT IV bd for 3 days. | |
| If Salmonella is positive add | |
| Tabs ciproflaxacin 500mg bd for 5 days. | |
| Advice and counselling against anxiety. | |
| Advice on sleeping under mosquitoes nets. | |
| If the symptoms still persist refer to Medical officer. | |
| Exhaustive list of Investigations Ordered | |
| Salmonella Test (Immunochromatography) (done) | |
| Malaria Parasite - RDT(Reach Clinics) (done) | |
| SUBJECTIVE | |
| AGE | |
| 25y | |
| Gender | |
| female | |
| Chief Complaint | |
| inability to fall asleep and headache for the past 2 week | |
| History of presenting Illness (HPI) | |
| The patient present with the complain of inability to fall a sleep and also having interrupted sleeping for the past 2 weeks, there is associated headache for 2 days. there is also poor appetite and feverish for 1 days. There is no history of fever, no vomiting or nausea. There is sometimes body pain, there is no abdominal pain no diarrhea. There is no history of recent travelling or coming in contact with any suspected persons. The patient said they had some family issues some days back. | |
| Medical History | |
| The patient is known peptic ulcer diseases, but not hypertension or diabetic. | |
| OBJECTIVE | |
| Review of Systems | |
| There is no problems associated to input and out put, there is no changes in urine color or volume, there is no blood in the stool. | |
| Physical Examination | |
| The patient is conscious, afebrile, not pale and not dehydrated. | |
| on examination there is no abdominal tenderness, no distension no any sign of organ enlargement. | |
| Vital Signs | |
| Blood pressure(108/73 mm[Hg]) | |
| Temperature(36.1°C) | |
| Anthropometry | |
| Height(157 cm) Weight(45 kg) BMI(18.3 kg/m2) | |
| """ | |
| soap_note_2 = \ | |
| """ASSESSMENT | |
| Diagnosis | |
| Peptic ulcer, site unspecified | |
| Differential Diagnosis | |
| Peptic ulcer, site unspecified | |
| PLAN | |
| Treatment plan | |
| To do mRDT and H pylori | |
| If all the laboratory investigation reveals positive give | |
| * Caps Omeprazole 20 mg bd 5/7 | |
| * Tabs Paracetamol 1 grm tds 3/7 | |
| * Caps Amoxicillin 500mg tds 5/7 | |
| * Susp Acipep 10mls tds 5/7 | |
| Health educate the patient on precautionary measures against Peptic Ulcer disease | |
| SUBJECTIVE | |
| AGE | |
| 49y | |
| Gender | |
| female | |
| Chief Complaint | |
| Chest Pain And Headache | |
| History of presenting Illness (HPI) | |
| Patient seen with the complain of chest pain and headache, associated with body malaise and fatigue for 2/52, the chest pain are associated with difficulty in breathing for 2/52 | |
| Medical History | |
| A known Peptic Ulcer Disease patient | |
| Not a known Hypertensive patient | |
| not a known Diabetic patient | |
| Not a known SCD patient, | |
| Gynaecology Summary | |
| Gravida 7, Para 7, | |
| Four children a life, | |
| There children die, | |
| OBJECTIVE | |
| Review of Systems | |
| No coughing, no Vomiting. there Headache, no palpitations no Dyspnea | |
| Physical Examination | |
| Patient is chronically ill looking not dehydrated and the conjunctiva is normal not pale, no abdominal tenderness and distention, | |
| Vital Signs | |
| Blood pressure(80/50 mm[Hg]) | |
| Temperature(36.7°C) | |
| Anthropometry | |
| Height(172 cm) Weight(67 kg) BMI(22.6 kg/m2) | |
| """ | |
| soap_note_3 = \ | |
| """ASSESSMENT | |
| Diagnosis | |
| Disorders of initiating and maintaining sleep [insomnias], Non-insulin-dependent diabetes mellitus: With unspecified complications | |
| Differential Diagnosis | |
| Non-insulin-dependent diabetes mellitus: With unspecified complications, Disorders of initiating and maintaining sleep [insomnias] | |
| PLAN | |
| Treatment plan | |
| Comment:- | |
| To do FBS/RBS and URINALYSIS | |
| PLAN A | |
| If the RBS/FBS/ and URINALYSIS is not within the normal range REFER Immediately to specialist. | |
| PLAN B | |
| If the RBS/FBS/ and URINALYSIS is normal take:- | |
| Continue adherence and compliance with Diabetic medications, Dietary modifications and Exercise. | |
| Tabs Ibuprofen 400mg bd for 3 days. | |
| Tabs Metformin 500mg bd for 2 weeks. | |
| Tabs Glibenclamide 5mg bd for 2 weeks. | |
| SUBJECTIVE | |
| AGE | |
| 54y | |
| Gender | |
| female | |
| Chief Complaint | |
| Insomnia And Bilateral Leg Ache. | |
| History of presenting Illness (HPI) | |
| The patient present with the complain of insomnia for over a week and constant bilateral legs pain that start from the gluteal region and radiates to the soles of the legs for over 2 years, the pain used to reduce only during sleeping period. there is chest pain and headache, dizziness, and nausea. there is also palpitation. | |
| Medical History | |
| The patient is known diabetic but not Hypertension. | |
| OBJECTIVE | |
| Review of Systems | |
| the blood pressure is normal, but the patient is overweight. | |
| Physical Examination | |
| the patient is conscious not pale not dehydrated, there is no pedal edema , no any difficulty in moving the extremities and there is no problem with reflexes. | |
| Vital Signs | |
| Blood pressure(120/82 mm[Hg]) | |
| Temperature(36.8°C) | |
| Anthropometry | |
| Height(159 cm) Weight(76 kg) BMI(30.1 kg/m2) | |
| """ | |
| client = OpenAI( | |
| api_key=os.environ['API_TOKEN'] | |
| ) | |
| def process(a, b): | |
| response = client.chat.completions.create( | |
| model="o1-mini-2024-09-12", | |
| messages=[ | |
| {"role": "user", "content": f"{a}\n{b}"} | |
| ] | |
| ) | |
| out = response.choices[0].message.content | |
| return out | |
| def set_txt1_text0(): | |
| return prompt_text | |
| # Functions for populating txt2 | |
| def set_txt2_text1(): | |
| return soap_note_1 | |
| def set_txt2_text2(): | |
| return soap_note_2 | |
| def set_txt2_text3(): | |
| return soap_note_3 | |
| with gr.Blocks() as iface: | |
| # Layout | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| txt1 = gr.Textbox(label='Prompt', lines=8, value="") | |
| txt2 = gr.Textbox(label='SOAP note', lines=8, value="") | |
| submit = gr.Button("Submit", variant='primary') | |
| button0 = gr.Button("Default Prompt") | |
| button1 = gr.Button("SOAP Note 1 (Malaria/Typhoid)") | |
| button2 = gr.Button("SOAP Note 2 (Ulcer)") | |
| button3 = gr.Button("SOAP Note 3 (Insomnia)") | |
| with gr.Column(scale=1): | |
| out_txt = gr.Textbox(label='ChatGPT\'s Response', placeholder='Click the "Submit" button to see Chat GPT\'s response', lines=10, interactive=False) | |
| # Button click handlers | |
| button0.click(fn=set_txt1_text0, outputs=txt1) | |
| button1.click(fn=set_txt2_text1, outputs=txt2) | |
| button2.click(fn=set_txt2_text2, outputs=txt2) | |
| button3.click(fn=set_txt2_text3, outputs=txt2) | |
| # Submit button click handler | |
| submit.click(fn=process, inputs=[txt1, txt2], outputs=[out_txt]) | |
| iface.launch() | |