From 038a114ceace1468c48afe732686c8914d83b9f7 Mon Sep 17 00:00:00 2001 From: akat5uki <40821810+akat5uki@users.noreply.github.com> Date: Thu, 22 Aug 2024 03:41:04 +0530 Subject: [PATCH 1/2] Added required validation for Max dosage. --- care/facility/api/serializers/prescription.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/care/facility/api/serializers/prescription.py b/care/facility/api/serializers/prescription.py index ed68e772a7..640073b8be 100644 --- a/care/facility/api/serializers/prescription.py +++ b/care/facility/api/serializers/prescription.py @@ -127,6 +127,10 @@ def validate(self, attrs): raise serializers.ValidationError( {"indicator": "Indicator should be set for PRN prescriptions."} ) + if attrs.get("max_dosage") is None or attrs.get("max_dosage") < attrs.get("base_dosage"): + raise serializers.ValidationError( + {"max_dosage": "Max dosage cannot be less than base dosage."} + ) attrs.pop("frequency", None) attrs.pop("days", None) else: From 2245d036783f6a8a7649c2e2ea237081d658086c Mon Sep 17 00:00:00 2001 From: akat5uki <40821810+akat5uki@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:36:18 +0530 Subject: [PATCH 2/2] Changes done as per suggestion. --- care/facility/api/serializers/prescription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/care/facility/api/serializers/prescription.py b/care/facility/api/serializers/prescription.py index 640073b8be..17806c68fa 100644 --- a/care/facility/api/serializers/prescription.py +++ b/care/facility/api/serializers/prescription.py @@ -127,7 +127,7 @@ def validate(self, attrs): raise serializers.ValidationError( {"indicator": "Indicator should be set for PRN prescriptions."} ) - if attrs.get("max_dosage") is None or attrs.get("max_dosage") < attrs.get("base_dosage"): + if attrs.get("max_dosage") and attrs.get("max_dosage") < attrs.get("base_dosage"): raise serializers.ValidationError( {"max_dosage": "Max dosage cannot be less than base dosage."} )