Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Конструктор лаборатории - проверка на уникальность внутреннего кода #4016

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions api/construct/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,29 @@ def get_lab_research(request):
def update_lab_research(request):
request_data = json.loads(request.body)
result = Researches.update_lab_research_and_fractions(request_data["research"], True)
Log.log(
result["old_data"]["pk"],
220002,
request.user.doctorprofile,
{"old_data": result["old_data"], "new_data": result["new_data"]},
)
return JsonResponse(result)
if result["ok"]:
Log.log(
result["old_data"]["pk"],
220002,
request.user.doctorprofile,
{"old_data": result["old_data"], "new_data": result["new_data"]},
)
return JsonResponse({"ok": result["ok"], "message": result["message"]})


@login_required
@group_required("Конструктор: Лабораторные исследования")
def create_lab_research(request):
request_data = json.loads(request.body)
result = Researches.create_lab_research_and_fractions(request_data["research"], True)
Log.log(
result["log_data"]["pk"],
220003,
request.user.doctorprofile,
result["log_data"],
)
return JsonResponse(result)
if result["ok"]:
Log.log(
result["log_data"]["pk"],
220003,
request.user.doctorprofile,
result["log_data"],
)
return JsonResponse({"ok": result["ok"], "pk": result["pk"], "message": result["message"]})


@login_required
Expand Down
16 changes: 14 additions & 2 deletions directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@ def get_tube_data(research_pk: int, need_fractions: bool = False) -> dict:
research_tubes[fraction.relation_id]["fractions"] = [fraction_data]
return research_tubes

@staticmethod
def check_duplicated_internal_code(internal_code):
result = Researches.objects.filter(internal_code=internal_code)
return result.exists()

@staticmethod
def get_laboratory_researches(podrazdelenie_id: int):
if podrazdelenie_id == -1:
Expand Down Expand Up @@ -715,6 +720,10 @@ def update_lab_research_and_fractions(research_data, need_log_data: bool = False
old_log_data = {}
new_log_data = {}
service_data = Researches.normalize_research_data(research_data)
internal_code_is_duplicated = Researches.check_duplicated_internal_code(service_data["internal_code"])
if internal_code_is_duplicated:
return {"ok": False, "message": "Такой внутренний код уже есть"}

service = Researches.objects.filter(pk=service_data["pk"]).first()
if need_log_data:
old_log_data = service.as_json_lab_full()
Expand Down Expand Up @@ -745,8 +754,8 @@ def update_lab_research_and_fractions(research_data, need_log_data: bool = False
if need_log_data:
new_log_data["fractions"][new_fraction.pk] = Fractions.as_json(new_fraction)
if need_log_data:
return {"ok": True, "old_data": old_log_data, "new_data": new_log_data}
return {"ok": True}
return {"ok": True, "old_data": old_log_data, "new_data": new_log_data, "message": ""}
return {"ok": True, "message": ""}

@staticmethod
def create_lab_service(service_data):
Expand All @@ -770,6 +779,9 @@ def create_lab_service(service_data):
def create_lab_research_and_fractions(research_data, need_log_data: bool = False):
log_data = {}
service_data = Researches.normalize_research_data(research_data)
internal_code_is_duplicated = Researches.check_duplicated_internal_code(service_data["internal_code"])
if internal_code_is_duplicated:
return {"ok": False, "pk": None, "message": "Такой внутренний код уже есть"}
new_service = Researches.create_lab_service(service_data)
if need_log_data:
log_data = new_service.as_json_lab_full()
Expand Down
8 changes: 4 additions & 4 deletions l2-frontend/src/construct/ResearchDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,14 @@ const updateResearch = async () => {
const researchValidate = validateResearch();
if (researchValidate.ok) {
await store.dispatch(actions.INC_LOADING);
const { ok } = await api('construct/laboratory/update-research', { research: research.value });
const { ok, message } = await api('construct/laboratory/update-research', { research: research.value });
await store.dispatch(actions.DEC_LOADING);
if (ok) {
root.$emit('msg', 'ok', 'Обновлено');
await getResearch();
emit('updateResearch');
} else {
root.$emit('msg', 'error', 'Ошибка');
root.$emit('msg', 'error', message);
}
} else {
root.$emit('msg', 'error', researchValidate.message);
Expand All @@ -586,15 +586,15 @@ const createResearch = async () => {
const researchValidate = validateResearch();
if (researchValidate.ok) {
await store.dispatch(actions.INC_LOADING);
const { ok, pk } = await api('construct/laboratory/create-research', { research: research.value });
const { ok, pk, message } = await api('construct/laboratory/create-research', { research: research.value });
await store.dispatch(actions.DEC_LOADING);
if (ok) {
research.value.pk = pk;
root.$emit('msg', 'ok', 'Создано');
await getResearch();
emit('updateResearch');
} else {
root.$emit('msg', 'error', 'Ошибка');
root.$emit('msg', 'error', message);
}
} else {
root.$emit('msg', 'error', researchValidate.message);
Expand Down
Loading