-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#127 - Adding validation to prescription base.
- Loading branch information
1 parent
a40cb41
commit 1694159
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Local Django | ||
from .patternvalidator import PatternValidator | ||
from .prescriptionbasevalidator import PrescriptionBaseValidator |
54 changes: 54 additions & 0 deletions
54
medical_prescription/prescription/validators/prescriptionbasevalidator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# django | ||
from django import forms | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
# local django | ||
from prescription import constants | ||
from user.constants import (NAME_MAX_LENGHT, | ||
NAME_MIN_LENGTH, | ||
NAME_SIZE | ||
) | ||
|
||
|
||
class PrescriptionBaseValidator(): | ||
""" | ||
Validator to prescription. | ||
""" | ||
|
||
def validate_patient(self, patient, patient_id): | ||
if len(patient) > NAME_MAX_LENGHT or len(patient) < NAME_MIN_LENGTH: | ||
raise forms.ValidationError(_(NAME_SIZE)) | ||
else: | ||
# Nothing to do. | ||
pass | ||
|
||
def validate_length_prescription(self, medicine, exam, recommendation): | ||
valid = False | ||
|
||
if len(medicine) == 1 and len(exam) == 1 and len(recommendation) == 1: | ||
|
||
for medicine_data in medicine: | ||
if len(medicine_data.data['form_medicine-0-medicine_id']) != 0: | ||
valid = True | ||
else: | ||
# Nothing to do. | ||
pass | ||
for exam_data in exam: | ||
if len(exam_data.data['form_exam-0-exam']) > 5: | ||
valid = True | ||
else: | ||
# Nothing to do. | ||
pass | ||
|
||
for recommendation_data in recommendation: | ||
if len(recommendation_data.data['form_recommendation-0-recommendation']) > 5: | ||
valid = True | ||
else: | ||
# Nothing to do. | ||
pass | ||
|
||
if not valid: | ||
raise forms.ValidationError(_(constants.EMPTY_PRESCRIPTION)) | ||
else: | ||
# Nothing to do. | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters