Skip to content

Commit

Permalink
Merge pull request #4053 from mikhailprivalov/allowed-forms-files-for…
Browse files Browse the repository at this point in the history
…-org

Прикрепление PDF к результату
  • Loading branch information
urchinpro authored Jul 3, 2024
2 parents 8422669 + cb43183 commit 9a7cbea
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 12 deletions.
21 changes: 21 additions & 0 deletions api/laboratory/forms100.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from directions.models import Issledovaniya, IssledovaniyaFiles


def form_01(request_data):
file = request_data.get("file")
user = request_data.get('user')
issledovanie_id = request_data.get("entity_id")
issledovanie: Issledovaniya = Issledovaniya.objects.filter(pk=issledovanie_id).select_related('research').first()
if issledovanie:
iss_files = IssledovaniyaFiles.objects.filter(issledovaniye_id=issledovanie.pk)
if file and iss_files.count() >= 5:
return {"ok": False, "result": [], "message": "Вы добавили слишком много файлов в одну заявку"}

if file and file.size > 5242880:
return {"ok": False, "result": [], "message": "Файл слишком большой"}

iss = IssledovaniyaFiles(issledovaniye_id=issledovanie.pk, uploaded_file=file, who_add_files=user.doctorprofile)
iss.save()
else:
return {"ok": False, "result": [], "message": "Нет такого исследования"}
return {"ok": True, "result": [], "message": ""}
1 change: 1 addition & 0 deletions api/laboratory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def form(request):
"allow_reset_confirm": iss.allow_reset_confirm(request.user),
"research": {
"title": research.title,
"enabled_add_files": research.enabled_add_files,
"can_comment": research.can_lab_result_comment,
"no_units_and_ref": research.no_units_and_ref,
"co_executor_mode": research.co_executor_mode or 0,
Expand Down
1 change: 1 addition & 0 deletions api/parse_file/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ def get_parts_fio(fio_data):
return family_data, name_data, patronymic_data


@login_required()
def upload_file(request):
# todo - Логирование загрузки файлов
try:
Expand Down
1 change: 1 addition & 0 deletions appconf/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def l2_modules() -> dict:
"code_price",
"all_service",
"show_barcode_button_in_direction_history",
"allowed_forms_file",
]
},
"consults_module": SettingManager.get("consults_module", default='false', default_type='b'),
Expand Down
14 changes: 12 additions & 2 deletions l2-frontend/src/components/UploadFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
<script setup lang="ts">
// todo - slot на вывод результата, для удобного вывода каждому)
// todo - дефолтный вывод результата - таблица, строчка
// todo - уведомление о успешной загрузке файла
import {
computed,
getCurrentInstance, onMounted, PropType, ref, watch,
} from 'vue';
import Treeselect from '@riophae/vue-treeselect';
Expand All @@ -94,6 +94,9 @@ import typesAndForms, { formsFile, typesFile } from './types-and-forms-file';
const { getTypes, getForms } = typesAndForms();
const store = useStore();
const allowedFormsForOrganization = computed(() => store.getters.modules.l2_allowed_forms_file.trim());
const root = getCurrentInstance().proxy.$root;
const props = defineProps({
typesFile: {
Expand Down Expand Up @@ -141,9 +144,16 @@ const selectedForm = ref(null);
const changeType = () => {
fileFilter.value = `.${selectedType.value}`;
currentFileForms.value = getForms(String(selectedType.value), props.formsFile);
currentFileForms.value = getForms(
String(selectedType.value),
props.formsFile,
props.uploadResult,
allowedFormsForOrganization.value.split(', '),
);
if (currentFileForms.value.length > 0) {
selectedForm.value = currentFileForms.value[0].id;
} else {
selectedForm.value = null;
}
};
Expand Down
40 changes: 32 additions & 8 deletions l2-frontend/src/components/types-and-forms-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface formsFile {
export default function typesAndForms() {
const fileTypes = ref({
XLSX: { id: 'XLSX', label: 'XLSX' },
PDF: { id: 'PDF', label: 'PDF' },
});
// todo - сделать соотношение - расширение файла - и все виды accept фильтров {xlsx: '.xlx, .xlsx, ws-excel'}
const getTypes = (types: string[]): typesFile[] => {
Expand All @@ -27,24 +28,47 @@ export default function typesAndForms() {
return result;
};

const isResultForm = ref([
'api.laboratory.forms100.form_01',
]);

/* (101.01) - 101 номер файла, 01 - номер функции в файле для обработки загруженного файла (см. parseFile) */
const fileForms = ref({
XLSX: {
'api.contracts.forms100.form_01': { id: 'api.contracts.forms100.form_01', label: 'Загрузка цен по прайсу' },
},
PDF: {
'api.laboratory.forms100.form_01': { id: 'api.laboratory.forms100.form_01', label: 'Загрузка PDF результата из QMS' },
},
});
// todo - режим UploadResult - получать по расширению файла - только функции связанные с сохранением результата (анализаторы)
// todo - UploadResult + forms - получать только выбранные isResult функции
const getForms = (type: string, forms: string[] = []): formsFile[] => {
let result: formsFile[] = [];
if (forms && forms.length > 0) {
// todo - UploadResult + forms - получать только выбранные isResult функции (протестировать)
const getForms = (type: string, forms: string[] = null, onlyResult = false, allowedForms: string[] = null): formsFile[] => {
/* onlyResult - Выдаст только формы находящиеся в isResultForm, allowedForms - выдаст только те функции которые разрешены */
const result: formsFile[] = [];
if (!allowedForms) {
return result;
}
if (forms && forms.length > 0) { // Если переданы формы
for (const form of forms) {
if (fileForms.value[type][form]) {
if (!onlyResult && fileForms.value[type][form] && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
} else if (onlyResult && isResultForm.value.includes(form) && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
}
}
} else if (!forms && onlyResult) { // если нет форм, но, есть "только результат"
for (const form of isResultForm.value) {
if (fileForms.value[type][form] && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
}
}
} else { // Если нет форм и "только результат" - выдать всё разрешенное
const tmpResult = Object.values(fileForms.value[type]);
for (const form of tmpResult) {
if (allowedForms.includes(String(form))) {
result.push(fileForms.value[type][form]);
}
}
} else {
result = Object.values(fileForms.value[type]);
}
return result;
};
Expand Down
11 changes: 9 additions & 2 deletions l2-frontend/src/modals/UploadFileModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<template>
<div>
<component
:is="tag"
>
<slot>
<a
class="pointer"
Expand Down Expand Up @@ -44,7 +46,7 @@
</div>
</div>
</Modal>
</div>
</component>
</template>

<script setup lang="ts">
Expand All @@ -60,6 +62,11 @@ const props = defineProps({
type: String,
required: false,
},
tag: {
type: String,
default: 'div',
required: false,
},
typesFile: {
type: Array as PropType<string[]>,
required: false,
Expand Down
9 changes: 9 additions & 0 deletions l2-frontend/src/pages/LaboratoryResults/ResultsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@
<thead>
<tr>
<td colspan="5">
<UploadFileModal
v-if="research.enabled_add_files"
title="Прикрепить результат"
:types-file="['PDF']"
:forms-file="['api.laboratory.forms100.form_01']"
:entity-id="pk"
/>
<strong>
{{ research.title }}
</strong>
Expand Down Expand Up @@ -320,10 +327,12 @@ import Ref from '@/pages/LaboratoryResults/Ref.vue';
import TextInputField from '@/pages/LaboratoryResults/TextInputField.vue';
import BloodTypeField from '@/pages/LaboratoryResults/BloodTypeField.vue';
import RefSettings from '@/pages/LaboratoryResults/RefSettings.vue';
import UploadFileModal from '@/modals/UploadFileModal.vue';
export default {
name: 'ResultsForm',
components: {
UploadFileModal,
RefSettings,
TextInputField,
BloodTypeField,
Expand Down
6 changes: 6 additions & 0 deletions l2-frontend/src/ui-cards/LaboratoryHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import LaboratorySelector from '@/ui-cards/LaboratorySelector.vue';
import ExecutionList from '@/ui-cards/ExecutionList.vue';
import LaboratoryJournal from '@/ui-cards/LaboratoryJournal.vue';
import LaboratoryPrintResults from '@/ui-cards/LaboratoryPrintResults.vue';
import UploadFileModal from '@/modals/UploadFileModal.vue';

Check warning on line 48 in l2-frontend/src/ui-cards/LaboratoryHeader.vue

View workflow job for this annotation

GitHub Actions / webpack_build_prod

'UploadFileModal' is defined but never used

Check warning on line 48 in l2-frontend/src/ui-cards/LaboratoryHeader.vue

View workflow job for this annotation

GitHub Actions / webpack_build_prod

'UploadFileModal' is defined but never used
export default {
name: 'LaboratoryHeader',
Expand Down Expand Up @@ -80,4 +81,9 @@ export default {
background: #049372 !important;
border: none !important;
}
.nav-upload-file {
padding: 8px 15px;
}
</style>

0 comments on commit 9a7cbea

Please sign in to comment.