Cardiosense-AG commited on
Commit
b1d646e
·
verified ·
1 Parent(s): e60b419

Update src/store.py

Browse files
Files changed (1) hide show
  1. src/store.py +12 -21
src/store.py CHANGED
@@ -14,15 +14,15 @@ def _rand(n=4) -> str:
14
  alphabet = string.ascii_uppercase + string.digits
15
  return ''.join(secrets.choice(alphabet) for _ in range(n))
16
 
17
- def new_case_id() -> str:
18
- return f"EC-{time.strftime('%Y%m%d-%H%M%S')}-{_rand()}"
19
-
20
  def case_path(case_id: str) -> Path:
21
  return cases_dir() / f"{case_id}.json"
22
 
 
 
 
23
  def _deep_merge(a: Dict[str, Any], b: Dict[str, Any]) -> Dict[str, Any]:
24
  out = dict(a)
25
- for k, v in b.items():
26
  if isinstance(v, dict) and isinstance(out.get(k), dict):
27
  out[k] = _deep_merge(out[k], v)
28
  else:
@@ -30,22 +30,9 @@ def _deep_merge(a: Dict[str, Any], b: Dict[str, Any]) -> Dict[str, Any]:
30
  return out
31
 
32
  def _migrate_soup_to_soap(obj: Dict[str, Any]) -> Dict[str, Any]:
33
- """If an older case has 'soup_draft', migrate it to 'soap_draft' (Uncertainties→Assessment)."""
34
- if "soap_draft" in obj:
35
- return obj
36
- if "soup_draft" in obj:
37
- sd = obj.get("soup_draft") or {}
38
- obj["soap_draft"] = {
39
- "subjective": sd.get("subjective",""),
40
- "objective": sd.get("objective",""),
41
- "assessment": sd.get("uncertainties",""), # map old key
42
- "plan": sd.get("plan",""),
43
- "citations": sd.get("citations", []),
44
- }
45
- # keep the old for safety, or uncomment next line to remove:
46
- # obj.pop("soup_draft", None)
47
- else:
48
- obj["soap_draft"] = {"subjective":"", "objective":"", "assessment":"", "plan":"", "citations":[]}
49
  return obj
50
 
51
  def list_cases(status: Optional[str] = None) -> List[Dict[str, Any]]:
@@ -75,6 +62,9 @@ def read_case(case_id: str) -> Optional[Dict[str, Any]]:
75
  try:
76
  obj = json.loads(p.read_text())
77
  obj = _migrate_soup_to_soap(obj)
 
 
 
78
  return obj
79
  except Exception:
80
  return None
@@ -106,7 +96,6 @@ def create_case(initial: Dict[str, Any]) -> Dict[str, Any]:
106
  "pcp_attests": False,
107
  "specialist_attests": False
108
  },
109
- "triage": {},
110
  "soap_draft": { # <-- SOAP by default
111
  "subjective": "",
112
  "objective": "",
@@ -118,6 +107,7 @@ def create_case(initial: Dict[str, Any]) -> Dict[str, Any]:
118
  }
119
  obj = _deep_merge(obj, initial or {})
120
  obj = _migrate_soup_to_soap(obj)
 
121
  save_case(obj)
122
  return obj
123
 
@@ -129,3 +119,4 @@ def update_case(case_id: str, patch: Dict[str, Any]) -> Optional[Dict[str, Any]]
129
  save_case(updated)
130
  return updated
131
 
 
 
14
  alphabet = string.ascii_uppercase + string.digits
15
  return ''.join(secrets.choice(alphabet) for _ in range(n))
16
 
 
 
 
17
  def case_path(case_id: str) -> Path:
18
  return cases_dir() / f"{case_id}.json"
19
 
20
+ def new_case_id() -> str:
21
+ return f"EC-{_now_iso().replace('-','').replace(':','').replace('T','')}-{_rand(4)}"
22
+
23
  def _deep_merge(a: Dict[str, Any], b: Dict[str, Any]) -> Dict[str, Any]:
24
  out = dict(a)
25
+ for k, v in (b or {}).items():
26
  if isinstance(v, dict) and isinstance(out.get(k), dict):
27
  out[k] = _deep_merge(out[k], v)
28
  else:
 
30
  return out
31
 
32
  def _migrate_soup_to_soap(obj: Dict[str, Any]) -> Dict[str, Any]:
33
+ # If older payloads used "soup_draft", migrate to "soap_draft"
34
+ if isinstance(obj, dict) and "soup_draft" in obj and "soap_draft" not in obj:
35
+ obj["soap_draft"] = obj.pop("soup_draft")
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  return obj
37
 
38
  def list_cases(status: Optional[str] = None) -> List[Dict[str, Any]]:
 
62
  try:
63
  obj = json.loads(p.read_text())
64
  obj = _migrate_soup_to_soap(obj)
65
+ # drop deprecated triage field if present
66
+ if isinstance(obj, dict) and 'triage' in obj:
67
+ obj.pop('triage', None)
68
  return obj
69
  except Exception:
70
  return None
 
96
  "pcp_attests": False,
97
  "specialist_attests": False
98
  },
 
99
  "soap_draft": { # <-- SOAP by default
100
  "subjective": "",
101
  "objective": "",
 
107
  }
108
  obj = _deep_merge(obj, initial or {})
109
  obj = _migrate_soup_to_soap(obj)
110
+ # no `triage` in new schema
111
  save_case(obj)
112
  return obj
113
 
 
119
  save_case(updated)
120
  return updated
121
 
122
+