Ali2206 commited on
Commit
0ec1903
·
verified ·
1 Parent(s): 038b1ff

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +10 -1
utils.py CHANGED
@@ -103,7 +103,16 @@ def serialize_patient(patient: dict) -> dict:
103
  return patient_copy
104
 
105
  def compute_patient_data_hash(data: dict) -> str:
106
- serialized = json.dumps(data, sort_keys=True)
 
 
 
 
 
 
 
 
 
107
  return hashlib.sha256(serialized.encode()).hexdigest()
108
 
109
  def compute_file_content_hash(file_content: bytes) -> str:
 
103
  return patient_copy
104
 
105
  def compute_patient_data_hash(data: dict) -> str:
106
+ # Custom JSON encoder to handle datetime objects
107
+ class DateTimeEncoder(json.JSONEncoder):
108
+ def default(self, obj):
109
+ if isinstance(obj, datetime):
110
+ return obj.isoformat()
111
+ elif isinstance(obj, ObjectId):
112
+ return str(obj)
113
+ return super().default(obj)
114
+
115
+ serialized = json.dumps(data, sort_keys=True, cls=DateTimeEncoder)
116
  return hashlib.sha256(serialized.encode()).hexdigest()
117
 
118
  def compute_file_content_hash(file_content: bytes) -> str: