Skip to content

Commit

Permalink
hijacking json dump instead of model dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Alexander committed Nov 2, 2023
1 parent 0e02bc2 commit f11b29f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lambdas/handlers/search_patient_details_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import json
from json import JSONDecodeError

import boto3
Expand Down Expand Up @@ -58,14 +59,15 @@ def lambda_handler(event, context):
pds_api_service = get_pds_service()(SSMService())
patient_details = pds_api_service.fetch_patient_details(nhs_number)

patient_details_dict = patient_details.model_dump()
gp_ods = patient_details_dict('general_practice_ods')
logger.info(f"Patient code: {gp_ods}")
response = patient_details.model_dump_json(by_alias=True)
json_load = json.loads(response)
logger.info(f"json loads: {json_load}")
logger.info(f"json value: {json_load['general_practice_ods']}")
gp_ods = json_load['general_practice_ods']

if gp_ods is not user_ods_code:
raise UserNotAuthorisedException

response = patient_details.model_dump_json(by_alias=True)

return ApiGatewayResponse(200, response, "GET").create_api_gateway_response()

except PatientNotFoundException as e:
Expand Down
3 changes: 0 additions & 3 deletions lambdas/services/patient_search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def handle_response(self, response: Response, nhs_number: str) -> PatientDetails
patient = Patient.model_validate(response.json())
logging.info(f"Patient: {patient}")
patient_details = patient.get_patient_details(nhs_number)
logging.info(f"Patient Details: {patient_details.model_dump}")
logging.info(f"Patient Details: {patient_details.model_dump(True)}")
logging.info(f"Patient Details: {patient_details.model_dump['general_practice_ods']}")
return patient_details

if response.status_code == 404:
Expand Down

0 comments on commit f11b29f

Please sign in to comment.