Skip to content

Commit

Permalink
Merge pull request #4303 from mikhailprivalov/template-field-by-depar…
Browse files Browse the repository at this point in the history
…tment

Конструктор описательных услуг - шаблоны полей по подразделению
  • Loading branch information
urchinpro authored Sep 25, 2024
2 parents dba843a + af06cf9 commit f7e88b6
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 95 deletions.
2 changes: 1 addition & 1 deletion api/directions/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
""",
Expand Down
41 changes: 34 additions & 7 deletions api/researches/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ResearchGroup,
ReleationsFT,
ParaclinicTemplateNameDepartment,
ParaclinicFieldTemplateDepartment,
)
from directory.utils import get_researches_details
from laboratory.decorators import group_required
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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"]
Expand All @@ -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", ''),
Expand All @@ -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"]
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)


Expand Down Expand Up @@ -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 = [
Expand Down
10 changes: 8 additions & 2 deletions directory/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from api.directions.sql_func import get_template_field_by_department
from directory.models import (
Researches as DResearches,
ParaclinicInputGroups,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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(
{
Expand All @@ -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,
Expand Down
56 changes: 20 additions & 36 deletions l2-frontend/src/construct/FastTemplatesEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
v-model="department"
class="treeselect-nbr treeselect-wide"
:options="departments"
:clearable="false"
:clearable="showAllDepartments"
placeholder="Выберите подразделение"
/>
</div>
Expand Down Expand Up @@ -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',
Expand All @@ -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 {
Expand All @@ -227,10 +238,7 @@ export default {
selected_template: -2,
template_data: {},
department: null,
departments: [],
departmentsForTemplate: [],
showAllDepartments: false,
userDepartmentId: null,
};
},
watch: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
},
},
};
</script>
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit f7e88b6

Please sign in to comment.