Skip to content

Commit

Permalink
Merge pull request #4266 from mikhailprivalov/upload-visits
Browse files Browse the repository at this point in the history
Инструменты - загрузка посещений
  • Loading branch information
urchinpro authored Sep 16, 2024
2 parents 6c0caf8 + be3851b commit 78f106b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 9 deletions.
80 changes: 80 additions & 0 deletions api/parse_file/forms100.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import base64
import json

import requests
from openpyxl.reader.excel import load_workbook

from contracts.models import PriceName, PriceCoast
from directory.models import Researches
from laboratory.settings import RMIS_MIDDLE_SERVER_ADDRESS, RMIS_MIDDLE_SERVER_TOKEN


def form_01(request_data):
Expand Down Expand Up @@ -57,3 +62,78 @@ def form_01(request_data):
if not starts:
return {"ok": False, "result": [], "message": "Не найдены колонка 'Код по прайсу' "}
return {"ok": True, "result": [], "message": ""}


def form_02(request_data):
"""
Загрузка посещений по файлу
На входе:
Файл XLSX с посещениями
Cтруктура:
номер карты, Заведующий отделением, Отделение, Услуга, Фамилия, Имя, Отчество, Дата рождения, СНИЛС, Диагноз, Дата услуги, Это травма
"""
file = request_data.get("file")
wb = load_workbook(filename=file)
ws = wb[wb.sheetnames[0]]
card_number_idx, head_department_idx, department_idx, service_idx, family_idx, name_idx, patronymic_idx, birthday_idx, snils_idx, diagnos_idx, service_date_idx, is_travma_idx = (
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
)
starts = False
file_data = []
for row in ws.rows:
cells = [str(x.value) for x in row]
if not starts:
if "номер карты" in cells:
card_number_idx = cells.index("номер карты")
head_department_idx = cells.index("Заведующий отделением")
department_idx = cells.index("Отделение")
service_idx = cells.index("Услуга")
family_idx = cells.index("Фамилия")
name_idx = cells.index("Имя")
patronymic_idx = cells.index("Отчество")
birthday_idx = cells.index("Дата рождения")
snils_idx = cells.index("СНИЛС")
diagnos_idx = cells.index("Диагноз")
service_date_idx = cells.index("Дата услуги")
is_travma_idx = cells.index("Это травма")
starts = True
else:
tmp_data = {
"cardNumber": cells[card_number_idx],
"headDepartment": cells[head_department_idx],
"department": cells[department_idx],
"service": cells[service_idx],
"family": cells[family_idx],
"name": cells[name_idx],
"patronymic": cells[patronymic_idx],
"birthday": cells[birthday_idx],
"snils": cells[snils_idx],
"diagnos": cells[diagnos_idx],
"serviceDate": cells[service_date_idx],
"isTravma": cells[is_travma_idx],
}
file_data.append(tmp_data)
if not starts:
return {"ok": False, "result": [], "message": "Не найдена колонка 'номер карты' "}

json_str = json.dumps(file_data)
base64_data = base64.b64encode(json_str.encode())
json_data = {"data": base64_data}
headers = {"authorization": f"Bearer {RMIS_MIDDLE_SERVER_TOKEN}"}

response = requests.post(f"{RMIS_MIDDLE_SERVER_ADDRESS}/send-case-visit", json=json_data, headers=headers)
result = response.json()

return {"ok": True, "result": [], "message": f"{result}"}
12 changes: 6 additions & 6 deletions l2-frontend/src/components/UploadFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import api from '@/api';
import typesAndForms, { formsFile, typesFile } from './types-and-forms-file';
const { getTypes, getForms } = typesAndForms();
const { getTypes, getForms, getFileFilters } = typesAndForms();
const store = useStore();
Expand Down Expand Up @@ -149,7 +149,7 @@ onMounted(async () => {
});
const changeType = () => {
fileFilter.value = `.${selectedType.value}`;
fileFilter.value = getFileFilters(selectedType.value);
currentFileForms.value = getForms(
String(selectedType.value),
props.formsFile,
Expand Down Expand Up @@ -213,13 +213,13 @@ const handleFileUpload = () => {
const input = fileInput.value as HTMLInputElement;
const re = /(?:\.([^.]+))?$/;
const fileExtension = re.exec(input.value)[1];
if (fileExtension.toLowerCase() !== String(selectedType.value).toLowerCase()) {
if (fileFilter.value.includes(fileExtension.toLowerCase())) {
[file.value] = input.files;
fileIsSelected.value = true;
} else {
input.value = '';
fileIsSelected.value = false;
root.$emit('msg', 'error', `Файл не ${selectedType.value}`);
} else {
[file.value] = input.files;
fileIsSelected.value = true;
}
};
Expand Down
8 changes: 6 additions & 2 deletions l2-frontend/src/components/types-and-forms-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export default function typesAndForms() {
const fileTypes = ref({
XLSX: { id: 'XLSX', label: 'XLSX' },
});
// todo - сделать соотношение - расширение файла - и все виды accept фильтров {xlsx: '.xlx, .xlsx, ws-excel'}
const fileFilters = {
XLSX: '.xlx, .xls, .xlsx, ws-excel',
};
const getFileFilters = (types) => fileFilters[types.toUpperCase()];
const getTypes = (types: string[]): typesFile[] => {
let result: typesFile[] = [];
if (types && types.length > 0) {
Expand All @@ -33,6 +36,7 @@ export default function typesAndForms() {
const fileForms = ref({
XLSX: {
100.01: { id: '100.01', label: 'Загрузка цен по прайсу' },
100.02: { id: '100.02', label: 'Загрузка посещений' },
},
});
const addForms = (type: string, forms = null, allowedForms: string[] = null) => {
Expand Down Expand Up @@ -61,5 +65,5 @@ export default function typesAndForms() {
}
return result;
};
return { getTypes, getForms };
return { getTypes, getForms, getFileFilters };
}
9 changes: 8 additions & 1 deletion l2-frontend/src/pages/Utils.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
:title-button="loadResultService"
/>
</ul>
<ui class="nav navbar-nav">
<UploadFileModal
tag="li"
:forms-file="['100.02']"
/>
</ui>
</button>
</div>
</div>
Expand All @@ -52,10 +58,11 @@
<script lang="ts">
import * as actions from '@/store/action-types';
import LoadFile from '@/ui-cards/LoadFile.vue';
import UploadFileModal from '@/modals/UploadFileModal.vue';
export default {
name: 'Utils',
components: { LoadFile },
components: { UploadFileModal, LoadFile },
data() {
return {
totalLogs: 0,
Expand Down
4 changes: 4 additions & 0 deletions laboratory/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def __getitem__(self, item):

ALLOWED_FORMS_FILE = {
"100.01": False,
"100.02": False,
}

EXCLUDE_TYPE_RESEARCH = {
Expand All @@ -449,6 +450,9 @@ def __getitem__(self, item):
"is_complex": False,
}

RMIS_MIDDLE_SERVER_ADDRESS = 'http://127.0.0.1:3000'
RMIS_MIDDLE_SERVER_TOKEN = 'token'

CASH_REGISTER_SERVER_ADDRESS = 'http://127.0.0.1:3000/'
CASH_REGISTER_SERVER_TOKEN = 'token'

Expand Down

0 comments on commit 78f106b

Please sign in to comment.