Skip to content

Commit

Permalink
Merge pull request #4686 from mikhailprivalov/constructor-complex-fix
Browse files Browse the repository at this point in the history
Конструктор комплексных услуг - улучшения
  • Loading branch information
urchinpro authored Feb 4, 2025
2 parents a9f4833 + 58c5284 commit 97a9cd2
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 93 deletions.
2 changes: 1 addition & 1 deletion api/construct/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
path('complex/get-complexes', views.get_complexes),
path('complex/check-hidden', views.check_complex_hidden),
path('complex/get-services', views.get_services_in_complex),
path('complex/add-service', views.add_service_in_complex),
path('complex/add-services', views.add_services_in_complex),
path('complex/change-complex-hidden', views.change_complex_hidden),
path('complex/update-complex', views.update_complex),
path('complex/change-service-hidden', views.change_service_hidden),
Expand Down
12 changes: 7 additions & 5 deletions api/construct/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ def get_services_in_complex(request):

@login_required
@group_required("Конструктор: Комплексные услуги")
def add_service_in_complex(request):
def add_services_in_complex(request):
request_data = json.loads(request.body)
complex_id = request_data.get("complexId")
service_id = request_data.get("serviceId")
result = ComplexService.add_service(complex_id, service_id)
Log.log(result["result"], 210003, request.user.doctorprofile, {"complex_id": complex_id, "service_id": service_id})
return status_response(result["ok"])
service_ids = request_data.get("serviceIds")
result = ComplexService.add_services(complex_id, service_ids)
if result["ok"]:
success_add = set(service_ids) - result["errors_ids"]
Log.log(complex_id, 210003, request.user.doctorprofile, {"complex_id": complex_id, "services_id": list(success_add)})
return JsonResponse({"ok": result["ok"], "message": result["message"], "errors": result.get("errors_reason")})


@login_required
Expand Down
7 changes: 4 additions & 3 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2831,13 +2831,14 @@ def update_coast_research_in_price(request):
@login_required
@group_required("Конструктор: Настройка организации")
def get_research_list(request):
request_data = json.loads(request.body)
exclude_categories = request_data.get("exclude_categories")
researches = Researches.objects.all().order_by("title")
res_list = Researches.gen_non_excluded_categories()

res_list = Researches.gen_non_excluded_categories(exclude_categories)
lab_podr = get_lab_podr()
lab_podr = [podr[0] for podr in lab_podr]
for research in researches:
if not Researches.check_exclude(research):
if not Researches.check_exclude(research, exclude_categories):
continue
is_hide = ""
if research.hide:
Expand Down
159 changes: 91 additions & 68 deletions directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class Meta:
def get_file_path_to_schemas(instance: 'Researches', filename):
return os.path.join('schemas-pdf', str(instance.pk), str(uuid.uuid4()), filename)


