Skip to content

Commit

Permalink
Merge pull request #4279 from mikhailprivalov/new-templates
Browse files Browse the repository at this point in the history
Шаблоны по подразделению
  • Loading branch information
urchinpro authored Sep 18, 2024
2 parents b9b9c77 + 5a1e0d9 commit 2d052ba
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 5 deletions.
47 changes: 47 additions & 0 deletions api/directions/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,50 @@ def get_total_confirm_direction(d_s, d_e, lab_podr, is_lab=False, is_paraclinic=
)
rows = namedtuplefetchall(cursor)
return rows


def get_template_research_by_department(research_id, department_id):
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT directory_paraclinictemplatename.id, directory_paraclinictemplatename.title
FROM public.directory_paraclinictemplatenamedepartment
INNER JOIN directory_paraclinictemplatename ON
directory_paraclinictemplatenamedepartment.template_name_id = directory_paraclinictemplatename.id
WHERE
directory_paraclinictemplatename.research_id = %(research_id)s AND
directory_paraclinictemplatenamedepartment.department_id = %(department_id)s
ORDER BY directory_paraclinictemplatename.title
""",
params={
'research_id': research_id,
'department_id': department_id,
},
)
rows = namedtuplefetchall(cursor)
return rows


def get_template_field_by_department(research_id, department_id):
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT
directory_paraclinicfieldtemplatedepartment.paraclinic_field_id as field_id,
directory_paraclinicfieldtemplatedepartment.value
FROM directory_paraclinicfieldtemplatedepartment
WHERE
directory_paraclinicfieldtemplatedepartment.department_id = %(department_id)s AND
directory_paraclinicfieldtemplatedepartment.research_id = %(research_id)s
""",
params={
'research_id': research_id,
'department_id': department_id,
},
)
rows = namedtuplefetchall(cursor)
return rows
37 changes: 32 additions & 5 deletions api/directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
get_confirm_direction_by_hospital,
get_directions_meta_info,
get_patient_open_case_data,
get_template_research_by_department,
get_template_field_by_department,
)
from api.stationar.stationar_func import hosp_get_hosp_direction, hosp_get_text_iss
from forms.forms_func import hosp_get_operation_data
Expand Down Expand Up @@ -1516,6 +1518,7 @@ def directions_paraclinic_form(request):
pk //= 10
add_fr = {}
f = False
doc_department_id = request.user.doctorprofile.podrazdeleniye_id
user_groups = [str(x) for x in request.user.groups.all()]
is_without_limit_paraclinic = "Параклиника без ограничений" in user_groups
if not request.user.is_superuser and not is_without_limit_paraclinic:
Expand Down Expand Up @@ -1868,18 +1871,37 @@ def directions_paraclinic_form(request):
}
)

ParaclinicTemplateName.make_default(i.research)
rts = ParaclinicTemplateName.objects.filter(research=i.research, hide=False)
default_template = ParaclinicTemplateName.make_default(i.research)

for rt in rts.order_by('title'):
if i.research.is_template_by_department:
templates_by_department = get_template_research_by_department(i.research_id, doc_department_id)
templates_data = [{"pk": template.id, "title": template.title} for template in templates_by_department]
iss["templates"].append(
{
"pk": rt.pk,
"title": rt.title,
"pk": default_template.pk,
"title": default_template.title,
}
)
iss["templates"].extend(templates_data)

else:
rts = ParaclinicTemplateName.objects.filter(research=i.research, hide=False)

for rt in rts.order_by('title'):
iss["templates"].append(
{
"pk": rt.pk,
"title": rt.title,
}
)

result_fields = {x.field_id: x for x in ParaclinicResult.objects.filter(issledovaniye=i)}

fields_templates_by_department_data = None
if i.research.is_template_by_department:
fields_templates_by_department = get_template_field_by_department(i.research_id, doc_department_id)
fields_templates_by_department_data = {field_template.field_id: field_template.value for field_template in fields_templates_by_department}

