Skip to content

Commit

Permalink
Merge pull request #30 from MohamedHamed12/softdelete
Browse files Browse the repository at this point in the history
get patient doctors
  • Loading branch information
MohamedHamed12 authored May 15, 2024
2 parents 9ab3ea3 + 9219d2a commit f581f91
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 11 additions & 2 deletions project/accounts/tests/test_doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ def test_create_patient(self):
# response = self.client.post('/accounts/patient/', data,
# format='json', HTTP_AUTHORIZATION='Bearer ' + self.staff_token)
# self.assertEqual(response.status_code, 201)
# def test_patient_doctors(self):
# doctor,doctoken=self.create_doctor(self.staff_token,national_id="12212121212121")

# visit=self.create_visit(self.staff_token,doctors_ids=[doctor['id']],patient_id=self.patient['id'])
# url=reverse('patient-doctors',kwargs={'pk':self.patient['id']})
# response=self.client.get(url, format='json', HTTP_AUTHORIZATION='Bearer ' + self.staff_token)
# self.assertEqual(response.status_code,200)
# self.assertEqual(len(response.data['results']),1)
def test_patient_doctors(self):
doctor,doctoken=self.create_doctor(self.staff_token,national_id="12212121212121")

visit=self.create_visit(self.staff_token,doctors_ids=[doctor['id']],patient_id=self.patient['id'])
url=reverse('patient-doctors',kwargs={'pk':self.patient['id']})
url=f"/accounts/patient/{self.patient['id']}/"
response=self.client.get(url, format='json', HTTP_AUTHORIZATION='Bearer ' + self.staff_token)
# print(response.data)
self.assertEqual(response.status_code,200)
self.assertEqual(len(response.data['results']),1)
self.assertEqual(len(response.data['doctors']),1)
2 changes: 1 addition & 1 deletion project/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
path('deleted-employee/delete/<str:pk>/', DeletedEmployeeView.as_view({'delete': 'destroy'}), name='deleted-employee-delete'),


path('patient/doctors/<str:pk>/', DoctorsOfPatient.as_view({'get': 'get'}), name='patient-doctors'),
# path('patient/doctors/<str:pk>/', DoctorsOfPatient.as_view({'get': 'get'}), name='patient-doctors'),

path('', include(router.urls)),
]
9 changes: 9 additions & 0 deletions project/accounts/views/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def create(self , request, *args, **kwargs):


return Response(PatientSerializer(patient).data, status=status.HTTP_201_CREATED)

def retrieve(self, request, *args, **kwargs):
response= super().retrieve(request, *args, **kwargs)
visits=Visit.objects.filter(patient=self.get_object())
all_doctors = Doctor.objects.filter(visits__in=visits).distinct()
response.data['doctors']= DoctorSerializer(all_doctors, many=True).data
return response


@swagger_auto_schema(
manual_parameters=[
openapi.Parameter(
Expand Down

0 comments on commit f581f91

Please # to comment.