class Researches(models.Model):
"""
Вид исследования
Expand Down Expand Up @@ -835,67 +836,92 @@ def get_all_ids(array: bool = False, hide: bool = False):
return result

@staticmethod
def check_exclude(research):
def check_exclude(research, exclude_categories: list = None):
"""Проверка на исключенные типы услуг, на входе либо SQL namedtuple, либо объект researches"""
result = True
if research.is_paraclinic and EXCLUDE_TYPE_RESEARCH["is_paraclinic"]:
result = False
elif research.is_doc_refferal and EXCLUDE_TYPE_RESEARCH["is_doc_refferal"]:
result = False
elif research.is_treatment and EXCLUDE_TYPE_RESEARCH["is_treatment"]:
result = False
elif research.is_stom and EXCLUDE_TYPE_RESEARCH["is_stom"]:
result = False
elif research.is_hospital and EXCLUDE_TYPE_RESEARCH["is_hospital"]:
result = False
elif research.is_slave_hospital and EXCLUDE_TYPE_RESEARCH["is_slave_hospital"]:
result = False
elif research.is_microbiology and EXCLUDE_TYPE_RESEARCH["is_microbiology"]:
result = False
elif research.is_citology and EXCLUDE_TYPE_RESEARCH["is_citology"]:
result = False
elif research.is_gistology and EXCLUDE_TYPE_RESEARCH["is_gistology"]:
result = False
elif research.is_form and EXCLUDE_TYPE_RESEARCH["is_form"]:
result = False
elif research.is_application and EXCLUDE_TYPE_RESEARCH["is_application"]:
result = False
elif research.is_direction_params and EXCLUDE_TYPE_RESEARCH["is_direction_params"]:
result = False
elif research.is_global_direction_params and EXCLUDE_TYPE_RESEARCH["is_global_direction_params"]:
result = False
elif research.is_monitoring and EXCLUDE_TYPE_RESEARCH["is_monitoring"]:
result = False
elif research.is_expertise and EXCLUDE_TYPE_RESEARCH["is_expertise"]:
result = False
elif research.is_aux and EXCLUDE_TYPE_RESEARCH["is_aux"]:
result = False
elif research.is_case and EXCLUDE_TYPE_RESEARCH["is_case"]:
result = False
elif research.is_complex and EXCLUDE_TYPE_RESEARCH["is_complex"]:
result = False
elif EXCLUDE_TYPE_RESEARCH["is_laboratory"]:
if research.is_paraclinic:
if EXCLUDE_TYPE_RESEARCH["is_paraclinic"] or (exclude_categories and "is_paraclinic" in exclude_categories):
result = False
elif research.is_doc_refferal:
if EXCLUDE_TYPE_RESEARCH["is_doc_refferal"] or (exclude_categories and "is_doc_refferal" in exclude_categories):
result = False
elif research.is_treatment:
if EXCLUDE_TYPE_RESEARCH["is_treatment"] or (exclude_categories and "is_treatment" in exclude_categories):
result = False
elif research.is_stom:
if EXCLUDE_TYPE_RESEARCH["is_stom"] or (exclude_categories and "is_stom" in exclude_categories):
result = False
elif research.is_hospital:
if EXCLUDE_TYPE_RESEARCH["is_hospital"] or (exclude_categories and "is_hospital" in exclude_categories):
result = False
elif research.is_slave_hospital:
if EXCLUDE_TYPE_RESEARCH["is_slave_hospital"] or (exclude_categories and "is_slave_hospital" in exclude_categories):
result = False
elif research.is_microbiology:
if EXCLUDE_TYPE_RESEARCH["is_microbiology"] or (exclude_categories and "is_microbiology" in exclude_categories):
result = False
elif research.is_citology:
if EXCLUDE_TYPE_RESEARCH["is_citology"] or (exclude_categories and "is_citology" in exclude_categories):
result = False
elif research.is_gistology:
if EXCLUDE_TYPE_RESEARCH["is_gistology"] or (exclude_categories and "is_gistology" in exclude_categories):
result = False
elif research.is_form:
if EXCLUDE_TYPE_RESEARCH["is_form"] or (exclude_categories and "is_form" in exclude_categories):
result = False
elif research.is_application:
if EXCLUDE_TYPE_RESEARCH["is_application"] or (exclude_categories and "is_application" in exclude_categories):
result = False
elif research.is_direction_params:
if EXCLUDE_TYPE_RESEARCH["is_direction_params"] or (exclude_categories and "is_direction_params" in exclude_categories):
result = False
elif research.is_global_direction_params:
if EXCLUDE_TYPE_RESEARCH["is_global_direction_params"] or (exclude_categories and "is_global_direction_params" in exclude_categories):
result = False
elif research.is_monitoring:
if EXCLUDE_TYPE_RESEARCH["is_monitoring"] or (exclude_categories and "is_monitoring" in exclude_categories):
result = False
elif research.is_expertise:
if EXCLUDE_TYPE_RESEARCH["is_expertise"] or (exclude_categories and "is_expertise" in exclude_categories):
result = False
elif research.is_aux:
if EXCLUDE_TYPE_RESEARCH["is_aux"] or (exclude_categories and "is_aux" in exclude_categories):
result = False
elif research.is_case:
if EXCLUDE_TYPE_RESEARCH["is_case"] or (exclude_categories and "is_case" in exclude_categories):
result = False
elif research.is_complex:
if EXCLUDE_TYPE_RESEARCH["is_complex"] or (exclude_categories and "is_complex" in exclude_categories):
result = False
elif EXCLUDE_TYPE_RESEARCH["is_laboratory"] or (exclude_categories and "is_laboratory" in exclude_categories):
result = False
return result

@staticmethod
def gen_non_excluded_categories():
def gen_non_excluded_categories(exclude_categories: list = None):
res_list = {}
if not EXCLUDE_TYPE_RESEARCH["is_laboratory"]:
if not EXCLUDE_TYPE_RESEARCH["is_laboratory"] and not exclude_categories or "is_laboratory" not in exclude_categories:
res_list["Лаборатория"] = {}
if not EXCLUDE_TYPE_RESEARCH["is_paraclinic"]:
if not EXCLUDE_TYPE_RESEARCH["is_paraclinic"] and not exclude_categories or "is_paraclinic" not in exclude_categories:
res_list["Параклиника"] = {}
if not EXCLUDE_TYPE_RESEARCH["is_doc_refferal"]:
if not EXCLUDE_TYPE_RESEARCH["is_doc_refferal"] and not exclude_categories or "is_doc_refferal" not in exclude_categories:
res_list["Консультации"] = {"Общие": []}
if not EXCLUDE_TYPE_RESEARCH["is_form"]:
if not EXCLUDE_TYPE_RESEARCH["is_form"] and not exclude_categories or "is_form" not in exclude_categories:
res_list["Формы"] = {"Общие": []}
if not EXCLUDE_TYPE_RESEARCH["is_treatment"]:
if not EXCLUDE_TYPE_RESEARCH["is_treatment"] and not exclude_categories or "is_treatment" not in exclude_categories:
res_list["Лечение"] = {"Общие": []}
if not EXCLUDE_TYPE_RESEARCH["is_microbiology"] and not EXCLUDE_TYPE_RESEARCH["is_gistology"] and not EXCLUDE_TYPE_RESEARCH["is_citology"]:
res_list["Морфология"] = {"Микробиология": [], "Гистология": [], "Цитология": []}
if not EXCLUDE_TYPE_RESEARCH["is_stom"]:
tmp_morfology = {}
if not EXCLUDE_TYPE_RESEARCH["is_microbiology"] and not exclude_categories or "is_microbiology" not in exclude_categories:
tmp_morfology["Микробиология"] = []
if not EXCLUDE_TYPE_RESEARCH["is_gistology"] and not exclude_categories or "is_gistology" not in exclude_categories:
tmp_morfology["Гистология"] = []
if not EXCLUDE_TYPE_RESEARCH["is_citology"] and not exclude_categories or "is_citology" not in exclude_categories:
tmp_morfology["Цитология"] = []
if len(tmp_morfology) > 0:
res_list["Морфология"] = tmp_morfology
if not EXCLUDE_TYPE_RESEARCH["is_stom"] and not exclude_categories or "is_stom" not in exclude_categories:
res_list["Стоматология"] = {"Общие": []}
if not EXCLUDE_TYPE_RESEARCH["is_complex"]:
if not EXCLUDE_TYPE_RESEARCH["is_complex"] and not exclude_categories or "is_complex" not in exclude_categories:
res_list["Комплексные услуги"] = {"Общие": []}
return res_list

Expand Down Expand Up @@ -1003,33 +1029,30 @@ def get_services_in_complex(complex_id: int, filtered_hide=False):
return result

@staticmethod
def check_complex(master_complex_id, slave_complex_services):
master_complex_services = ComplexService.objects.filter(main_research_id=master_complex_id).values_list("slave_research_id", flat=True)
master_complex_ids = set(master_complex_services)
for service in slave_complex_services:
if service.slave_research_id in master_complex_ids:
return {"ok": False, "message": "В добавляемом комплексе пересекаются услуги"}
if service.slave_research.is_complex:
return {"ok": False, "message": "Нельзя добавить комплекс с комплексами"}
return {"ok": True, "message": ""}
def add_services(complex_id: int, service_ids: list):
if not service_ids:
return {"ok": False, "message": "Услуги не переданы"}
errors_reason = []
errors_ids = set()
for service_id in service_ids:
result_add = ComplexService.add_service(complex_id, service_id)
if not result_add["ok"]:
errors_reason.append({"service_id": service_id, "reason": result_add["message"]})
errors_ids.add(service_id)
result = {"ok": True, "message": "", "errors_reason": errors_reason, "errors_ids": errors_ids}
return result

@staticmethod
def add_service(complex_id: int, service_id: int, ):
if not complex_id or not service_id:
return {"ok": False, "message": "Комплекс или услуга не переданы"}
if complex_id == service_id:
return {"ok": False, "message": "Нельзя добавить в комплекс этот же комплекс"}
def add_service(complex_id: int, service_id: int):
current_service: ComplexService = ComplexService.objects.filter(main_research_id=complex_id, slave_research_id=service_id).first()
if current_service:
return {"ok": False, "message": "Услуга уже есть"}
slave_complex_service = ComplexService.objects.filter(main_research_id=service_id).select_related('slave_research')
if slave_complex_service.exists():
check_result = ComplexService.check_complex(complex_id, slave_complex_service)
if not check_result["ok"]:
return check_result
service_is_complex = Researches.objects.filter(pk=service_id).first().is_complex
if service_is_complex:
return {"ok": False, "message": "Услуга является комплексом"}
complex_service = ComplexService(main_research_id=complex_id, slave_research_id=service_id)
complex_service.save()
return {"ok": True, "message": "", "result": complex_service.main_research_id}
return {"ok": True, "message": ""}

@staticmethod
def change_hidden_complex(complex_id: int):
Expand Down
49 changes: 34 additions & 15 deletions l2-frontend/src/construct/ConstructComplexServices.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class="form-control nbr left-radius complex-title"
:class="complexIsHidden ? 'hide-background hide-border' : ''"
:disabled="complexIsHidden"
placeholder="Введите наименование комплексной услуги"
>
<div class="flex">
<button
Expand Down Expand Up @@ -47,6 +48,7 @@
<input
v-model="search"
class="form-control left-radius right-radius"
placeholder="Поиск"
>
</div>
<div
Expand All @@ -62,6 +64,14 @@
width="35"
>
</colgroup>
<thead class="sticky">
<tr class="border-no-top">
<th class="text-center">
<strong>Наименование исследования</strong>
</th>
<th />
</tr>
</thead>
<tr
v-for="service in filteredService"
:key="service.id"
Expand Down Expand Up @@ -104,18 +114,19 @@
>
<div class="flex">
<Treeselect
v-model="selectedService"
v-model="selectedServices"
:options="services"
:disable-branch-nodes="true"
class="add-treeselect"
placeholder="Выберите услугу..."
:multiple="true"
placeholder="Выберите исследование..."
/>
<div class="flex">
<button
v-tippy
class="btn btn-blue-nb nbr save-button right-radius"
title="Добавить услугу"
:disabled="!selectedService"
:disabled="selectedServices.length < 1"
@click="addService"
>
Добавить
Expand Down Expand Up @@ -161,10 +172,10 @@ onMounted(() => {
});
const services = ref([]);
const selectedService = ref(null);
const selectedServices = ref([]);
const getServices = async () => {
await store.dispatch(actions.INC_LOADING);
const { data } = await api('get-research-list');
const { data } = await api('get-research-list', { exclude_categories: ['is_complex'] });
await store.dispatch(actions.DEC_LOADING);
services.value = data;
};
Expand Down Expand Up @@ -263,25 +274,27 @@ watch(selectedComplex, () => {
});
const addService = async () => {
const serviceExists = servicesInComplex.value.find((service) => service.id === selectedService.value);
if (!serviceExists && selectedService.value !== selectedComplex.value.id) {
const serviceExists = servicesInComplex.value.find((service) => selectedServices.value.includes(service.id));
if (!serviceExists) {
await store.dispatch(actions.INC_LOADING);
const { ok, message } = await api('construct/complex/add-service', {
const { ok, message, errors } = await api('construct/complex/add-services', {
complexId: selectedComplex.value.id,
serviceId: selectedService.value,
serviceIds: selectedServices.value,
});
await store.dispatch(actions.DEC_LOADING);
if (ok) {
await getServicesInComplex();
selectedService.value = null;
root.$emit('msg', 'ok', 'Услуга добавлена');
selectedServices.value = [];
if (errors.length > 0) {
root.$emit('msg', 'warning', 'Не все услуги добавлены');
} else {
root.$emit('msg', 'ok', 'Услуги добавлены');
}
} else {
root.$emit('msg', 'error', message);
}
} else if (serviceExists) {
root.$emit('msg', 'error', 'Услуга уже добавлена');
} else if (selectedService.value === selectedComplex.value.id) {
root.$emit('msg', 'error', 'Нельзя добавить в комплекс этот же комплекс');
root.$emit('msg', 'error', 'Услуги пересекаются');
}
};
Expand Down Expand Up @@ -312,7 +325,7 @@ onMounted(() => {
margin-bottom: 20px;
}
.scroll {
min-height: 112px;
min-height: 108px;
max-height: calc(100vh - 400px);
overflow-y: auto;
}
Expand Down Expand Up @@ -370,4 +383,10 @@ onMounted(() => {
width: 85px;
margin: 20px auto;
}
.sticky {
position: sticky;
top: 0;
z-index: 1;
background-color: white;
}
</style>
2 changes: 1 addition & 1 deletion slog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Log(models.Model):
(210000, 'Комплексные услуги: создание комплекса'),
(210001, 'Комплексные услуги: обновление комплекса'),
(210002, 'Комплексные услуги: изменение видимости комплекса'),
(210003, 'Комплексные услуги: добавление услуги в комплекс'),
(210003, 'Комплексные услуги: добавление услуг в комплекс'),
(210004, 'Комплексные услуги: изменение видимости услуги в комплексе'),
(220000, 'Конструктор лабораторных исследований: изменение порядка услуги'),
(220001, 'Конструктор лабораторных исследований: изменение видимости услуги'),
Expand Down

0 comments on commit 97a9cd2

Please sign in to comment.