Update hedis_engine.py
Browse files- hedis_engine.py +15 -1
hedis_engine.py
CHANGED
|
@@ -130,14 +130,28 @@ class InteractiveHedisComplianceEngine:
|
|
| 130 |
# Remove any leading/trailing whitespace and newlines
|
| 131 |
result_str = result_str.strip()
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
# Try to parse as JSON
|
| 134 |
criteria_json = json.loads(result_str)
|
| 135 |
return criteria_json
|
| 136 |
except json.JSONDecodeError as e:
|
| 137 |
print(f"JSON parsing error: {e}")
|
| 138 |
print(f"Raw result: {repr(str(result))}")
|
|
|
|
| 139 |
# If not valid JSON, return as string
|
| 140 |
-
return {"raw_output": str(result)}
|
| 141 |
|
| 142 |
def display_criteria(self, criteria: dict) -> None:
|
| 143 |
"""Display the HEDIS criteria in a user-friendly format."""
|
|
|
|
| 130 |
# Remove any leading/trailing whitespace and newlines
|
| 131 |
result_str = result_str.strip()
|
| 132 |
|
| 133 |
+
# Remove surrounding quotes if the entire JSON is quoted
|
| 134 |
+
if len(result_str) >= 2 and result_str.startswith('"') and result_str.endswith('"'):
|
| 135 |
+
# Check if it's actually a quoted JSON string by trying to parse the unquoted version
|
| 136 |
+
try:
|
| 137 |
+
unquoted = result_str[1:-1]
|
| 138 |
+
# Handle escaped quotes in the JSON
|
| 139 |
+
unquoted = unquoted.replace('\\"', '"').replace('\\n', '\n')
|
| 140 |
+
test_parse = json.loads(unquoted)
|
| 141 |
+
result_str = unquoted
|
| 142 |
+
except:
|
| 143 |
+
# If unquoting fails, keep original
|
| 144 |
+
pass
|
| 145 |
+
|
| 146 |
# Try to parse as JSON
|
| 147 |
criteria_json = json.loads(result_str)
|
| 148 |
return criteria_json
|
| 149 |
except json.JSONDecodeError as e:
|
| 150 |
print(f"JSON parsing error: {e}")
|
| 151 |
print(f"Raw result: {repr(str(result))}")
|
| 152 |
+
print(f"Cleaned result: {repr(result_str)}")
|
| 153 |
# If not valid JSON, return as string
|
| 154 |
+
return {"raw_output": str(result), "parse_error": str(e)}
|
| 155 |
|
| 156 |
def display_criteria(self, criteria: dict) -> None:
|
| 157 |
"""Display the HEDIS criteria in a user-friendly format."""
|