diff --git a/api/directions/sql_func.py b/api/directions/sql_func.py index 51292d5993..256b1e5523 100644 --- a/api/directions/sql_func.py +++ b/api/directions/sql_func.py @@ -621,7 +621,7 @@ def get_template_research_by_department(research_id, department_id, hide="true") directory_paraclinictemplatenamedepartment.department_id = %(department_id)s AND (directory_paraclinictemplatename.hide = %(hide)s or directory_paraclinictemplatename.hide = false) - ORDER BY directory_paraclinictemplatename.title + ORDER BY directory_paraclinictemplatename.id """, diff --git a/api/researches/views.py b/api/researches/views.py index a17900cfe4..55bdd4391b 100644 --- a/api/researches/views.py +++ b/api/researches/views.py @@ -31,6 +31,7 @@ ResearchGroup, ReleationsFT, ParaclinicTemplateNameDepartment, + ParaclinicFieldTemplateDepartment, ) from directory.utils import get_researches_details from laboratory.decorators import group_required @@ -448,6 +449,7 @@ def researches_update(request): info = request_data.get("info", "").strip() hide = request_data.get("hide") templates_by_department = request_data.get("templatesByDepartment") + department_template_pk = request_data.get("departmentForTemplatesField") site_type = request_data.get("site_type", None) groups = request_data.get("groups", []) tube = request_data.get("tube", -1) @@ -460,6 +462,10 @@ def researches_update(request): show_more_services = request_data.get("show_more_services", True) hospital_research_department_pk = request_data.get("hospital_research_department_pk", -1) current_nsi_research_code = request_data.get("currentNsiResearchCode", -1) + user = request.user + can_change_template_department = user.doctorprofile.has_group("Конструктор: Параклинические (описательные) исследования - шаблоны по подразделениям") + if not can_change_template_department: + can_change_template_department = user.is_superuser if tube == -1: tube = None stationar_slave = is_simple and -500 >= department_pk > -600 and main_service_pk != 1 @@ -480,7 +486,6 @@ def researches_update(request): is_paraclinic=not desc and department.p_type == 3, paraclinic_info=info, hide=hide, - templates_by_department=templates_by_department, is_doc_refferal=department_pk == -2, is_treatment=department_pk == -3, is_stom=department_pk == -4, @@ -514,6 +519,8 @@ def researches_update(request): show_more_services=show_more_services, nsi_id=current_nsi_research_code, ) + if can_change_template_department: + res.templates_by_department = templates_by_department elif DResearches.objects.filter(pk=pk).exists(): res = DResearches.objects.filter(pk=pk)[0] if res == researche_direction_current_params: @@ -543,7 +550,6 @@ def researches_update(request): res.microbiology_tube_id = tube if department_pk == -6 else None res.paraclinic_info = info res.hide = hide - res.templates_by_department = templates_by_department res.site_type_id = site_type res.internal_code = internal_code res.uet_refferal_doc = uet_refferal_doc @@ -560,6 +566,8 @@ def researches_update(request): res.has_own_form_result = own_form_result res.show_more_services = show_more_services and not res.is_microbiology and not res.is_form res.nsi_id = current_nsi_research_code + if can_change_template_department: + res.templates_by_department = templates_by_department if res: res.save() if main_service_pk != 1 and stationar_slave: @@ -601,6 +609,8 @@ def researches_update(request): g.fields_inline = group.get("fieldsInline", False) if g: g.save() + + department_template_field = None for field in group["fields"]: f = None pk = field["pk"] @@ -617,7 +627,6 @@ def researches_update(request): hide=field["hide"], default_value=field["default"], visibility=field.get("visibility", ""), - input_templates=json.dumps(field["values_to_input"]), field_type=field.get("field_type", 0), can_edit_computed=field.get("can_edit", False), helper=field.get("helper", ''), @@ -629,6 +638,12 @@ def researches_update(request): cda_option_id=field.get("cdaOption", -1) if field.get("cdaOption", -1) != -1 else None, patient_control_param_id=field.get("patientControlParam", -1) if field.get("patientControlParam", -1) != -1 else None, ) + if department_template_pk: + department_template_field = ParaclinicFieldTemplateDepartment( + paraclinic_field_id=f.pk, research_id=res.pk, department_id=department_template_pk, value=json.dumps(field["values_to_input"]) + ) + else: + f.input_templates = json.dumps(field["values_to_input"]) elif ParaclinicInputField.objects.filter(pk=pk).exists(): f = ParaclinicInputField.objects.get(pk=pk) f.title = field["title"] @@ -641,7 +656,6 @@ def researches_update(request): f.hide = field["hide"] f.default_value = field["default"] f.visibility = field.get("visibility", "") - f.input_templates = json.dumps(field["values_to_input"]) f.field_type = field.get("field_type", 0) f.can_edit_computed = field.get("can_edit", False) f.required = field.get("required", False) @@ -654,8 +668,21 @@ def researches_update(request): f.control_param = field.get("controlParam", '') f.patient_control_param_id = field.get("patientControlParam", -1) if field.get("patientControlParam", -1) != -1 else None f.cda_option_id = field.get("cdaOption", -1) if field.get("cdaOption", -1) != -1 else None + + if department_template_pk: + department_template_field: ParaclinicFieldTemplateDepartment = ParaclinicFieldTemplateDepartment.objects.filter(pk=f.pk).first() + if department_template_field: + department_template_field.value = json.dumps(field["values_to_input"]) + else: + department_template_field = ParaclinicFieldTemplateDepartment( + paraclinic_field_id=f.pk, research_id=res.pk, department_id=department_template_pk, value=json.dumps(field["values_to_input"]) + ) + else: + f.input_templates = json.dumps(field["values_to_input"]) if f: f.save() + if department_template_field: + department_template_field.save() if f.default_value == '': continue @@ -671,8 +698,8 @@ def researches_update(request): def researches_details(request): request_data = json.loads(request.body) pk = request_data.get("pk") - response = get_researches_details(pk) - + templates_department_pk = request_data.get("departmentForTemplatesField") + response = get_researches_details(pk, templates_department_pk) return JsonResponse(response) @@ -726,7 +753,7 @@ def fast_templates(request): elif department_id and not is_all: templates = get_template_research_by_department(research_id, department_id, hide="false") else: - templates = ParaclinicTemplateName.objects.filter(research__pk=request_data["pk"]).order_by('title') + templates = ParaclinicTemplateName.objects.filter(research__pk=request_data["pk"]).order_by('pk') if not is_all: templates = templates.filter(hide=False) result = [ diff --git a/directory/utils.py b/directory/utils.py index bdbe33d3cf..601eeb2e1f 100644 --- a/directory/utils.py +++ b/directory/utils.py @@ -1,3 +1,4 @@ +from api.directions.sql_func import get_template_field_by_department from directory.models import ( Researches as DResearches, ParaclinicInputGroups, @@ -10,7 +11,7 @@ from external_system.sql_func import get_unique_method_instrumental_diagnostic -def get_researches_details(pk): +def get_researches_details(pk, templates_department_pk=None): response = {"pk": -1, "department": -1, "title": '', "short_title": '', "code": '', "info": '', "hide": False, "groups": []} direction_params_all = [{"id": -1, "label": "Пусто"}, *[{"id": x.pk, "label": x.title} for x in DResearches.objects.filter(is_direction_params=True).order_by("title")]] response["direction_params_all"] = direction_params_all @@ -65,6 +66,10 @@ def get_researches_details(pk): if res.is_direction_params: response["assigned_to_params"] = [f'{x.pk} – {x.get_full_short_title()}' for x in DResearches.objects.filter(direction_params=res)] + templates_fields_data = {} + if res.templates_by_department and templates_department_pk: + templates_fields = get_template_field_by_department(res.pk, templates_department_pk) + templates_fields_data = {template.field_id: template.value for template in templates_fields} for group in ParaclinicInputGroups.objects.filter(research__pk=pk).order_by("order"): g = { "pk": group.pk, @@ -77,6 +82,7 @@ def get_researches_details(pk): "fieldsInline": group.fields_inline, "cdaOption": group.cda_option_id if group.cda_option else -1, } + for field in ParaclinicInputField.objects.filter(group=group).order_by("order"): g["fields"].append( { @@ -90,7 +96,7 @@ def get_researches_details(pk): "default": field.default_value, "visibility": field.visibility, "hide": field.hide, - "values_to_input": json.loads(field.input_templates), + "values_to_input": json.loads(field.input_templates) if not templates_department_pk else json.loads(templates_fields_data.get(field.pk, '[]')), "field_type": field.field_type, "can_edit": field.can_edit_computed, "required": field.required, diff --git a/l2-frontend/src/construct/FastTemplatesEditor.vue b/l2-frontend/src/construct/FastTemplatesEditor.vue index 554e6e2c34..5ad3c80013 100644 --- a/l2-frontend/src/construct/FastTemplatesEditor.vue +++ b/l2-frontend/src/construct/FastTemplatesEditor.vue @@ -19,7 +19,7 @@ v-model="department" class="treeselect-nbr treeselect-wide" :options="departments" - :clearable="false" + :clearable="showAllDepartments" placeholder="Выберите подразделение" /> @@ -197,7 +197,6 @@ import MKBField from '@/fields/MKBField.vue'; import researchesPoint from '@/api/researches-point'; import * as actions from '@/store/action-types'; import '@riophae/vue-treeselect/dist/vue-treeselect.css'; -import api from '@/api'; export default { name: 'FastTemplatesEditor', @@ -219,6 +218,18 @@ export default { type: Boolean, required: false, }, + departments: { + type: Array, + required: false, + }, + showAllDepartments: { + type: Boolean, + required: false, + }, + userDepartmentId: { + type: Number, + required: false, + }, }, data() { return { @@ -227,10 +238,7 @@ export default { selected_template: -2, template_data: {}, department: null, - departments: [], departmentsForTemplate: [], - showAllDepartments: false, - userDepartmentId: null, }; }, watch: { @@ -251,12 +259,12 @@ export default { }, }, created() { + this.load_data(); if (this.byDepartment) { - this.checkAdmin(); - this.loadDepartment(); - } else { - this.departments.push({ id: 'all', label: 'Все' }); - this.department = 'all'; + this.departmentsForTemplate = this.departments; + if (!this.showAllDepartments) { + this.department = this.departments[0].id; + } } }, methods: { @@ -290,7 +298,7 @@ export default { this.clear(); } let department = null; - if (this.department !== 'all') { + if (this.department) { department = this.department; } this.$store.dispatch(actions.INC_LOADING); @@ -303,22 +311,6 @@ export default { this.$store.dispatch(actions.DEC_LOADING); }); }, - async loadDepartment() { - await this.$store.dispatch(actions.INC_LOADING); - const { data } = await api('get-departments-with-exclude', { exclude_type: [2] }); - await this.$store.dispatch(actions.DEC_LOADING); - if (this.showAllDepartments) { - this.departments.push({ id: 'all', label: 'Все' }); - this.departments.push(...data); - this.departmentsForTemplate = data; - this.department = 'all'; - } else { - const userDepartment = data.find((department) => department.id === this.userDepartmentId); - this.departments.push(userDepartment); - this.departmentsForTemplate.push(userDepartment); - this.department = userDepartment.id; - } - }, select_template(pk) { if (pk === this.selected_template) return; this.$store.dispatch(actions.INC_LOADING); @@ -362,14 +354,6 @@ export default { this.$store.dispatch(actions.DEC_LOADING); }); }, - checkAdmin() { - this.userDepartmentId = this.$store.getters.user_data.department.pk; - const { groups } = this.$store.getters.user_data; - if (groups.includes('Конструктор: Параклинические (описательные) исследования - шаблоны по подразделениям') - || groups.includes('Admin')) { - this.showAllDepartments = true; - } - }, }, }; @@ -415,7 +399,7 @@ export default { position: relative; padding-bottom: 36px; .inner { - height: 100%; + height: calc(100% - 36px); width: 100%; overflow-y: auto; overflow-x: hidden; diff --git a/l2-frontend/src/construct/ParaclinicResearchEditor.vue b/l2-frontend/src/construct/ParaclinicResearchEditor.vue index e0da11fde8..a6d80c16d4 100644 --- a/l2-frontend/src/construct/ParaclinicResearchEditor.vue +++ b/l2-frontend/src/construct/ParaclinicResearchEditor.vue @@ -64,6 +64,7 @@ По подразделению @@ -92,6 +93,20 @@ +
+ Подразделения для шаблонов + +
По подразделению @@ -1113,6 +1129,9 @@ :research_pk="loaded_pk" :groups="groups" :by-department="templatesByDepartment" + :departments="departmentsForTemplatesField" + :show-all-departments="showAllDepartmentForTemplateField" + :user-department-id="userDepartmentId" /> { @@ -1594,7 +1623,7 @@ export default { } this.groups.push(g); }, - load() { + async load() { this.title = ''; this.short_title = ''; this.autoRegisterRmisLocation = ''; @@ -1603,7 +1632,6 @@ export default { this.code = ''; this.info = ''; this.hide = false; - this.templatesByDepartment = false; this.site_type = null; this.groups = []; this.direction_current_form = ''; @@ -1614,49 +1642,44 @@ export default { this.hospital_research_department_pk = -1; this.type_period = null; if (this.pk >= 0) { - this.$store.dispatch(actions.INC_LOADING); - constructPoint - .researchDetails(this, 'pk') - .then(data => { - this.title = data.title; - this.short_title = data.short_title; - this.autoRegisterRmisLocation = data.autoRegisterRmisLocation; - this.schedule_title = data.schedule_title; - this.is_global_direction_params = data.is_global_direction_params; - this.code = data.code; - this.internal_code = data.internal_code; - this.uet_refferal_doc = data.uet_refferal_doc; - this.uet_refferal_co_executor_1 = data.uet_refferal_co_executor_1; - this.direction_current_form = data.direction_current_form; - this.result_current_form = data.result_current_form; - this.currentNsiResearchCode = data.currentNsiResearchCode; - this.collectNsiResearchCode = data.collectNsiResearchCode; - this.collectMethods = data.collectMethods; - this.speciality = data.speciality; - this.hospital_research_department_pk = data.department; - this.info = data.info.replace(//g, '\n').replace(/
/g, '\n'); - this.hide = data.hide; - this.templatesByDepartment = data.templatesByDepartment; - this.site_type = data.site_type; - this.loaded_pk = this.pk; - this.groups = data.groups; - this.direction_params_all = data.direction_params_all; - this.patient_control_param_all = data.patient_control_param_all; - this.cda_options = data.cda_options; - this.direction_current_params = data.direction_current_params; - this.direction_expertise_all = data.direction_expertise_all; - this.direction_current_expertise = data.direction_current_expertise; - this.assigned_to_params = data.assigned_to_params; - this.show_more_services = data.show_more_services; - this.is_paraclinic = data.is_paraclinic; - this.type_period = data.type_period; - if (this.groups.length === 0) { - this.add_group(); - } - }) - .finally(() => { - this.$store.dispatch(actions.DEC_LOADING); - }); + await this.$store.dispatch(actions.INC_LOADING); + const data = await constructPoint.researchDetails(this, ['pk', 'departmentForTemplatesField']); + await this.$store.dispatch(actions.DEC_LOADING); + this.title = data.title; + this.short_title = data.short_title; + this.autoRegisterRmisLocation = data.autoRegisterRmisLocation; + this.schedule_title = data.schedule_title; + this.is_global_direction_params = data.is_global_direction_params; + this.code = data.code; + this.internal_code = data.internal_code; + this.uet_refferal_doc = data.uet_refferal_doc; + this.uet_refferal_co_executor_1 = data.uet_refferal_co_executor_1; + this.direction_current_form = data.direction_current_form; + this.result_current_form = data.result_current_form; + this.currentNsiResearchCode = data.currentNsiResearchCode; + this.collectNsiResearchCode = data.collectNsiResearchCode; + this.collectMethods = data.collectMethods; + this.speciality = data.speciality; + this.hospital_research_department_pk = data.department; + this.info = data.info.replace(//g, '\n').replace(/
/g, '\n'); + this.hide = data.hide; + this.templatesByDepartment = data.templatesByDepartment; + this.site_type = data.site_type; + this.loaded_pk = this.pk; + this.groups = data.groups; + this.direction_params_all = data.direction_params_all; + this.patient_control_param_all = data.patient_control_param_all; + this.cda_options = data.cda_options; + this.direction_current_params = data.direction_current_params; + this.direction_expertise_all = data.direction_expertise_all; + this.direction_current_expertise = data.direction_current_expertise; + this.assigned_to_params = data.assigned_to_params; + this.show_more_services = data.show_more_services; + this.is_paraclinic = data.is_paraclinic; + this.type_period = data.type_period; + if (this.groups.length === 0) { + this.add_group(); + } } else { this.add_group(); } @@ -1685,6 +1708,7 @@ export default { 'code', 'hide', 'templatesByDepartment', + 'departmentForTemplatesField', 'groups', 'site_type', 'internal_code', @@ -1732,6 +1756,29 @@ export default { const { rows } = await this.$api('external-system/fsidi-by-method', { method: this.currentMethod }); this.collectNsiResearchCode = rows; }, + async loadDepartmentsForTemplate() { + await this.$store.dispatch(actions.INC_LOADING); + const { data } = await this.$api('get-departments-with-exclude', { exclude_type: [2] }); + await this.$store.dispatch(actions.DEC_LOADING); + if (this.showAllDepartmentForTemplateField) { + this.departmentsForTemplatesField.push(...data); + } else { + const userDepartment = data.find((department) => department.id === this.userDepartmentId); + this.departmentsForTemplatesField.push(userDepartment); + this.departmentForTemplatesField = userDepartment.id; + } + }, + checkShowAllTemplates() { + this.userDepartmentId = this.$store.getters.user_data.department.pk; + const { groups } = this.$store.getters.user_data; + if (groups.includes('Конструктор: Параклинические (описательные) исследования - шаблоны по подразделениям') + || groups.includes('Admin')) { + this.showAllDepartmentForTemplateField = true; + } + }, + async changeTemplateField() { + await this.load(); + }, }, };