Skip to content

Commit

Permalink
Merge pull request #3485 from mikhailprivalov/constructSubGroup
Browse files Browse the repository at this point in the history
подгруппы по подразделениям
  • Loading branch information
Wellheor1 authored Feb 7, 2024
2 parents 03021db + be9ec8d commit 102e7da
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 24 deletions.
3 changes: 3 additions & 0 deletions api/construct/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
path('laboratory/get-ref-books', views.get_lab_ref_books),
path('laboratory/get-research-additional-data', views.get_lab_research_additional_data),
path('laboratory/get-comments-variants', views.get_comments_variants),
path('department/get-subgroups', views.get_subgroups_department),
path('department/save-subgroups', views.save_subgroups_department),
path('get-subgroups-all', views.get_subgroups_all),
]
39 changes: 37 additions & 2 deletions api/construct/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
import simplejson as json
from directory.models import Researches, Unit, LaboratoryMaterial, SubGroup, ResultVariants, MaterialVariants
from directory.models import Researches, Unit, LaboratoryMaterial, ResultVariants, MaterialVariants, SubGroupPadrazdeleniye, SubGroupDirectory
from laboratory.decorators import group_required
from podrazdeleniya.models import Podrazdeleniya
from researches.models import Tubes
Expand Down Expand Up @@ -58,9 +58,10 @@ def update_lab_research(request):
@login_required
@group_required("Конструктор: Лабораторные исследования")
def get_lab_ref_books(request):
request_data = json.loads(request.body)
units = Unit.get_units()
materials = LaboratoryMaterial.get_materials()
subgroups = SubGroup.get_groups()
subgroups = SubGroupPadrazdeleniye.get_subgroup_podrazdeleniye(request_data["departmentId"])
variants = ResultVariants.get_all()
tubes = Tubes.get_all()
result = {"units": units, "materials": materials, "subGroups": subgroups, "variants": variants, "tubes": tubes}
Expand All @@ -80,3 +81,37 @@ def get_lab_research_additional_data(request):
request_data = json.loads(request.body)
result = Researches.get_lab_additional_data(request_data["researchPk"])
return JsonResponse({"result": result})


@login_required
def get_subgroups_department(request):
request_data = json.loads(request.body)
pk = request_data['department_pk']
podrazdeleniye = Podrazdeleniya.objects.get(pk=pk)
rows = SubGroupPadrazdeleniye.get_subgroup_podrazdeleniye(podrazdeleniye)
return JsonResponse(rows, safe=False)


@login_required
def save_subgroups_department(request):
request_data = json.loads(request.body)
tb_data = request_data.get('tb_data', '')
department_pk = int(request_data.get('department_pk', -1))
if len(tb_data) < 1:
return JsonResponse({'message': 'Ошибка в количестве'})
result = SubGroupPadrazdeleniye.save_subgroups_department(department_pk, tb_data)
if result:
return JsonResponse({'ok': True, 'message': 'Сохранено'})
return JsonResponse({'ok': False, 'message': 'ошибка'})


@login_required
def get_subgroups_all(request):
rows = [
{
"id": subgroup.pk,
"label": f"{subgroup.title}",
}
for subgroup in SubGroupDirectory.objects.all().order_by("title")
]
return JsonResponse(rows, safe=False)
3 changes: 2 additions & 1 deletion directory/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,5 @@ class SetComplexService(admin.ModelAdmin):
admin.site.register(models.AuxService, SetAuxService)
admin.site.register(models.ComplexService, SetComplexService)
admin.site.register(models.LaboratoryMaterial)
admin.site.register(models.SubGroup)
admin.site.register(models.SubGroupDirectory)
admin.site.register(models.SubGroupPadrazdeleniye)
38 changes: 31 additions & 7 deletions directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,46 @@ class Meta:
verbose_name_plural = 'Биоматериалы'


class SubGroup(models.Model):
class SubGroupDirectory(models.Model):
title = models.CharField(max_length=64, help_text="Подгруппа услуги")

def __str__(self):
return "%s" % self.title

@staticmethod
def get_groups():
result = [{"id": group.pk, "label": group.title} for group in SubGroup.objects.all()]
return result

class Meta:
verbose_name = 'Погруппа услуги'
verbose_name_plural = 'Подгруппы услуг'


class SubGroupPadrazdeleniye(models.Model):
subgroup = models.ForeignKey(SubGroupDirectory, blank=True, default=None, null=True, help_text='Подгруппа', on_delete=models.CASCADE)
podrazdeleniye = models.ForeignKey(Podrazdeleniya, help_text="Лаборатория", db_index=True, null=True, blank=True, default=None, on_delete=models.CASCADE)

@staticmethod
def get_subgroup_podrazdeleniye(podrazdeleniye):
subgroups = SubGroupPadrazdeleniye.objects.filter(podrazdeleniye=podrazdeleniye)
return [{"subgroupId": p.subgroup.pk, "id": p.subgroup.pk, "label": p.subgroup.title} for p in subgroups]

