diff --git a/api/reports/sql_func.py b/api/reports/sql_func.py index 55a7819dca..235ae2e37a 100644 --- a/api/reports/sql_func.py +++ b/api/reports/sql_func.py @@ -70,7 +70,7 @@ def get_simple_directions_for_hosp_stationar(iss_id): cursor.execute( """ SELECT - directions_napravleniya.id as directionn_id + directions_napravleniya.id as direction_id FROM directions_napravleniya WHERE directions_napravleniya.parent_id in %(iss_id)s """, @@ -92,21 +92,30 @@ def get_field_results(directions, input_field, fraction_field): dpif.title as field_title, dpif.statistic_pattern_param_id as input_static_param, dr.value as fraction_value, - df.statistic_pattern_param_id as fraction_static_param + df.statistic_pattern_param_id as fraction_static_param, + dn.parent_id as parrent_iss, + pd.napravleniye_id as hosp_direction, + ci.family, + ci.name, + ci.patronymic, + to_char(ci.birthday, 'DD.MM.YYYY') as born, + to_char(EXTRACT(YEAR from age(directions_issledovaniya.time_confirmation, ci.birthday)), '999') as ind_age FROM directions_issledovaniya LEFT JOIN directions_napravleniya dn on directions_issledovaniya.napravleniye_id = dn.id LEFT JOIN directions_paraclinicresult dp on directions_issledovaniya.id = dp.issledovaniye_id + LEFT JOIN clients_card cc on dn.client_id = cc.id + LEFT JOIN clients_individual ci on cc.individual_id = ci.id LEFT JOIN directory_paraclinicinputfield dpif on dp.field_id = dpif.id LEFT JOIN directions_result dr on directions_issledovaniya.id = dr.issledovaniye_id - LEFT JOIN directory_fractions df on dr.fraction_id = df.id + LEFT JOIN directory_fractions df on dr.fraction_id = df.id + LEFT JOIN directions_issledovaniya pd on pd.id = dn.parent_id + WHERE directions_issledovaniya.napravleniye_id in %(directions)s AND directions_issledovaniya.time_confirmation is not Null - AND ( dpif.id in %(input_field)s OR df.id in %(fraction_field)s - ) - ORDER BY time_confirm - + AND ( dpif.id in %(input_field)s OR df.id in %(fraction_field)s) + ORDER BY pd.napravleniye_id """, params={'directions': directions, 'input_field': input_field, 'fraction_field': fraction_field, 'tz': TIME_ZONE}, ) diff --git a/api/reports/statistic_model/base_columns.py b/api/reports/statistic_model/base_columns.py new file mode 100644 index 0000000000..47e066ad77 --- /dev/null +++ b/api/reports/statistic_model/base_columns.py @@ -0,0 +1,80 @@ +from openpyxl.styles import Border, Side, Alignment, Font, NamedStyle +from openpyxl.utils.cell import get_column_letter + + +def custom_research_data(query_sql): + result = [] + prev_direction = None + step = 0 + tmp_result = { + "permanent_field": { + "Случай": "", + "Протокол": "", + "Пациент": "", + "Пол": "", + "Дата рождения": "", + "Возраст": "", + "Адрес": "", + }, + "custom_field": {}, + } + custom_fields = [] + for i in query_sql: + if prev_direction != i.direction_id and step != 0: + result.append(tmp_result.copy()) + if prev_direction != i.direction_number: + tmp_result = { + "permanent_field": { + "Случай": f"{i.hosp_direction}", + "Протокол": f"{i.direction_id}", + "Пациент": f"{i.family} {i.name} {i.patronymic}", + "Пол": i.patient_sex, + "Дата рождения": i.born, + "Возраст": i.ind_age, + "Адрес": i.patient_fact_address if i.patient_fact_address else i.patient_main_address, + } + } + tmp_result["custom_field"][i.field_title] = i.field_value + if i.field_title not in custom_fields: + custom_fields.append(i.field_title) + step += 1 + prev_direction = i.direction_id + result.append(tmp_result.copy()) + fields = ["Случай", "Протокол", "Пациент", "Пол", "Дата рождения", "Возраст", "Адрес"] + fields.extend(custom_fields) + return {"result": result, "custom_fields": custom_fields, "fields": fields} + + +def custom_research_base(ws1, d1, d2, result_query, research_title): + style_border = NamedStyle(name="style_border_ca") + bd = Side(style='thin', color="000000") + style_border.border = Border(left=bd, top=bd, right=bd, bottom=bd) + style_border.font = Font(bold=True, size=11) + style_border.alignment = Alignment(wrap_text=True, horizontal='center', vertical='center') + + ws1.cell(row=1, column=1).value = 'Услуга:' + ws1.cell(row=1, column=2).value = research_title + ws1.cell(row=2, column=1).value = 'Период:' + ws1.cell(row=3, column=1).value = f'c {d1} по {d2}' + + columns = [ + ('Направление', 15), + ('Источник', 15), + ('Пациент', 45), + ('Пол', 10), + ('Дата рождения', 26), + ('Возраст', 10), + ('Адрес', 40), + ('Исполнитель', 35), + ('Код врача', 15), + ] + + columns2 = [(i, 25) for i in result_query["custom_fields"]] + columns.extend(columns2) + row = 5 + for idx, column in enumerate(columns, 1): + ws1.cell(row=row, column=idx).value = column[0] + ws1.column_dimensions[get_column_letter(idx)].width = column[1] + ws1.cell(row=row, column=idx).style = style_border + + return ws1 \ No newline at end of file diff --git a/api/reports/statistic_model/variable_columns.py b/api/reports/statistic_model/variable_columns.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/reports/views.py b/api/reports/views.py index 54d074f105..a0aa536bd6 100644 --- a/api/reports/views.py +++ b/api/reports/views.py @@ -78,12 +78,18 @@ def xlsx_model(request): if request.method == "POST": data = json.loads(request.body) directions = data.get("directions") + hosp_directions = data.get("hospDirections") id_model = data.get("idModel") - sql_pair_direction_iss = {i.iss_id: i.direction_id for i in get_pair_direction_iss(tuple(directions))} + sql_pair_direction_iss = {i.iss_id: i.direction_id for i in get_pair_direction_iss(tuple(hosp_directions))} + sql_simple_directions = [i.direction_id for i in get_simple_directions_for_hosp_stationar(tuple(sql_pair_direction_iss.keys()))] + directions.extend(sql_simple_directions) + res_dir = set(directions) statistic_param_data = StatisticPatternParamSet.get_statistic_param(id_model) input_field_statistic_param = ParaclinicInputField.get_field_input_by_pattern_param(list(statistic_param_data.keys())) laboratory_fractions_statistic_param = Fractions.get_fraction_id_by_pattern_param(list(statistic_param_data.keys())) - result_directions = get_field_results(tuple(sql_simple_directions), tuple(input_field_statistic_param), tuple(laboratory_fractions_statistic_param)) + if len(laboratory_fractions_statistic_param) == 0: + laboratory_fractions_statistic_param = [-1] + result_directions = get_field_results(tuple(res_dir), tuple(input_field_statistic_param), tuple(laboratory_fractions_statistic_param)) return JsonResponse({"results": "file-xls-model", "link": "open-xls", "result": result_directions}) diff --git a/api/researches/views.py b/api/researches/views.py index 4d63d2e47a..ca1056c8a4 100644 --- a/api/researches/views.py +++ b/api/researches/views.py @@ -331,13 +331,14 @@ def researches_by_department(request): response = {"researches": [], "direction_forms": direction_form, "result_forms": result_form, "specialities": spec_data, "permanent_directories": NSI, "period_types": period_types} request_data = json.loads(request.body) + is_constructor = request_data.get('isConstructor') department_pk = int(request_data["department"]) user_groups = [str(x) for x in request.user.groups.all()] check_self_access_edit_research = False access_edit_research_ids = [] doctor_id = request.user.doctorprofile.pk - if "Конструктор: Редактировать свои услуги" in user_groups: + if is_constructor and "Конструктор: Редактировать свои услуги" in user_groups: check_self_access_edit_research = True doctor_department = request.user.doctorprofile.podrazdeleniye_id research_sql_data = get_constructor_edit_access_by_department_or_doctor(int(doctor_department), int(doctor_id)) @@ -687,7 +688,8 @@ def researches_update(request): f.hide = field["hide"] f.default_value = field["default"] f.visibility = field.get("visibility", "") - if field_data.field_type != field.get("field_type", 0): + su = request.user.is_superuser or request.user.doctorprofile.all_hospitals_users_control + if field_data.field_type != field.get("field_type", 0) and not su: return JsonResponse(response) f.field_type = field.get("field_type", 0) f.can_edit_computed = field.get("can_edit", False) diff --git a/l2-frontend/src/construct/ConstructParaclinic.vue b/l2-frontend/src/construct/ConstructParaclinic.vue index 5b6fc2646e..5e101d57c4 100644 --- a/l2-frontend/src/construct/ConstructParaclinic.vue +++ b/l2-frontend/src/construct/ConstructParaclinic.vue @@ -193,7 +193,7 @@ export default { load_researches() { this.$store.dispatch(actions.INC_LOADING); researchesPoint - .getResearchesByDepartment(this, 'department') + .getResearchesByDepartment(this, 'department', { isConstructor: true }) .then((data) => { this.researches_list = data.researches; this.direction_forms = data.direction_forms; diff --git a/l2-frontend/src/pages/Search.vue b/l2-frontend/src/pages/Search.vue index 0b594167be..d981c9544d 100644 --- a/l2-frontend/src/pages/Search.vue +++ b/l2-frontend/src/pages/Search.vue @@ -681,7 +681,8 @@ export default class SearchPage extends Vue { async genPatternReport() { await this.$store.dispatch(actions.INC_LOADING); const directions = this.results.map(el => (el.direction_number)); - const data = await this.$api('reports/xlsx-model', { directions, idModel: this.statisticPattern }); + const hospDirections = this.results.map(el => (el.history_num)); + const data = await this.$api('reports/xlsx-model', { directions, hospDirections, idModel: this.statisticPattern }); this.link = data.link; if (this.link) { window.open(`/statistic/${this.link}?file=${encodeURIComponent(JSON.stringify(data.results))}`, '_blank');