Skip to content

Commit

Permalink
Merge pull request #3367 from mikhailprivalov/construct-laboratory-v2
Browse files Browse the repository at this point in the history
Конструктор лаборатории v2
  • Loading branch information
urchinpro authored Jan 11, 2024
2 parents 88c334a + 5e51957 commit 5111726
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 151 deletions.
7 changes: 4 additions & 3 deletions api/construct/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from . import views

urlpatterns = [
path('laboratory/get-departments', views.get_departments),
path('laboratory/get-departments', views.get_lab_departments),
path('laboratory/get-tubes', views.get_tubes),
path('laboratory/update-order-research', views.update_order_research),
path('laboratory/update-order-fraction', views.update_order_fraction),
path('laboratory/change-visibility-research', views.change_visibility_research),
path('laboratory/get-research', views.get_research),
path('laboratory/update-research', views.update_research),
path('laboratory/get-research', views.get_lab_research),
path('laboratory/update-research', views.update_lab_research),
path('laboratory/get-ref-books', views.get_lab_ref_books),
]
18 changes: 14 additions & 4 deletions api/construct/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
import simplejson as json
from directory.models import Researches, Fractions
from directory.models import Researches, Fractions, Unit, LaboratoryMaterial, SubGroup
from laboratory.decorators import group_required
from podrazdeleniya.models import Podrazdeleniya
from utils.response import status_response


@login_required
@group_required("Конструктор: Лабораторные исследования")
def get_departments(request):
def get_lab_departments(request):
result = Podrazdeleniya.get_podrazdeleniya(Podrazdeleniya.LABORATORY)
return JsonResponse({"result": result})

Expand Down Expand Up @@ -48,15 +48,25 @@ def change_visibility_research(request):

@login_required
@group_required("Конструктор: Лабораторные исследования")
def get_research(request):
def get_lab_research(request):
request_data = json.loads(request.body)
result = Researches.get_research(request_data["researchPk"])
return JsonResponse({"result": result})


@login_required
@group_required("Конструктор: Лабораторные исследования")
def update_research(request):
def update_lab_research(request):
request_data = json.loads(request.body)
result = Researches.update_lab_research(request_data["research"])
return status_response(result)


@login_required
@group_required("Конструктор: Лабораторные исследования")
def get_lab_ref_books(request):
units = Unit.get_units()
materials = LaboratoryMaterial.get_materials()
subgroups = SubGroup.get_groups()
result = {"units": units, "materials": materials, "subgroups": subgroups}
return JsonResponse({"result": result})
55 changes: 42 additions & 13 deletions directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ class LaboratoryMaterial(models.Model):
def __str__(self):
return "%s" % self.title

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

class Meta:
verbose_name = 'Биоматериал'
verbose_name_plural = 'Биоматериалы'
Expand All @@ -151,6 +156,11 @@ class SubGroup(models.Model):
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 = 'Подгруппы услуг'
Expand Down Expand Up @@ -526,7 +536,7 @@ def as_json(research):

@staticmethod
def get_tube_data(research_pk: int, need_fractions: bool = False) -> dict:
fractions = Fractions.objects.filter(research_id=research_pk).select_related('relation__tube').order_by('sort_weight')
fractions = Fractions.objects.filter(research_id=research_pk).select_related('relation__tube', 'unit', 'variants').order_by('sort_weight')
research_tubes = {}
for fraction in fractions:
if research_tubes.get(fraction.relation_id) and need_fractions:
Expand Down Expand Up @@ -603,8 +613,12 @@ def get_research(research_pk: int):
"shortTitle": research.short_title,
"code": research.code,
"internalCode": research.internal_code,
"ecpCode": research.ecp_id,
"ecpId": research.ecp_id,
"preparation": research.preparation,
"departmentId": research.podrazdeleniye_id,
"laboratoryMaterialId": research.laboratory_material_id,
"subGroupId": research.sub_group_id,
"laboratoryDuration": research.laboratory_duration,
"tubes": [value for _, value in research_tubes.items()],
}
return result
Expand All @@ -616,16 +630,21 @@ def update_lab_research(research_data):
for tube in research_data["tubes"]:
for fraction in tube["fractions"]:
current_fractions = fractions.get(pk=fraction["pk"])
current_fractions.title = fraction["title"]
current_fractions.ecp_id = fraction["ecpCode"]
current_fractions.title = fraction["title"].strip()
current_fractions.ecp_id = fraction["ecpId"].strip()
current_fractions.fsli = fraction["fsli"]
current_fractions.unit_id = fraction["unitId"]
current_fractions.save()
research.title = research_data["title"]
research.short_title = research_data["shortTitle"]
research.code = research_data["code"]
research.ecp_id = research_data["ecpCode"]
research.internal_code = research_data["internalCode"]
research.title = research_data["title"].strip()
research.short_title = research_data["shortTitle"].strip()
research.code = research_data["code"].strip()
research.ecp_id = research_data["ecpId"].strip()
research.internal_code = research_data["internalCode"].strip()
research.preparation = research_data["preparation"]
research.podrazdeleniye_id = research_data["departmentId"]
research.laboratory_material_id = research_data["laboratoryMaterialId"]
research.sub_group_id = research_data["subGroupId"]
research.laboratory_duration = research_data["laboratoryDuration"]
research.save()
return True

