Skip to content

Commit

Permalink
add validator registr
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegGsk committed Oct 7, 2024
1 parent 2f6bee4 commit b6cf140
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion .github/workflows/prod_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ jobs:
echo "${{ secrets.ENV_FILE }}" > .env
cd infra/prod/
sudo systemctl stop adaptive_hockey_federation.service
docker system prune --force
sudo cp -f /home/production/adaptive_hockey_federation/infra/prod/adaptive_hockey_federation.service /etc/systemd/system/adaptive_hockey_federation.service
Expand Down
6 changes: 5 additions & 1 deletion adaptive_hockey_federation/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
StaffTeamMember,
Team,
)
from main.validators import validate_registr_diagnosis
from users.models import User


Expand Down Expand Up @@ -142,7 +143,10 @@ def clean_identity_document(self):
def clean_diagnosis(self):
"""Метод, выполняющий валидацию поля с диагнозом."""
nosology = self.cleaned_data.get("nosology")
diagnosis = self.cleaned_data.get("diagnosis")
diagnosis = validate_registr_diagnosis(
self.cleaned_data.get("diagnosis"),
)

if Diagnosis.objects.filter(name=diagnosis).exists():
diagnos = Diagnosis.objects.get(name=diagnosis)
if diagnos.nosology != nosology:
Expand Down
14 changes: 14 additions & 0 deletions adaptive_hockey_federation/main/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import re


def validate_registr_diagnosis(diagnosis: str) -> str:
"""
Метод, проверяющий диагноз на соответствие коду МКБ-10.
Если нет, то возвращает диагноз с заглавной буквы.
"""
pattern = r"^([A-Z]\d{2})(.\d)?$"

if not re.match(pattern, diagnosis):
return diagnosis.capitalize()
return diagnosis

0 comments on commit b6cf140

Please sign in to comment.