diff --git a/api/construct/urls.py b/api/construct/urls.py index e10c83a369..feb0680fda 100644 --- a/api/construct/urls.py +++ b/api/construct/urls.py @@ -11,4 +11,6 @@ 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), + path('laboratory/get-fraction', views.get_fraction), + path('laboratory/update-fraction', views.update_fraction), ] diff --git a/api/construct/views.py b/api/construct/views.py index edf2365d0f..82d831ce26 100644 --- a/api/construct/views.py +++ b/api/construct/views.py @@ -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, Fractions, Unit, LaboratoryMaterial, SubGroup +from directory.models import Researches, Fractions, Unit, LaboratoryMaterial, SubGroup, ResultVariants from laboratory.decorators import group_required from podrazdeleniya.models import Podrazdeleniya from utils.response import status_response @@ -68,5 +68,22 @@ 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} + variants = ResultVariants.get_all() + result = {"units": units, "materials": materials, "subGroups": subgroups, "variants": variants} return JsonResponse({"result": result}) + + +@login_required +@group_required("Конструктор: Лабораторные исследования") +def get_fraction(request): + request_data = json.loads(request.body) + result = Fractions.get_fraction(request_data["fractionPk"]) + return JsonResponse({"result": result}) + + +@login_required +@group_required("Конструктор: Лабораторные исследования") +def update_fraction(request): + request_data = json.loads(request.body) + result = Fractions.update_fraction(request_data["fraction"]) + return status_response(result) diff --git a/directory/models.py b/directory/models.py index 1ed6b8a7c8..e99b115d07 100644 --- a/directory/models.py +++ b/directory/models.py @@ -536,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', 'unit', 'variants').order_by('sort_weight') + fractions = Fractions.objects.filter(research_id=research_pk).select_related('relation__tube', 'unit', 'variants').order_by('relation_id', 'sort_weight') research_tubes = {} for fraction in fractions: if research_tubes.get(fraction.relation_id) and need_fractions: @@ -625,27 +625,63 @@ def get_research(research_pk: int): @staticmethod def update_lab_research(research_data): - research = Researches.objects.get(pk=research_data["pk"]) - fractions = Fractions.objects.filter(research_id=research.pk) + research_title = research_data["title"].strip() if research_data["title"] else None + research_short_title = research_data["shortTitle"].strip() if research_data["shortTitle"] else '' + research_ecp_id = research_data["ecpId"].strip() if research_data["ecpId"] else '' + research_code = research_data["code"].strip() if research_data["code"] else '' + research_internal_code = research_data["internalCode"].strip() if research_data["internalCode"] else '' + research = Researches.objects.filter(pk=research_data["pk"]).first() + fractions = None + if research and research_title: + research.title = research_title + research.short_title = research_short_title + research.code = research_code + research.ecp_id = research_ecp_id + research.internal_code = research_internal_code + 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() + fractions = Fractions.objects.filter(research_id=research.pk) + elif research_title: + research = Researches( + title=research_title, + short_title=research_short_title, + ecp_id=research_ecp_id, + code=research_code, + internal_code=research_internal_code, + preparation=research_data["preparation"], + podrazdeleniye_id=research_data["departmentId"], + laboratory_material_id=research_data["laboratoryMaterialId"], + sub_group_id=research_data["subGroupId"], + laboratory_duration=research_data["laboratoryDuration"], + sort_weight=research_data["order"], + ) + research.save() + else: + return False for tube in research_data["tubes"]: for fraction in tube["fractions"]: - current_fractions = fractions.get(pk=fraction["pk"]) - 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"].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() + if fractions: + current_fractions = fractions.filter(pk=fraction["pk"]).first() + else: + current_fractions = None + if current_fractions: + 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() + else: + title = fraction["title"].strip() if fraction["title"] else '' + ecp_id = fraction["ecpId"].strip() if fraction["ecpId"] else '' + unit_id = fraction["unitId"] if fraction["unitId"] != -1 else None + new_fraction = Fractions( + research_id=research.pk, title=title, ecp_id=ecp_id, fsli=fraction["fsli"], unit_id=unit_id, relation_id=tube["pk"], sort_weight=fraction["order"] + ) + new_fraction.save() return True @@ -979,6 +1015,11 @@ class ResultVariants(models.Model): def get_variants(self): return self.values.split('|') + @staticmethod + def get_all(): + result = [{"id": variants.pk, "label": variants.values} for variants in ResultVariants.objects.all()] + return result + def __str__(self): return str(self.get_variants()) @@ -1113,6 +1154,30 @@ def update_order(fraction_pk: int, fraction_nearby_pk: int, action: str): fraction_nearby.save() return True + @staticmethod + def get_fraction(fraction_pk: int): + fraction = Fractions.objects.get(pk=fraction_pk) + refM = [{"age": key, "value": value} for key, value in fraction.ref_m.items()] if isinstance(fraction.ref_m, dict) else [] + refF = [{"age": key, "value": value} for key, value in fraction.ref_f.items()] if isinstance(fraction.ref_f, dict) else [] + result = {"pk": fraction.pk, "title": fraction.title, "variantsId": fraction.variants_id, "formula": fraction.formula, "refM": refM, "refF": refF} + return result + + @staticmethod + def update_fraction(fraction_data: dict): + fraction = Fractions.objects.get(pk=fraction_data["pk"]) + fraction.variants_id = fraction_data["variantsId"] + fraction.formula = fraction_data["formula"].strip() + ref_m_dict = {} + ref_f_dict = {} + for ref in fraction_data["refM"]: + ref_m_dict[ref["age"].strip()] = ref["value"].strip() + for ref in fraction_data["refF"]: + ref_f_dict[ref["age"].strip()] = ref["value"].strip() + fraction.ref_m = ref_m_dict + fraction.ref_f = ref_f_dict + fraction.save() + return True + def __str__(self): return self.research.title + " | " + self.title diff --git a/l2-frontend/src/construct/ConstructLaboratory.vue b/l2-frontend/src/construct/ConstructLaboratory.vue index 664d0da3f7..fad6fe1284 100644 --- a/l2-frontend/src/construct/ConstructLaboratory.vue +++ b/l2-frontend/src/construct/ConstructLaboratory.vue @@ -23,6 +23,7 @@ @updateOrder="updateOrder" @changeVisibility="changeVisibility" @edit="edit" + @add="add" />
@@ -84,19 +88,26 @@ const search = ref(''); const researchTubes = ref([]); +const currentResearchPk = ref(null); const getTubes = async () => { await store.dispatch(actions.INC_LOADING); const { result } = await api('construct/laboratory/get-tubes', { department_id: department.value }); await store.dispatch(actions.DEC_LOADING); researchTubes.value = result; + currentResearchPk.value = null; }; -const currentResearchPk = ref(null); - const edit = ({ researchPk }) => { currentResearchPk.value = researchPk; }; +const newResearch = ref({}); + +const add = (newResearchData: object) => { + currentResearchPk.value = -1; + newResearch.value = newResearchData; +}; + watch([department], () => { getTubes(); currentResearchPk.value = null; @@ -145,6 +156,7 @@ const changeVisibility = async ({ researchPk }) => { const units = ref([]); const materials = ref([]); const subGroups = ref([]); +const variants = ref([]); const getRefbooks = async () => { await store.dispatch(actions.INC_LOADING); @@ -153,6 +165,7 @@ const getRefbooks = async () => { units.value = result.units; materials.value = result.materials; subGroups.value = result.subGroups; + variants.value = result.variants; }; onMounted(() => { diff --git a/l2-frontend/src/construct/FractionDetail.vue b/l2-frontend/src/construct/FractionDetail.vue new file mode 100644 index 0000000000..6a85cfd75d --- /dev/null +++ b/l2-frontend/src/construct/FractionDetail.vue @@ -0,0 +1,182 @@ + +