Skip to content

Commit

Permalink
add DenominationValidator to validate dosage fields in Prescription m…
Browse files Browse the repository at this point in the history
…odel (#1716)

* Add DosageValidator to Prescription model

* make the validator more generic

* fix migrations

* update migrations
  • Loading branch information
sainak authored Dec 7, 2023
1 parent d481c90 commit 46341e1
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Generated by Django 4.2.5 on 2023-12-06 13:06

from django.db import migrations, models

import care.utils.models.validators


class Migration(migrations.Migration):
dependencies = [
("facility", "0397_truncate_discharge_time"),
]

operations = [
migrations.AlterField(
model_name="prescription",
name="dosage",
field=models.CharField(
blank=True,
max_length=100,
null=True,
validators=[
care.utils.models.validators.DenominationValidator(
allow_floats=True,
max_amount=5000,
min_amount=0.0001,
precision=4,
units={"mg", "g", "ml", "tsp", "ampule(s)", "drop(s)"},
)
],
),
),
migrations.AlterField(
model_name="prescription",
name="max_dosage",
field=models.CharField(
blank=True,
max_length=100,
null=True,
validators=[
care.utils.models.validators.DenominationValidator(
allow_floats=True,
max_amount=5000,
min_amount=0.0001,
precision=4,
units={"mg", "g", "ml", "tsp", "ampule(s)", "drop(s)"},
)
],
),
),
]
9 changes: 7 additions & 2 deletions care/facility/models/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from care.facility.models.patient_consultation import PatientConsultation
from care.utils.models.base import BaseModel
from care.utils.models.validators import dosage_validator


class FrequencyEnum(enum.Enum):
Expand Down Expand Up @@ -92,7 +93,9 @@ class Prescription(BaseModel):
blank=True,
null=True,
)
dosage = models.CharField(max_length=100, blank=True, null=True)
dosage = models.CharField(
max_length=100, blank=True, null=True, validators=[dosage_validator]
)

is_prn = models.BooleanField(default=False)

Expand All @@ -107,7 +110,9 @@ class Prescription(BaseModel):

# prn fields
indicator = models.TextField(blank=True, null=True)
max_dosage = models.CharField(max_length=100, blank=True, null=True)
max_dosage = models.CharField(
max_length=100, blank=True, null=True, validators=[dosage_validator]
)
min_hours_between_doses = models.IntegerField(blank=True, null=True)

notes = models.TextField(default="", blank=True)
Expand Down
110 changes: 0 additions & 110 deletions care/facility/tests/test_medicine_administrations_api.py

This file was deleted.

Loading

0 comments on commit 46341e1

Please sign in to comment.