@staticmethod
def save_subgroups_department(department_pk, tb_data):
podrazdeleniye = Podrazdeleniya.objects.filter(pk=department_pk).first()
SubGroupPadrazdeleniye.objects.filter(podrazdeleniye=podrazdeleniye).delete()
for t_b in tb_data:
subgroup = SubGroupDirectory.objects.filter(pk=t_b['subgroupId']).first()
if subgroup:
if not SubGroupPadrazdeleniye.objects.filter(podrazdeleniye=podrazdeleniye, subgroup=subgroup).exists():
SubGroupPadrazdeleniye(podrazdeleniye=podrazdeleniye, subgroup=subgroup).save()

return True

def __str__(self):
return f"{self.subgroup.title} - {self.podrazdeleniye.title}"

class Meta:
verbose_name = 'Свзяь погруппы и подздаления'
verbose_name_plural = 'Связи погрупп и подздалений'


class Researches(models.Model):
"""
Вид исследования
Expand Down Expand Up @@ -340,7 +364,7 @@ class Researches(models.Model):
n3_id_med_document_type = models.SmallIntegerField(default=0, blank=True, help_text="N3 id_med_document_type")
ecp_id = models.CharField(max_length=16, default='', blank=True, verbose_name='Код услуги в ЕЦП')
laboratory_material = models.ForeignKey(LaboratoryMaterial, blank=True, default=None, null=True, help_text='Биоматериал', on_delete=models.SET_NULL)
sub_group = models.ForeignKey(SubGroup, blank=True, default=None, null=True, help_text='Подгруппа', on_delete=models.SET_NULL)
sub_group = models.ForeignKey(SubGroupDirectory, blank=True, default=None, null=True, help_text='Подгруппа', on_delete=models.SET_NULL)
laboratory_duration = models.CharField(max_length=3, default='', blank=True, verbose_name='Срок выполнения')
is_need_send_egisz = models.BooleanField(blank=True, default=False, help_text="Требуется отправка документав ЕГИСЗ")

Expand Down
17 changes: 9 additions & 8 deletions l2-frontend/src/construct/ConstructLaboratory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ const add = (newResearchData: object) => {
};
};
watch([department], () => {
getTubes();
currentResearch.value = {
pk: null, order: null, departmentId: department.value, tubes: null,
};
});
const filteredResearchTubes = computed(() => researchTubes.value.map(tubes => {
const searchTerm = search.value.toLowerCase();
const result = tubes.researches.filter(research => {
Expand Down Expand Up @@ -181,11 +174,19 @@ const refBooks = ref<refBook>({
const getRefbooks = async () => {
await store.dispatch(actions.INC_LOADING);
const { result } = await api('construct/laboratory/get-ref-books');
const { result } = await api('construct/laboratory/get-ref-books', { departmentId: department.value });
await store.dispatch(actions.DEC_LOADING);
refBooks.value = result;
};
watch([department], () => {
getTubes();
currentResearch.value = {
pk: null, order: null, departmentId: department.value, tubes: null,
};
getRefbooks();
});
const editRelationId = ref(null);
const editRelation = ({ relationId }) => {
editRelationId.value = relationId;
Expand Down
45 changes: 39 additions & 6 deletions l2-frontend/src/forms/DepartmentEditRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,35 @@
/>
</td>
<td>
<i
v-if="department.type === '7'"
class="fa fa-bed"
style="margin-top: 10px; margin-left: 7px"
/>
<div>
<a
href="#"
class="a-under"
style="padding-right: 10px"
@click.prevent="editDepartment(department.pk)"
>
<i
v-if="department.type === '7'"
v-tippy
class="fa fa-bed"
style="margin-top: 10px; margin-left: 7px"
title="Настройки подразделения"
/>
<i
v-if="department.type === '2'"
v-tippy
class="fa-solid fa-vials"
style="margin-top: 10px; margin-left: 7px"
title="Настройки подразделения"
/>
</a>
</div>
</td>
<SubGroupsDepartment
v-if="subgroups_department"
:department_pk="department.pk"
:readonly="false"
/>
</tr>
</template>

Expand All @@ -45,10 +68,11 @@ import _ from 'lodash';
import departmentsDirectory from '@/api/departments-directory';
import * as actions from '@/store/action-types';
import SubGroupsDepartment from '@/modals/SubGroupDepartment.vue';
export default {
name: 'DepartmentEditRow',
components: { Treeselect },
components: { Treeselect, SubGroupsDepartment },
props: {
can_edit: {
type: Boolean,
Expand All @@ -67,6 +91,7 @@ export default {
return {
updated: false,
timer: null,
subgroups_department: false,
};
},
computed: {
Expand All @@ -91,6 +116,11 @@ export default {
this.save_clear_deb();
},
},
created() {
this.$root.$on('hide_subgroups_department', () => {
this.subgroups_department = false;
});
},
beforeMount() {
clearTimeout(this.timer);
},
Expand Down Expand Up @@ -128,6 +158,9 @@ export default {
await this.$store.dispatch(actions.GET_ALL_DEPARTMENTS);
},
editDepartment(iDdepartment) {

Check warning on line 161 in l2-frontend/src/forms/DepartmentEditRow.vue

View workflow job for this annotation

GitHub Actions / webpack_build_prod

'iDdepartment' is defined but never used

Check warning on line 161 in l2-frontend/src/forms/DepartmentEditRow.vue

View workflow job for this annotation

GitHub Actions / webpack_build_prod

'iDdepartment' is defined but never used
this.subgroups_department = true;
},
},
};
</script>
Loading

0 comments on commit 102e7da

Please sign in to comment.