Skip to content

Commit

Permalink
Bypass Active Questionnaire Check
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg committed Jan 7, 2025
1 parent 6414e0d commit c470f5e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions care/emr/api/viewsets/questionnaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,7 +13,6 @@
Patient,
Questionnaire,
QuestionnaireOrganization,
QuestionnaireResponse,
)
from care.emr.resources.organization.spec import OrganizationReadSpec
from care.emr.resources.questionnaire.spec import (
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c470f5e

Please sign in to comment.