Expand Down Expand Up @@ -998,6 +1017,17 @@ class Unit(models.Model):
hide = models.BooleanField(default=False, blank=True, verbose_name='Скрытие')
ucum = models.CharField(max_length=55, default='', blank=True, verbose_name='UCUM')

@staticmethod
def get_units():
result = [
{
"id": unit.pk,
"label": unit.title,
}
for unit in Unit.objects.filter(hide=False)
]
return result

def __str__(self) -> str:
return f"{self.code}{self.short_title}{self.title}"

Expand Down Expand Up @@ -1062,11 +1092,10 @@ def as_json(fraction) -> dict:
result = {
"pk": fraction.pk,
"title": fraction.title,
"unit": fraction.unit.title if fraction.unit else "",
"variants": fraction.variants.get_variants() if fraction.variants else "",
"order": fraction.sort_weight,
"ecpCode": fraction.ecp_id,
"unitId": fraction.unit_id,
"ecpId": fraction.ecp_id,
"fsli": fraction.fsli,
"order": fraction.sort_weight,
}
return result

Expand Down
38 changes: 28 additions & 10 deletions l2-frontend/src/construct/ConstructLaboratory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div
class="sidebar-content"
>
<TubeGroup
<ResearchesGroup
v-for="(tube, idx) in filteredResearchTubes"
:key="idx"
:tube="tube"
Expand All @@ -42,6 +42,10 @@
<ResearchDetail
v-if="currentResearchPk"
:research-pk="currentResearchPk"
:departments="departments.slice(1)"
:units="units"
:materials="materials"
:sub-groups="subGroups"
@updateResearch="getTubes"
/>
</div>
Expand All @@ -55,27 +59,24 @@ import {
import Treeselect from '@riophae/vue-treeselect';
import '@riophae/vue-treeselect/dist/vue-treeselect.css';
import TubeGroup from '@/construct/TubeGroup.vue';
import { useStore } from '@/store';
import * as actions from '@/store/action-types';
import api from '@/api';
import ResearchDetail from '@/construct/ResearchDetail.vue';
import ResearchesGroup from '@/construct/ResearchesGroup.vue';
const store = useStore();
const root = getCurrentInstance().proxy.$root;
const department = ref(null);
const departments = ref([
{ id: 1, label: 'отделение1' },
]);
const departments = ref([]);
const getDepartments = async () => {
await store.dispatch(actions.INC_LOADING);
const { result } = await api('construct/laboratory/get-departments');
await store.dispatch(actions.DEC_LOADING);
result.push({
id: -1, label: 'Все',
});
result.unshift({ id: -1, label: 'Все' });
departments.value = result;
};
Expand All @@ -92,7 +93,7 @@ const getTubes = async () => {
const currentResearchPk = ref(null);
const edit = async ({ researchPk }) => {
const edit = ({ researchPk }) => {
currentResearchPk.value = researchPk;
};
Expand Down Expand Up @@ -141,16 +142,30 @@ const changeVisibility = async ({ researchPk }) => {
}
};
const units = ref([]);
const materials = ref([]);
const subGroups = ref([]);
const getRefbooks = async () => {
await store.dispatch(actions.INC_LOADING);
const { result } = await api('construct/laboratory/get-ref-books');
await store.dispatch(actions.DEC_LOADING);
units.value = result.units;
materials.value = result.materials;
subGroups.value = result.subGroups;
};
onMounted(() => {
getDepartments();
getRefbooks();
});
</script>

<style scoped lang="scss">
.two-col {
display: grid;
grid-template-columns: 450px auto;
grid-template-columns: minmax(200px, 450px) minmax(150px, auto);
margin-bottom: 5px;
height: calc(100vh - 36px);
}
Expand Down Expand Up @@ -183,4 +198,7 @@ onMounted(() => {
margin: 0;
flex: 0 0 34px;
}
.content-construct {
overflow-y: auto;
}
</style>
Loading

0 comments on commit 5111726

Please sign in to comment.