Skip to content

Commit

Permalink
Merge pull request #3375 from mikhailprivalov/construct-laboratory-v3
Browse files Browse the repository at this point in the history
Конструктор лаборатории v3
  • Loading branch information
urchinpro authored Jan 14, 2024
2 parents 868ab85 + 902bd13 commit 236c20a
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 87 deletions.
2 changes: 2 additions & 0 deletions api/construct/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
21 changes: 19 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, 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
Expand Down Expand Up @@ -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)
105 changes: 85 additions & 20 deletions directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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

Expand Down
17 changes: 15 additions & 2 deletions l2-frontend/src/construct/ConstructLaboratory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@updateOrder="updateOrder"
@changeVisibility="changeVisibility"
@edit="edit"
@add="add"
/>
<div
v-if="filteredResearchTubes.length === 0"
Expand All @@ -42,10 +43,13 @@
<ResearchDetail
v-if="currentResearchPk"
:research-pk="currentResearchPk"
:new-research="newResearch"
:department-id="department"
:departments="departments.slice(1)"
:units="units"
:materials="materials"
:sub-groups="subGroups"
:variants="variants"
@updateResearch="getTubes"
/>
</div>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -153,6 +165,7 @@ const getRefbooks = async () => {
units.value = result.units;
materials.value = result.materials;
subGroups.value = result.subGroups;
variants.value = result.variants;
};
onMounted(() => {
Expand Down
Loading

0 comments on commit 236c20a

Please sign in to comment.