gpaasch commited on
Commit
ec7356b
·
1 Parent(s): b31399c

1. More structured query format focusing on ICD-10 codes

Browse files

2. Better parsing of diagnoses from response
3. Weighted confidence scores
4. Specific error handling
5. Focus on clinical differentiation

Files changed (1) hide show
  1. src/app.py +32 -16
src/app.py CHANGED
@@ -144,32 +144,48 @@ def process_speech(new_transcript, history):
144
  return history
145
 
146
  try:
147
- # Query the symptom index with user's transcript
148
- response = symptom_index.as_query_engine().query(
149
- f"""Based on this symptom description, list the top 2-3 most likely ICD-10 codes
150
- and key differentiating questions we should ask: {new_transcript}"""
151
- )
152
 
153
- # Parse the response and structure initial findings
154
- icd_codes = str(response).strip().split('\n')
155
- primary_diagnosis = icd_codes[0] if icd_codes else "Unknown"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
- # Structure a response that includes specific follow-up
158
  formatted_response = {
159
- "diagnoses": [primary_diagnosis],
160
- "confidences": [0.6], # Start with moderate confidence
161
- "follow_up": f"To differentiate between possible diagnoses, {icd_codes[1] if len(icd_codes) > 1 else 'please describe'}:"
162
  }
163
 
164
- # Add to conversation history
165
  history.append({"role": "user", "content": new_transcript})
166
  history.append({"role": "assistant", "content": json.dumps(formatted_response, indent=2)})
167
 
168
  except Exception as e:
 
169
  error_response = {
170
- "error": str(e),
171
- "status": "error",
172
- "transcript": new_transcript
173
  }
174
  history.append({"role": "user", "content": new_transcript})
175
  history.append({"role": "assistant", "content": json.dumps(error_response, indent=2)})
 
144
  return history
145
 
146
  try:
147
+ # First, get potential diagnoses based on symptoms
148
+ diagnosis_query = f"""
149
+ Given these symptoms: '{new_transcript}'
 
 
150
 
151
+ Identify the most likely ICD-10 diagnoses and key questions to differentiate between them.
152
+ Focus only on symptoms mentioned and their clinical implications.
153
+
154
+ Format response as:
155
+ 1. Primary suspected diagnosis: [ICD-10 code] - [description]
156
+ 2. Alternative diagnosis: [ICD-10 code] - [description]
157
+ 3. Key differentiating question
158
+ """
159
+
160
+ response = symptom_index.as_query_engine().query(diagnosis_query)
161
+
162
+ # Parse response into structured format
163
+ lines = str(response).strip().split('\n')
164
+ diagnoses = []
165
+ follow_up = ""
166
+
167
+ for line in lines:
168
+ if '[' in line and ']' in line: # Extract ICD-10 codes
169
+ code = line[line.find('[')+1:line.find(']')]
170
+ diagnoses.append(code)
171
+ elif 'Key differentiating question' in line:
172
+ follow_up = line.split(':')[-1].strip()
173
 
 
174
  formatted_response = {
175
+ "diagnoses": diagnoses[:2], # Top 2 diagnoses
176
+ "confidences": [0.7, 0.3] if len(diagnoses) > 1 else [0.7], # Weighted confidences
177
+ "follow_up": follow_up if follow_up else "What other symptoms are you experiencing?"
178
  }
179
 
 
180
  history.append({"role": "user", "content": new_transcript})
181
  history.append({"role": "assistant", "content": json.dumps(formatted_response, indent=2)})
182
 
183
  except Exception as e:
184
+ print(f"Error processing speech: {str(e)}")
185
  error_response = {
186
+ "diagnoses": ["Error processing symptoms"],
187
+ "confidences": [0],
188
+ "follow_up": "Could you please repeat your symptoms?"
189
  }
190
  history.append({"role": "user", "content": new_transcript})
191
  history.append({"role": "assistant", "content": json.dumps(error_response, indent=2)})