diff --git a/care/emr/api/viewsets/questionnaire.py b/care/emr/api/viewsets/questionnaire.py index b256d338fc..ac7e0f933c 100644 --- a/care/emr/api/viewsets/questionnaire.py +++ b/care/emr/api/viewsets/questionnaire.py @@ -3,7 +3,7 @@ from django_filters import rest_framework as filters from pydantic import UUID4, BaseModel from rest_framework.decorators import action -from rest_framework.exceptions import PermissionDenied, ValidationError +from rest_framework.exceptions import PermissionDenied from rest_framework.response import Response from care.emr.api.viewsets.base import EMRModelViewSet @@ -13,7 +13,6 @@ Patient, Questionnaire, QuestionnaireOrganization, - QuestionnaireResponse, ) from care.emr.resources.organization.spec import OrganizationReadSpec from care.emr.resources.questionnaire.spec import ( @@ -61,13 +60,19 @@ def perform_create(self, instance): ) def validate_data(self, instance, model_obj=None): - if ( - model_obj - and not QuestionnaireResponse.objects.filter( - questionnaire=model_obj - ).exists() - ): - raise ValidationError("Cannot edit an active questionnaire") + pass + # If we're editing an existing questionnaire (model_obj is not None) + # and there are no responses linked to this questionnaire yet + # if ( + # model_obj + # and not QuestionnaireResponse.objects.filter( + # questionnaire=model_obj + # ).exists() + # ): + # Prevent editing if the questionnaire has already been used (has responses) + # This ensures data integrity by not allowing changes to questionnaires + # that are actively being used + # raise ValidationError("Cannot edit an active questionnaire") def authorize_create(self, instance): for org in instance.organizations: