Add files via upload
Upload notebook and sample data
This commit is contained in:
17
gp_referral_toolkit/patient_note.txt
Normal file
17
gp_referral_toolkit/patient_note.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
45F, fatigue and weight gain. Reports cold intolerance and constipation. No palpitations. Family history of thyroid disease.
|
||||
|
||||
---
|
||||
|
||||
56M, chest pain on exertion for 3 weeks. No SOB or nausea. Hypertension, diabetes. Family history of CAD.
|
||||
|
||||
---
|
||||
|
||||
22F, recurrent UTIs. Sexually active. No fever or flank pain. Normal renal function. History of E. coli positive urine cultures.
|
||||
|
||||
---
|
||||
|
||||
60M, progressive shortness of breath. Former smoker. Bilateral wheezing on auscultation. Awaiting spirometry. History of COPD.
|
||||
|
||||
---
|
||||
|
||||
32F, persistent headaches. Worse with stress. Normal neuro exam. No aura. Family history of migraines. Normal MRI last year.
|
||||
46
gp_referral_toolkit/referral_letter_bot.py
Normal file
46
gp_referral_toolkit/referral_letter_bot.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import openai
|
||||
|
||||
# Step 1: Summarize the patient consultation note
|
||||
def summarize_patient_note(note_text):
|
||||
response = openai.chat.completions.create(
|
||||
model="gpt-4o-mini",
|
||||
messages=[
|
||||
{"role": "user", "content": f"Please summarize the following patient consultation note in a clear, clinical style:\n\n{note_text}"}
|
||||
]
|
||||
)
|
||||
return response.choices[0].message.content
|
||||
|
||||
# Step 2: Generate a specialist referral letter
|
||||
def generate_referral_letter(summary_text, specialist_type):
|
||||
system_prompt = f"You are an experienced general practitioner. Based on the consultation summary, write a concise, professional referral letter to a {specialist_type}."
|
||||
|
||||
response = openai.chat.completions.create(
|
||||
model="gpt-4o-mini",
|
||||
messages=[
|
||||
{"role": "system", "content": system_prompt},
|
||||
{"role": "user", "content": f"Consultation summary:\n\n{summary_text}"}
|
||||
]
|
||||
)
|
||||
return response.choices[0].message.content
|
||||
|
||||
# Main logic
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
with open('patient_note.txt', 'r', encoding='utf-8') as file:
|
||||
patient_note = file.read()
|
||||
|
||||
# Step 1: Summarize the note
|
||||
summary = summarize_patient_note(patient_note)
|
||||
print("\n🩺 Consultation Summary:")
|
||||
print(summary)
|
||||
|
||||
# Step 2: Ask user which specialist to refer to
|
||||
specialist = input("\n➡️ Which specialist is this referral for (e.g., cardiologist, neurologist)?\n")
|
||||
|
||||
# Step 3: Generate the referral letter
|
||||
referral_letter = generate_referral_letter(summary, specialist)
|
||||
print("\n📨 Generated Referral Letter:\n")
|
||||
print(referral_letter)
|
||||
|
||||
except FileNotFoundError:
|
||||
print("❌ The file 'patient_note.txt' was not found. Please ensure it exists in the project folder.")
|
||||
Reference in New Issue
Block a user