diff --git a/.DS_Store b/.DS_Store index 2ebd6f5..48a7cf4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md deleted file mode 100644 index 22f2092..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# medods_m3health_extension - -Расширение для МИС Медодс в рамках интеграции с N3.Health \ No newline at end of file diff --git a/content.js b/content.js index 2435a33..b0a6aff 100644 --- a/content.js +++ b/content.js @@ -1,5 +1,7 @@ // content.js -console.log('[EXT][content] loaded'); +if (isDocumentsPage()) { + console.log('[EXT][content] loaded'); +} const dataType = 'metaData'; const userDataType = 'userData'; @@ -38,19 +40,26 @@ window.addEventListener('message', (event) => { }); -async function loadPageData() { +async function loadStorageData() { storageData = await chrome.storage.local.get(dataType); + const userData = await chrome.storage.local.get(userDataType); storageData.userData = userData[userDataType]; +} - if (!storageData || !storageData.metaData || Object.keys(storageData.metaData).length === 0) { - console.log(`[EXT][content] no data for ${dataType}, injecting...`); - injectScript(`${dataType}.js`); - } else { - console.log(`[EXT][content] metadata already exists in storage`); +async function updateStorageData() { + if (!storageData.metaData || !storageData.userData) { + await loadStorageData(); } } +async function loadPageData() { + console.log(`[EXT][content] renew data for ${dataType}, injecting...`); + injectScript(`${dataType}.js`); + + await loadStorageData(); +} + function isDocumentsPage() { return ( location.href.includes('/clients/') && @@ -89,6 +98,8 @@ window.addEventListener('message', async (event) => { return; } + await updateStorageData(); + // Получаем данные из storage if (!storageData.metaData) { window.postMessage({ @@ -171,6 +182,8 @@ window.addEventListener('message', async (event) => { } }, '*'); + await updateStorageData(); + // Фильтруем документы по номерам const filteredDocs = storageData.metaData.docs.filter(doc => event.data.payload.docNumbers.includes(parseInt(doc.number, 10)) @@ -223,10 +236,10 @@ window.addEventListener('message', async (event) => { }, 0); } - // В content.js, в основном обработчике window.addEventListener добавьте: - // ОБРАБОТЧИК ПОДГОТОВКИ ДОКУМЕНТОВ (используем существующие метаданные) if (event.data.type === 'prepareDocuments') { + await updateStorageData(); + // Проверяем наличие метаданных if (!storageData.metaData) { window.postMessage({ @@ -287,6 +300,8 @@ window.addEventListener('message', async (event) => { // ОБРАБОТЧИК ПРОВЕРКИ ПРАВ НА ОТЗЫВ if (event.data.type === 'checkRevokePermission') { + await updateStorageData(); + const hasPermission = String(storageData.userData?.id) === String(event.data.payload.userIdLpu); window.postMessage({ @@ -328,6 +343,8 @@ window.addEventListener('message', async (event) => { // ОБРАБОТЧИК ПОИСКА ПОЛУЧАТЕЛЕЙ ПО ТЕЛЕФОНУ if (event.data.type === 'searchRecipients') { + await updateStorageData(); + const data = { ...event.data.payload, idPatientMis: storageData.metaData.patient.idPatientMis diff --git a/documents.js b/documents.js index 69bac0b..2bc1632 100644 --- a/documents.js +++ b/documents.js @@ -708,10 +708,19 @@ const tableRows = data.map((singing, index) => { // Определяем последний статус const commonStatuses = singing.statuses.filter(s => s.idPatientMis === null); - const lastStatus = commonStatuses.reduce((max, status) => + let lastStatus = commonStatuses.reduce((max, status) => status.id > max.id ? status : max , commonStatuses[0] || singing.statuses[0]); + + if (!lastStatus) { + lastStatus = { + category: 'processing', + description: 'Неизвестный статус', + created_at: singing.created_at + } + } + const statusClass = getStatusClass(lastStatus.category); const statusIcon = getStatusIcon(lastStatus.category); const statusColor = lastStatus.category === 'completed' ? '#67C23A' : diff --git a/singing.js b/singing.js index 7fc34ea..ce540b8 100644 --- a/singing.js +++ b/singing.js @@ -700,7 +700,7 @@ addBtn.style.cssText = 'height: 24px; padding: 0 8px;'; // Проверяем, не добавлен ли уже этот получатель - const alreadyAdded = recipients.some(r => r.id === person.id); + const alreadyAdded = recipients.some(r => r.idPatientMis === person.idPatientMis); if (alreadyAdded) { addBtn.disabled = true; addBtn.classList.add('is-disabled');