for group in i.research.paraclinicinputgroups_set.all():
g = {
"pk": group.pk,
Expand All @@ -1900,6 +1922,11 @@ def directions_paraclinic_form(request):
values_to_input = ([] if not field.required or field_type not in [10, 12] or i.research.is_monitoring else ['- Не выбрано']) + (
[] if field.input_templates == '[]' or not field.input_templates else json.loads(field.input_templates)
)
if fields_templates_by_department_data:
values_to_input_by_department = fields_templates_by_department_data.get(field.pk)
if values_to_input_by_department:
values_to_input = json.loads(values_to_input_by_department)

value = (
((field.default_value if field_type not in [3, 11, 13, 14, 30] else '') if not result_field else result_field.value)
if field_type not in [1, 20]
Expand Down
23 changes: 23 additions & 0 deletions directory/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ class ResParaclinicInputField(admin.ModelAdmin):
)


class ResParaclinicFieldTemplateDepartment(admin.ModelAdmin):
list_display = (
'paraclinic_field',
'research',
'department',
)
list_display_links = (
'paraclinic_field',
'research',
'department',
)


class ResParaclinicTemplateDepartment(admin.ModelAdmin):
list_display = (
'template_name',
'department',
)
list_display_links = ('template_name', 'department')


class ResParaclinicInputGroups(admin.ModelAdmin):
list_display = (
'title',
Expand Down Expand Up @@ -287,6 +308,7 @@ class SetComplexService(admin.ModelAdmin):
admin.site.register(models.Researches, ResAdmin)
admin.site.register(models.ParaclinicInputGroups, ResParaclinicInputGroups)
admin.site.register(models.ParaclinicInputField, ResParaclinicInputField)
admin.site.register(models.ParaclinicFieldTemplateDepartment, ResParaclinicFieldTemplateDepartment)
admin.site.register(models.References, RefAdmin)
admin.site.register(models.ResultVariants)
admin.site.register(models.MaterialVariants)
Expand Down Expand Up @@ -315,6 +337,7 @@ class SetComplexService(admin.ModelAdmin):
admin.site.register(models.SetOrderResearch, SetOrderResearchAdmin)
admin.site.register(models.AuxService, SetAuxService)
admin.site.register(models.ComplexService, SetComplexService)
admin.site.register(models.ParaclinicTemplateNameDepartment, ResParaclinicTemplateDepartment)
admin.site.register(models.LaboratoryMaterial)
admin.site.register(models.SubGroupDirectory)
admin.site.register(models.SubGroupPadrazdeleniye)
35 changes: 35 additions & 0 deletions directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class Researches(models.Model):
laboratory_duration = models.CharField(max_length=3, default="", blank=True, verbose_name="Срок выполнения")
is_need_send_egisz = models.BooleanField(blank=True, default=False, help_text="Требуется отправка документав ЕГИСЗ")
count_volume_material_for_tube = models.FloatField(default=0, verbose_name="Количество материала для емкости в долях", blank=True)
is_template_by_department = models.BooleanField(default=False, help_text="Искать шаблон заполнения по подразделению")

@staticmethod
def save_plan_performer(tb_data):
Expand Down Expand Up @@ -1209,6 +1210,24 @@ class Meta:
verbose_name_plural = "Поля описательного протокола"


class ParaclinicFieldTemplateDepartment(models.Model):
"""
Шаблоны подразделений на поля
"""

paraclinic_field = models.ForeignKey(ParaclinicInputField, verbose_name="Поле в кротоколе", on_delete=models.CASCADE)
research = models.ForeignKey(Researches, verbose_name="Услуга", on_delete=models.CASCADE, db_index=True)
department = models.ForeignKey(Podrazdeleniya, verbose_name="Подразделение", on_delete=models.CASCADE, db_index=True)
value = models.TextField(verbose_name="Значение", help_text="Список значений ['', '']")

class Meta:
verbose_name = "Шаблон на поле для подразделения"
verbose_name_plural = "Шаблоны на поля для подразделений"

def __str__(self):
return f"{self.paraclinic_field.title} - {self.research.title} {self.department_id}"


class ParaclinicTemplateName(models.Model):
DEFAULT_TEMPLATE_TITLE = "По умолчанию"

Expand Down Expand Up @@ -1249,6 +1268,22 @@ def __str__(self):
return f"{self.field}, {self.value}"


class ParaclinicTemplateNameDepartment(models.Model):
"""
Шаблоны подразделений на услуги
"""

template_name = models.ForeignKey(ParaclinicTemplateName, verbose_name="Шаблон на услугу", on_delete=models.CASCADE)
department = models.ForeignKey(Podrazdeleniya, verbose_name="Подразделение", on_delete=models.CASCADE, db_index=True)

class Meta:
verbose_name = "Шаблон на услугу для подразделения"
verbose_name_plural = "Шаблоны на услуги для подразделений"

def __str__(self):
return f"{self.template_name.title} - {self.department_id}"


class AutoAdd(models.Model):
"""
Перечисление связей исследований, которые могут быть назначены только вместе (A только с B)
Expand Down

0 comments on commit 2d052ba

Please sign in to comment.