Skip to content

Commit

Permalink
Merge pull request #2717 from ohcnetwork/bypass_validation
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshhari authored Jan 7, 2025
2 parents 6414e0d + 4697dd4 commit b70ccc1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions care/emr/api/viewsets/questionnaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ def perform_create(self, instance):
)

def validate_data(self, instance, model_obj=None):
# 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()
and 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):
Expand Down

0 comments on commit b70ccc1

Please sign in to comment.