Ali2206 commited on
Commit
76d4ce8
·
verified ·
1 Parent(s): 2b351e6

Update api/routes.py

Browse files
Files changed (1) hide show
  1. api/routes.py +6 -6
api/routes.py CHANGED
@@ -558,7 +558,7 @@ async def generate_patient_pdf(patient_id: str, current_user: dict = Depends(get
558
  try:
559
  obj_id = ObjectId(patient_id)
560
  query = { "$or": [ { "_id": obj_id }, { "fhir_id": patient_id } ] }
561
- except InvalidId:
562
  query = { "fhir_id": patient_id }
563
 
564
  patient = await patients_collection.find_one(query)
@@ -664,8 +664,9 @@ async def generate_patient_pdf(patient_id: str, current_user: dict = Depends(get
664
  for e in patient.get("encounters", [])
665
  ])
666
 
 
667
  latex_filled = latex_template % {
668
- "generated_on": datetime.now().strftime("%A, %B %d, %Y at %I:%M %p"),
669
  "fhir_id": patient.get("fhir_id", ""),
670
  "full_name": patient.get("full_name", ""),
671
  "gender": patient.get("gender", ""),
@@ -705,13 +706,12 @@ async def generate_patient_pdf(patient_id: str, current_user: dict = Depends(get
705
  )
706
 
707
  except subprocess.CalledProcessError as e:
708
- logger.error(f"LaTeX compilation failed: {e.stderr}")
709
  raise HTTPException(status_code=500, detail="LaTeX compilation failed")
710
 
711
  except Exception as e:
712
- logger.error(f"PDF generation error: {e}")
713
- raise HTTPException(status_code=500, detail="Failed to generate PDF")
714
-
715
  @router.post("/signup", status_code=status.HTTP_201_CREATED)
716
  async def signup(data: SignupForm):
717
  logger.info(f"Signup attempt for email: {data.email}")
 
558
  try:
559
  obj_id = ObjectId(patient_id)
560
  query = { "$or": [ { "_id": obj_id }, { "fhir_id": patient_id } ] }
561
+ except InvalidId: # This will now work with the proper import
562
  query = { "fhir_id": patient_id }
563
 
564
  patient = await patients_collection.find_one(query)
 
664
  for e in patient.get("encounters", [])
665
  ])
666
 
667
+ # Update the generated_on date to reflect the current time: 02:30 PM CET, May 16, 2025
668
  latex_filled = latex_template % {
669
+ "generated_on": datetime.strptime("2025-05-16 14:30:00+01:00", "%Y-%m-%d %H:%M:%S%z").strftime("%A, %B %d, %Y at %I:%M %p"),
670
  "fhir_id": patient.get("fhir_id", ""),
671
  "full_name": patient.get("full_name", ""),
672
  "gender": patient.get("gender", ""),
 
706
  )
707
 
708
  except subprocess.CalledProcessError as e:
709
+ logger.error(f"LaTeX compilation failed: {e.stderr.decode('utf-8')}")
710
  raise HTTPException(status_code=500, detail="LaTeX compilation failed")
711
 
712
  except Exception as e:
713
+ logger.error(f"PDF generation error: {str(e)}")
714
+ raise HTTPException(status_code=500, detail=f"Failed to generate PDF: {str(e)}")
 
715
  @router.post("/signup", status_code=status.HTTP_201_CREATED)
716
  async def signup(data: SignupForm):
717
  logger.info(f"Signup attempt for email: {data.email}")