新增
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -68,6 +68,39 @@ def _truthy(value: Any) -> bool:
|
||||
return bool(value)
|
||||
|
||||
|
||||
def _row_mapping(value: Any) -> dict[str, Any]:
|
||||
"""Return only fields actually supplied by an API row when possible."""
|
||||
|
||||
if isinstance(value, Mapping):
|
||||
return dict(value)
|
||||
raw = getattr(value, "raw", None)
|
||||
if isinstance(raw, Mapping) and raw:
|
||||
return dict(raw)
|
||||
fields = getattr(value, "__dataclass_fields__", {})
|
||||
return {
|
||||
name: getattr(value, name, None)
|
||||
for name in fields
|
||||
if name != "raw"
|
||||
}
|
||||
|
||||
|
||||
def merge_prescription_detail(row: Any, detail: Any) -> dict[str, Any]:
|
||||
"""Match the admin editor's ``{...listRow, ...detail}`` state merge."""
|
||||
|
||||
merged = _row_mapping(row)
|
||||
merged.update(_row_mapping(detail))
|
||||
# Repository models retain the original API row in ``raw`` and expose
|
||||
# canonical alias fields (for example ``patient_phone`` -> ``phone``) on
|
||||
# the dataclass. Add those aliases without letting an omitted detail field
|
||||
# overwrite a list-only audit/void value with its model default.
|
||||
for source in (detail, row):
|
||||
fields = getattr(source, "__dataclass_fields__", {})
|
||||
for name in fields:
|
||||
if name != "raw" and name not in merged:
|
||||
merged[name] = getattr(source, name, None)
|
||||
return merged
|
||||
|
||||
|
||||
def prescription_status(row: Any) -> tuple[str, str]:
|
||||
"""Return the admin audit-column status; void state has its own column."""
|
||||
|
||||
@@ -730,7 +763,11 @@ class PrescriptionsPage(QWidget):
|
||||
or not can_edit_or_delete(row)
|
||||
):
|
||||
return
|
||||
self._load_detail(row, self._open_editor, message="正在准备编辑处方…")
|
||||
self._load_detail(
|
||||
row,
|
||||
lambda detail: self._open_editor(merge_prescription_detail(row, detail)),
|
||||
message="正在准备编辑处方…",
|
||||
)
|
||||
|
||||
def _open_editor(self, detail: Any) -> None:
|
||||
dialog = PrescriptionEditorDialog(
|
||||
|
||||
Reference in New Issue
Block a user