-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chambers-v3
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
directions/management/commands/change_client_slave_hosp_by_root_hosp.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,34 @@ | ||
from django.core.management.base import BaseCommand | ||
from directions.models import Napravleniya, Issledovaniya | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('history_id', type=str) | ||
|
||
def handle(self, *args, **kwargs): | ||
""" | ||
:param history_id - Номер направления на историю болезни | ||
Смена карты у всех подчиненных направлений в т.ч историй болезни, вывод историй у которых могут быть свои подчиненные услуги. | ||
Необходимо прогнать все истории которые будут выведены | ||
""" | ||
|
||
history_id = kwargs['history_id'] | ||
need_change_history_ids = set() | ||
direction: Napravleniya = Napravleniya.objects.filter(pk=history_id).first() | ||
if not direction: | ||
self.stdout.write('Такого направления нет') | ||
return None | ||
issledovanie: Issledovaniya = Issledovaniya.objects.filter(napravleniye_id=direction.pk).select_related('research').first() | ||
if not issledovanie.research.is_hospital: | ||
self.stdout.write('Данное направление не является историей болезни') | ||
return None | ||
slave_hospital_directions: issledovanie = Napravleniya.objects.filter(parent_id=issledovanie.pk) | ||
for slave_direction in slave_hospital_directions: | ||
slave_direction.client_id = direction.client_id | ||
slave_direction.save() | ||
self.stdout.write(f'У направления {slave_direction.pk} изменена карта на {direction.client_id}') | ||
slave_direction_issledovanie: Issledovaniya = Issledovaniya.objects.filter(napravleniye_id=slave_direction.pk).select_related('research').first() | ||
if slave_direction_issledovanie.research.is_hospital: | ||
need_change_history_ids.add(slave_direction.pk) | ||
self.stdout.write(f'Следующие направления - истории болезни (при необходимости повторите скрипт с этими направлениями) \n' f'{need_change_history_ids}') |