Skip to content

Commit 5dd6f03

Browse files
committed
copilot code review
1 parent ea34861 commit 5dd6f03

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

extensions/bridge/protocols/bridge_patient_sync.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class BridgePatientSync(BaseProtocol):
1818
EventType.Name(EventType.PATIENT_UPDATED),
1919
EventType.Name(EventType.PATIENT_CONTACT_POINT_CREATED),
2020
EventType.Name(EventType.PATIENT_CONTACT_POINT_UPDATED),
21-
# will need to export PatientAddress as a standalone data model to support these
2221
# leaving as a TODO for now
22+
# will need to export PatientAddress as a standalone data model to support these
2323
# EventType.Name(EventType.PATIENT_ADDRESS_CREATED),
2424
# EventType.Name(EventType.PATIENT_ADDRESS_UPDATED),
2525
]
@@ -49,21 +49,22 @@ def bridge_patient_metadata(self):
4949

5050
return metadata
5151

52-
def set_patient_id(self):
52+
def get_patient_id(self):
5353
if self.event.type in [EventType.PATIENT_CREATED, EventType.PATIENT_UPDATED]:
5454
return self.target
5555
elif self.event.type in [EventType.PATIENT_CONTACT_POINT_CREATED, EventType.PATIENT_CONTACT_POINT_UPDATED]:
5656
contact_point_id = self.target
57-
contact_point = PatientContactPoint.objects.get(id=contact_point_id)
58-
return contact_point.patient.id
57+
if not hasattr(self, '_cached_contact_point') or self._cached_contact_point.id != contact_point_id:
58+
self._cached_contact_point = PatientContactPoint.objects.get(id=contact_point_id)
59+
return self._cached_contact_point.patient.id
5960
# elif self.event.type in [EventType.PATIENT_ADDRESS_CREATED, EventType.PATIENT_ADDRESS_UPDATED]:
6061
# address_id = self.target
6162
# address = PatientAddress.objects.get(id=address_id)
6263
# return address.patient.id
6364

6465
def compute(self):
6566
event_type = self.event.type
66-
canvas_patient_id = self.set_patient_id()
67+
canvas_patient_id = self.get_patient_id()
6768
contact_point_id = self.target if event_type in [EventType.PATIENT_CONTACT_POINT_CREATED, EventType.PATIENT_CONTACT_POINT_UPDATED] else None
6869

6970
log.info(f'>>> BridgePatientSync.compute {EventType.Name(event_type)} for {canvas_patient_id}')
@@ -85,19 +86,19 @@ def compute(self):
8586

8687
# Get a reference to the target patient
8788
canvas_patient = Patient.objects.get(id=canvas_patient_id)
88-
contact_point = PatientContactPoint.objects.get(id=contact_point_id) if contact_point_id else None
89+
contact_point = self._cached_contact_point if contact_point_id else None
8990

9091
# Generate the payload for creating or updating the patient in Bridge
9192
# At the moment this is just sending a contact point (as telecom) if it is present via the event,
9293
# regardless of the event type (create or update)
93-
# And since ContactPoint is refered to elsewhere as 'telecom' I'm assuming it is NOT an email...
94+
# And since ContactPoint is referred to elsewhere as 'telecom' I'm assuming it is NOT an email...
9495
# TODO: Pass email and address here
9596
bridge_payload = {
9697
'externalId': canvas_patient.id,
9798
'firstName': canvas_patient.first_name,
9899
'lastName': canvas_patient.last_name,
99100
'dateOfBirth': canvas_patient.birth_date.isoformat(),
100-
'telecom': [contact_point] if contact_point else None,
101+
'telecom': contact_point if contact_point else None,
101102
}
102103

103104
if event_type == EventType.PATIENT_CREATED:
@@ -185,7 +186,7 @@ def post(self) -> list[Response | Effect]:
185186
]
186187

187188
patient = Patient.objects.create(
188-
first_name=json_body.get("firstName"),
189+
first_name=json_body.get('firstName'),
189190
last_name=json_body.get('lastName'),
190191
birth_date=json_body.get('dateOfBirth'),
191192
)

0 commit comments

Comments
 (0)