Spaces:
Runtime error
Runtime error
Update MeatValidatorAgent.py
Browse files- MeatValidatorAgent.py +66 -0
MeatValidatorAgent.py
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MEATValidatorAgent:
|
| 3 |
+
def __init__(self, model: str = "gpt-4o"):
|
| 4 |
+
self.llm = ChatOpenAI(model=model, temperature=0)
|
| 5 |
+
|
| 6 |
+
self.agent = Agent(
|
| 7 |
+
role="MEAT Criteria Validator",
|
| 8 |
+
goal="Determine clinical status and validate MEAT criteria for confirmed diagnoses.",
|
| 9 |
+
backstory="You are a compliance and risk adjustment specialist who classifies diagnoses "
|
| 10 |
+
"into clinical status categories and validates MEAT criteria from chart documentation.",
|
| 11 |
+
verbose=True,
|
| 12 |
+
memory=False,
|
| 13 |
+
llm=self.llm,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def validate_one(self, diagnosis_entry: dict) -> dict:
|
| 17 |
+
"""Validate MEAT criteria for a diagnosis that is confirmed (answer=yes)."""
|
| 18 |
+
diagnosis = diagnosis_entry["diagnosis"]
|
| 19 |
+
icd10 = diagnosis_entry["icd10"]
|
| 20 |
+
context = diagnosis_entry["context"]
|
| 21 |
+
|
| 22 |
+
task = Task(
|
| 23 |
+
description=(
|
| 24 |
+
f"Diagnosis: {diagnosis} (ICD-10: {icd10})\n\n"
|
| 25 |
+
f"Patient chart excerpts:\n{context}\n\n"
|
| 26 |
+
"Determine:\n"
|
| 27 |
+
"A. Clinical Status: one of {ACTIVE, MONITORING, HISTORICAL}.\n"
|
| 28 |
+
"- ACTIVE: currently under treatment, ongoing management, or acute care\n"
|
| 29 |
+
"- MONITORING: surveillance visits, follow-up, observation\n"
|
| 30 |
+
"- HISTORICAL: past condition, no current clinical impact\n\n"
|
| 31 |
+
"B. MEAT Criteria Validation (Y/N for each):\n"
|
| 32 |
+
"- MONITOR: Are signs/symptoms being tracked?\n"
|
| 33 |
+
"- EVALUATE: Are test results or treatment responses reviewed?\n"
|
| 34 |
+
"- ASSESS: Did provider order tests or make clinical assessments?\n"
|
| 35 |
+
"- TREAT: Are therapeutic interventions documented?\n\n"
|
| 36 |
+
"Output must be strict JSON:\n"
|
| 37 |
+
"{'clinical_status': 'ACTIVE/MONITORING/HISTORICAL', "
|
| 38 |
+
"'meat': {'monitor': true/false, 'evaluate': true/false, 'assess': true/false, 'treat': true/false}, "
|
| 39 |
+
"'rationale': 'short justification'}"
|
| 40 |
+
),
|
| 41 |
+
expected_output="JSON with keys clinical_status, meat, rationale",
|
| 42 |
+
agent=self.agent,
|
| 43 |
+
json_mode=True,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
crew = Crew(agents=[self.agent], tasks=[task], process=Process.sequential, verbose=True)
|
| 47 |
+
result = crew.kickoff()
|
| 48 |
+
result = json.loads(repair_json(result))
|
| 49 |
+
|
| 50 |
+
return {
|
| 51 |
+
**diagnosis_entry,
|
| 52 |
+
"clinical_status": result.get("clinical_status"),
|
| 53 |
+
"meat": result.get("meat", {}),
|
| 54 |
+
"meat_rationale": result.get("rationale", "")
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
def run(self, confirmed_diagnoses: list[dict]) -> list[dict]:
|
| 58 |
+
"""Loop through all confirmed (yes) diagnoses and validate MEAT criteria."""
|
| 59 |
+
enriched_results = []
|
| 60 |
+
for entry in confirmed_diagnoses:
|
| 61 |
+
if entry.get("answer", "").lower() == "yes":
|
| 62 |
+
print(f"\n[INFO] Validating MEAT for: {entry['diagnosis']} ({entry['icd10']})")
|
| 63 |
+
enriched = self.validate_one(entry)
|
| 64 |
+
enriched_results.append(enriched)
|
| 65 |
+
print(f"[MEAT RESULT] {enriched}")
|
| 66 |
+
return enriched_results
|