Skip to content

Commit

Permalink
changes for pr test
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-sharmav committed Nov 7, 2024
1 parent a090f44 commit 6cba5a5
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions care/facility/api/serializers/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,32 @@ def _remove_irrelevant_fields(self, attrs: dict, keep_fields: set[str]) -> None:

def validate_medicine(self, attrs):
"""Validate the medicine field and check for duplicate prescriptions."""
attrs["medicine"] = get_object_or_404(
MedibaseMedicine, external_id=attrs["medicine"]
)

# Check for existing prescription
if (
not self.instance
and Prescription.objects.filter(
consultation__external_id=self.context["request"].parser_context[
"kwargs"
]["consultation_external_id"],
medicine=attrs["medicine"],
discontinued=False,
).exists()
):
raise serializers.ValidationError(
{
"medicine": (
"This medicine is already prescribed to this patient. "
"Discontinue the existing prescription to prescribe again."
)
}
if "medicine" in attrs:
medicine_id = attrs["medicine"]
attrs["medicine"] = get_object_or_404(
MedibaseMedicine, external_id=medicine_id
)

# Check for existing prescription
if (
not self.instance
and Prescription.objects.filter(
consultation__external_id=self.context["request"].parser_context[
"kwargs"
]["consultation_external_id"],
medicine=attrs["medicine"],
discontinued=False,
).exists()
):
raise serializers.ValidationError(
{
"medicine": (
"This medicine is already prescribed to this patient. "
"Discontinue the existing prescription to prescribe again."
)
}
)

def _validate_max_dosage_presence(self, base_dosage: str, max_dosage: str) -> None:
if max_dosage and not base_dosage:
raise serializers.ValidationError(
Expand Down

0 comments on commit 6cba5a5

Please sign in to comment.