diff --git a/project/accounts/tests/test_doctor.py b/project/accounts/tests/test_doctor.py index b0b8f4e..d91cc75 100644 --- a/project/accounts/tests/test_doctor.py +++ b/project/accounts/tests/test_doctor.py @@ -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) \ No newline at end of file + self.assertEqual(len(response.data['doctors']),1) \ No newline at end of file diff --git a/project/accounts/urls.py b/project/accounts/urls.py index 0a8314c..5993d68 100644 --- a/project/accounts/urls.py +++ b/project/accounts/urls.py @@ -42,7 +42,7 @@ path('deleted-employee/delete//', DeletedEmployeeView.as_view({'delete': 'destroy'}), name='deleted-employee-delete'), - path('patient/doctors//', DoctorsOfPatient.as_view({'get': 'get'}), name='patient-doctors'), + # path('patient/doctors//', DoctorsOfPatient.as_view({'get': 'get'}), name='patient-doctors'), path('', include(router.urls)), ] diff --git a/project/accounts/views/patient.py b/project/accounts/views/patient.py index 95f0bbb..be5e583 100644 --- a/project/accounts/views/patient.py +++ b/project/accounts/views/patient.py @@ -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(