diff --git a/project/accounts/migrations/0005_remove_doctor_is_deleted_remove_employee_is_deleted_and_more.py b/project/accounts/migrations/0005_remove_doctor_is_deleted_remove_employee_is_deleted_and_more.py new file mode 100644 index 0000000..d6baa55 --- /dev/null +++ b/project/accounts/migrations/0005_remove_doctor_is_deleted_remove_employee_is_deleted_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 5.0.3 on 2024-05-13 17:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0004_doctor_deleted_doctor_deleted_by_cascade_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="doctor", + name="is_deleted", + ), + migrations.RemoveField( + model_name="employee", + name="is_deleted", + ), + migrations.RemoveField( + model_name="patient", + name="is_deleted", + ), + ] diff --git a/project/accounts/models/models.py b/project/accounts/models/models.py index 379bee0..c61e1c2 100644 --- a/project/accounts/models/models.py +++ b/project/accounts/models/models.py @@ -34,7 +34,7 @@ class Profile(SafeDeleteModel): notes= models.TextField(blank=True,null=True) address = models.JSONField(null=True, blank=True) phone = models.JSONField(null=True, blank=True) - is_deleted = models.BooleanField(default=False) + created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: diff --git a/project/accounts/serializers/doctor.py b/project/accounts/serializers/doctor.py index 5b7fce6..d1ddba9 100644 --- a/project/accounts/serializers/doctor.py +++ b/project/accounts/serializers/doctor.py @@ -6,8 +6,7 @@ class DoctorSerializer(serializers.ModelSerializer): address =AddressSerializer( required=False) class Meta: model = Doctor - # fields = '__all__' - exclude = ['is_deleted'] + fields = '__all__' diff --git a/project/accounts/serializers/employee.py b/project/accounts/serializers/employee.py index 7625fd1..2d92c0d 100644 --- a/project/accounts/serializers/employee.py +++ b/project/accounts/serializers/employee.py @@ -6,8 +6,7 @@ class EmployeeSerializer(serializers.ModelSerializer): address =AddressSerializer( required=False) class Meta: model = Employee - # fields = '__all__' - exclude = ['is_deleted'] + fields = '__all__' diff --git a/project/accounts/serializers/patient.py b/project/accounts/serializers/patient.py index c0c6bf8..dd7cf05 100644 --- a/project/accounts/serializers/patient.py +++ b/project/accounts/serializers/patient.py @@ -6,8 +6,7 @@ class UserImageSerializer(serializers.ModelSerializer): class Meta: model = UserImage - # fields = '__all__' - exclude = ['is_deleted'] + fields = '__all__' @@ -19,8 +18,8 @@ class PatientSerializer(serializers.ModelSerializer): class Meta: model = Patient - - exclude = ['is_deleted'] + fields = '__all__' + # exclude = ['is_deleted'] def validate_address(self, value): address_serializer = AddressSerializer(data=value) if not address_serializer.is_valid() or value!=address_serializer.data: diff --git a/project/accounts/tests/test_delete.py b/project/accounts/tests/test_delete.py index 1bc90a2..7df78dc 100644 --- a/project/accounts/tests/test_delete.py +++ b/project/accounts/tests/test_delete.py @@ -161,7 +161,7 @@ def test_delete_doctor_restore(self): url=reverse('doctor-restore') response = self.client.post( url, format='json', HTTP_AUTHORIZATION='Bearer ' + self.staff_token,data=data) - + # print(response.data) self.assertEqual(response.status_code, 200) self.assertEqual(Doctor.objects.count(), 1) self.assertEqual(len( Doctor.deleted_objects.all()), 0) diff --git a/project/accounts/urls.py b/project/accounts/urls.py index 65b662c..08b2eb1 100644 --- a/project/accounts/urls.py +++ b/project/accounts/urls.py @@ -29,12 +29,12 @@ path('change-password/', ChangePasswordView.as_view(), name='change-password'), - path('patients/restore/', PatientViewSet.as_view({'post': 'restore'}), name='patient-restore'), path('patients/deleted/', PatientViewSet.as_view({'get': 'get_deleted'}), name='patient-get-deleted'), - - path('doctors/restore/', DoctorViewSet.as_view({'post': 'restore'}), name='doctor-restore'), path('doctors/deleted/', DoctorViewSet.as_view({'get': 'get_deleted'}), name='doctor-get-deleted'), - - path('employees/restore/', EmployeeViewSet.as_view({'post': 'restore'}), name='employee-restore'), path('employees/deleted/', EmployeeViewSet.as_view({'get': 'get_deleted'}), name='employee-get-deleted'), + + path('employees/restore/', RestoreEmployeeView.as_view(), name='employee-restore'), + path('patients/restore/', RestorePatientView.as_view(), name='patient-restore'), + path('doctors/restore/', RestoreDoctorView.as_view(), name='doctor-restore'), + ] diff --git a/project/accounts/views/doctor.py b/project/accounts/views/doctor.py index 74397e1..ac6dfea 100644 --- a/project/accounts/views/doctor.py +++ b/project/accounts/views/doctor.py @@ -67,15 +67,7 @@ def destroy(self, request, *args, **kwargs): return Response(status=status.HTTP_204_NO_CONTENT) else: return super().destroy(request, *args, **kwargs) - def restore(self, request, *args, **kwargs): - serializer = RestoreDoctorSerializer(data=request.data) - if not serializer.is_valid(): - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - instance = serializer.validated_data['id'] - instance.undelete() - return Response(status=status.HTTP_200_OK) - + def get_deleted(self, request, *args, **kwargs): paginator = self.pagination_class() @@ -84,3 +76,17 @@ def get_deleted(self, request, *args, **kwargs): serializer = self.get_serializer(result_page, many=True) return paginator.get_paginated_response(serializer.data) + +from rest_framework.generics import GenericAPIView +class RestoreDoctorView(GenericAPIView): + serializer_class = RestoreDoctorSerializer + permission_classes = [IsAuthenticated,CustomPermission] + + def post(self, request, *args, **kwargs): + serializer = RestoreDoctorSerializer(data=request.data) + if not serializer.is_valid(): + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + instance = serializer.validated_data['id'] + instance.undelete() + return Response(status=status.HTTP_200_OK) diff --git a/project/accounts/views/employee.py b/project/accounts/views/employee.py index afbbb77..bb8e92d 100644 --- a/project/accounts/views/employee.py +++ b/project/accounts/views/employee.py @@ -72,15 +72,7 @@ def destroy(self, request, *args, **kwargs): return Response(status=status.HTTP_204_NO_CONTENT) else: return super().destroy(request, *args, **kwargs) - def restore(self, request, *args, **kwargs): - serializer = RestoreEmployeeSerializer(data=request.data) - if not serializer.is_valid(): - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - instance = serializer.validated_data['id'] - instance.undelete() - return Response(status=status.HTTP_200_OK) - + def get_deleted(self, request, *args, **kwargs): paginator = self.pagination_class() @@ -90,6 +82,16 @@ def get_deleted(self, request, *args, **kwargs): return paginator.get_paginated_response(serializer.data) - - +from rest_framework.generics import GenericAPIView +class RestoreEmployeeView(GenericAPIView): + serializer_class = RestoreEmployeeSerializer + permission_classes = [IsAuthenticated,CustomPermission] + def post(self, request, *args, **kwargs): + serializer = RestoreEmployeeSerializer(data=request.data) + if not serializer.is_valid(): + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + instance = serializer.validated_data['id'] + instance.undelete() + return Response(status=status.HTTP_200_OK) diff --git a/project/accounts/views/patient.py b/project/accounts/views/patient.py index 613fff8..bb27f84 100644 --- a/project/accounts/views/patient.py +++ b/project/accounts/views/patient.py @@ -74,15 +74,7 @@ def destroy(self, request, *args, **kwargs): return Response(status=status.HTTP_204_NO_CONTENT) else: return super().destroy(request, *args, **kwargs) - def restore(self, request, *args, **kwargs): - serializer = RestorePatientSerializer(data=request.data) - if not serializer.is_valid(): - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - instance = serializer.validated_data['id'] - instance.undelete() - return Response(status=status.HTTP_200_OK) - + def get_deleted(self, request, *args, **kwargs): paginator = self.pagination_class() @@ -90,4 +82,18 @@ def get_deleted(self, request, *args, **kwargs): result_page = paginator.paginate_queryset(deleted_patients, request) serializer = self.get_serializer(result_page, many=True) return paginator.get_paginated_response(serializer.data) + + +from rest_framework.generics import GenericAPIView +class RestorePatientView(GenericAPIView): + serializer_class = RestorePatientSerializer + permission_classes = [IsAuthenticated,CustomPermission] + def post(self, request, *args, **kwargs): + serializer = RestorePatientSerializer(data=request.data) + if not serializer.is_valid(): + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + instance = serializer.validated_data['id'] + instance.undelete() + return Response(status=status.HTTP_200_OK) diff --git a/project/visit/filters/__init__.py b/project/visit/filters/__init__.py index f6ac671..f16d63d 100644 --- a/project/visit/filters/__init__.py +++ b/project/visit/filters/__init__.py @@ -51,7 +51,7 @@ class Meta: 'end_at': ['year', 'month', 'day', 'hour', 'minute', 'second', 'gt','lt','gte','lte'], 'doctors': ['exact'], 'patient': ['exact'], - 'is_deleted': ['exact'], + # 'is_deleted': ['exact'], 'created_at': ['year', 'month', 'day', 'hour', 'minute', 'second', 'gt','lt','gte','lte'], } diff --git a/project/visit/migrations/0004_remove_attachment_is_deleted_remove_visit_is_deleted.py b/project/visit/migrations/0004_remove_attachment_is_deleted_remove_visit_is_deleted.py new file mode 100644 index 0000000..3487bf9 --- /dev/null +++ b/project/visit/migrations/0004_remove_attachment_is_deleted_remove_visit_is_deleted.py @@ -0,0 +1,21 @@ +# Generated by Django 5.0.3 on 2024-05-13 17:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("visit", "0003_attachment_deleted_attachment_deleted_by_cascade_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="attachment", + name="is_deleted", + ), + migrations.RemoveField( + model_name="visit", + name="is_deleted", + ), + ] diff --git a/project/visit/models/models.py b/project/visit/models/models.py index 8c6e545..b882954 100644 --- a/project/visit/models/models.py +++ b/project/visit/models/models.py @@ -22,7 +22,6 @@ class Visit(SafeDeleteModel): patient = models.ForeignKey('accounts.Patient', on_delete=models.CASCADE) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - is_deleted = models.BooleanField(default=False) notes = models.TextField(blank=True) def save(self, *args, **kwargs): self.visit_number = Visit.objects.count()+1 @@ -43,7 +42,6 @@ class Attachment(SafeDeleteModel): notes = models.TextField(blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - is_deleted = models.BooleanField(default=False) def save(self, *args, **kwargs): self.file_type = self.file.name.split('.')[-1] super(Attachment, self).save(*args, **kwargs) diff --git a/project/visit/serializers/attachment.py b/project/visit/serializers/attachment.py index b6c352e..cda2dd4 100644 --- a/project/visit/serializers/attachment.py +++ b/project/visit/serializers/attachment.py @@ -8,8 +8,7 @@ class AttachmentSerializer(serializers.ModelSerializer): file_type=serializers.CharField(read_only=True) class Meta: model = Attachment - # fields = '__all__' - exclude = ['is_deleted'] + fields = '__all__' class RestoreAttachmentSerializer(serializers.Serializer): id = serializers.IntegerField() diff --git a/project/visit/serializers/visit.py b/project/visit/serializers/visit.py index 605e709..29f4ff4 100644 --- a/project/visit/serializers/visit.py +++ b/project/visit/serializers/visit.py @@ -28,8 +28,7 @@ class VisitSerializer(serializers.ModelSerializer): attachment = AttachmentSerializer( read_only=True, many=True,source='visit_attachments', required=False) class Meta: model = Visit - # fields = '__all__' - exclude = ['is_deleted'] + fields = '__all__' class RestoreVisitSerializer(serializers.Serializer): diff --git a/project/visit/urls.py b/project/visit/urls.py index 283c2e4..5fac5ca 100644 --- a/project/visit/urls.py +++ b/project/visit/urls.py @@ -23,9 +23,9 @@ # path('patients/restore/', PatientViewSet.as_view({'post': 'restore'}), name='patient-restore'), # path('patients/deleted/', PatientViewSet.as_view({'get': 'get_deleted'}), name='patient-get-deleted'), - path('visits/restore/', VisitViewSet.as_view({'post': 'restore'}), name='visit-restore'), path('visits/deleted/', VisitViewSet.as_view({'get': 'get_deleted'}), name='visit-get-deleted'), - path('attachments/restore/', AttachmentViewSet.as_view({'post': 'restore'}), name='attachment-restore'), path('attachments/deleted/', AttachmentViewSet.as_view({'get': 'get_deleted'}), name='attachment-get-deleted'), + path('visits/restore/', RestoreVisitView.as_view(), name='visit-restore'), + path('attachments/restore/', RestoreAttachmentView.as_view(), name='attachment-restore'), ] diff --git a/project/visit/views/attachment.py b/project/visit/views/attachment.py index 2787a1d..8586cb5 100644 --- a/project/visit/views/attachment.py +++ b/project/visit/views/attachment.py @@ -56,15 +56,7 @@ def destroy(self, request, *args, **kwargs): return Response(status=status.HTTP_204_NO_CONTENT) else: return super().destroy(request, *args, **kwargs) - def restore(self, request, *args, **kwargs): - serializer = RestoreAttachmentSerializer(data=request.data) - if not serializer.is_valid(): - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - instance = serializer.validated_data['id'] - instance.undelete() - return Response(status=status.HTTP_200_OK) - + def get_deleted(self, request, *args, **kwargs): paginator = self.pagination_class() @@ -72,7 +64,18 @@ def get_deleted(self, request, *args, **kwargs): result_page = paginator.paginate_queryset( deleted_attachments, request) serializer = self.get_serializer(result_page, many=True) return paginator.get_paginated_response(serializer.data) - +from rest_framework.generics import GenericAPIView +class RestoreAttachmentView(GenericAPIView): + serializer_class=RestoreAttachmentSerializer + pagination_class = CustomPagination + def post(self, request, *args, **kwargs): + serializer = RestoreAttachmentSerializer(data=request.data) + if not serializer.is_valid(): + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + instance = serializer.validated_data['id'] + instance.undelete() + return Response(status=status.HTTP_200_OK) diff --git a/project/visit/views/visit.py b/project/visit/views/visit.py index b2256d9..8ee23b0 100644 --- a/project/visit/views/visit.py +++ b/project/visit/views/visit.py @@ -56,14 +56,7 @@ def destroy(self, request, *args, **kwargs): return Response(status=status.HTTP_204_NO_CONTENT) else: return super().destroy(request, *args, **kwargs) - def restore(self, request, *args, **kwargs): - serializer = RestoreVisitSerializer(data=request.data) - if not serializer.is_valid(): - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - instance = serializer.validated_data['id'] - instance.undelete() - return Response(status=status.HTTP_200_OK) + def get_deleted(self, request, *args, **kwargs): @@ -72,7 +65,18 @@ def get_deleted(self, request, *args, **kwargs): result_page = paginator.paginate_queryset(deleted_visits, request) serializer = self.get_serializer(result_page, many=True) return paginator.get_paginated_response(serializer.data) - +from rest_framework.generics import GenericAPIView +class RestoreVisitView(GenericAPIView): + serializer_class=RestoreVisitSerializer + pagination_class = CustomPagination + def post(self, request, *args, **kwargs): + serializer = RestoreVisitSerializer(data=request.data) + if not serializer.is_valid(): + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + + instance = serializer.validated_data['id'] + instance.undelete() + return Response(status=status.HTTP_200_OK)