Download src/static/js/record.js from LabSoft/Epikriza: direct link, hf CLI and curl.
- Browser
- Download file 10.1 kB
-
https://huggingface.co/spaces/LabSoft/Epikriza/resolve/main/src/static/js/record.js
- Command line
-
hf download hf://spaces/LabSoft/Epikriza/src/static/js/record.js
-
curl -L -o record.js https://huggingface.co/spaces/LabSoft/Epikriza/resolve/main/src/static/js/record.js
10.1 kB
| // src/static/js/record.js | |
| const podaciPacijentaBox = document.getElementById("podaciPacijentaBox"); | |
| const epikrizaBox = document.getElementById("epikrizaBox"); | |
| const copyButton = document.getElementById("copyButton"); | |
| const copyMessage = document.getElementById("copyMessage"); | |
| const deleteButton = document.getElementById("deleteButton"); | |
| const postProcessButton = document.getElementById("postProcessButton"); | |
| const uploadButton = document.getElementById("uploadButton"); | |
| const fileInput = document.getElementById("fileInput"); | |
| const uploadCsvButton = document.getElementById("uploadCsvButton"); | |
| const csvInput = document.getElementById("csvInput"); | |
| const patientIdDropdown = document.getElementById("patientIdDropdown"); | |
| const toggleViewButton = document.getElementById("toggleViewButton"); | |
| const tableIcn = document.getElementById("tableIcn"); | |
| const txtIcn = document.getElementById("txtIcn"); | |
| const chatbotIframe = document.getElementById("chatbotIframe"); | |
| const chatbotToggle = document.querySelector(".chatbot-toggle"); | |
| chatbotToggle.addEventListener("click", () => { | |
| if (chatbotIframe.style.display === "none" || !chatbotIframe.style.display) { | |
| openChatUI(); | |
| } else { | |
| closeChatUI(); | |
| } | |
| }); | |
| function openChatUI() { | |
| chatbotIframe.style.display = "block"; | |
| chatbotToggle.style.display = "none"; // Sakrij toggle dugme kada je chat otvoren | |
| } | |
| function closeChatUI() { | |
| chatbotIframe.style.display = "none"; | |
| chatbotToggle.style.display = "flex"; // Prikaži toggle dugme kada je chat zatvoren | |
| } | |
| let isTableView = false; | |
| let detaljiPoId = {}; | |
| function autoResizeTextarea(textarea) { | |
| // Postavljanje visine na 'auto' osigurava da se visina prilagodi sadržaju | |
| textarea.style.height = "auto"; | |
| // Postavljanje visine na scrollHeight + "px" omogućava precizno prilagođavanje | |
| textarea.style.height = textarea.scrollHeight + "px"; | |
| } | |
| uploadCsvButton.addEventListener("click", function () { | |
| csvInput.click(); // Trigger file input dialog when upload CSV button is clicked | |
| }); | |
| function toggleView() { | |
| isTableView = !isTableView; // Promeni stanje prikaza | |
| loadDetailsForId(patientIdDropdown.value); // Ponovo učitaj detalje za trenutno izabrani ID | |
| } | |
| const expectedHeaders = [ | |
| "id_pacijenta", | |
| "rbr_epi", | |
| "rbr_pepi", | |
| "tip_pepi", | |
| "misljenje", | |
| ]; | |
| function isValidCsv(headers) { | |
| // Proverava da li su sva očekivana zaglavlja prisutna | |
| return expectedHeaders.every((header) => headers.includes(header)); | |
| } | |
| csvInput.addEventListener("change", function () { | |
| const file = this.files[0]; | |
| if (file) { | |
| Papa.parse(file, { | |
| complete: function (results) { | |
| const actualHeaders = results.meta.fields; // Papa Parse pruža zaglavlja u `meta.fields` | |
| if (isValidCsv(actualHeaders)) { | |
| // Ako fajl sadrži očekivana zaglavlja, obradi podatke | |
| processCsvResults(results.data); | |
| } else { | |
| // Ako fajl ne sadrži očekivana zaglavlja, obavesti korisnika | |
| alert("Fajl nije važeći. Molimo učitajte ispravan CSV fajl."); | |
| patientIdDropdown.style.display = "none"; // Opciono sakrij dropdown | |
| toggleViewButton.style.display = "none"; // Sakrij dugme za promenu prikaza | |
| } | |
| }, | |
| header: true, | |
| skipEmptyLines: true, | |
| delimiter: "\t", // Ako je potrebno, prilagodite delimiter; uklonite ovu liniju ako želite da Papa Parse automatski detektuje delimiter | |
| }); | |
| } | |
| }); | |
| function processCsvResults(data) { | |
| detaljiPoId = {}; // Resetovanje za svaki novi upload | |
| data.forEach((row) => { | |
| const idPacijenta = row["id_pacijenta"]; | |
| const rbr_epi = row["rbr_epi"]; | |
| const rbr_pepi = row["rbr_pepi"]; | |
| const tip_pepi = row["tip_pepi"]; | |
| const misljenje = row["misljenje"]; | |
| if (!detaljiPoId[idPacijenta]) { | |
| detaljiPoId[idPacijenta] = []; | |
| } | |
| detaljiPoId[idPacijenta].push({ rbr_epi, rbr_pepi, tip_pepi, misljenje }); | |
| }); | |
| populateDropdown(Object.keys(detaljiPoId)); | |
| } | |
| function populateDropdown(ids) { | |
| patientIdDropdown.innerHTML = | |
| '<option value="">Izaberite ID pacijenta</option>'; | |
| ids.forEach((id) => { | |
| const option = document.createElement("option"); | |
| option.value = option.textContent = id; | |
| patientIdDropdown.appendChild(option); | |
| }); | |
| patientIdDropdown.style.display = "block"; | |
| } | |
| function loadDetailsForId(idPacijenta) { | |
| const detalji = detaljiPoId[idPacijenta]; | |
| let detaljiTekst = ""; | |
| let tabelaHtml = ""; | |
| if (isTableView) { | |
| // Generišite HTML za tabelu | |
| tabelaHtml = | |
| '<table border="1"><tr><th>Epi</th><th>Pepi</th><th>Tip</th><th>Mišljenje</th></tr>'; | |
| detalji.forEach((detalj) => { | |
| tabelaHtml += `<tr> | |
| <td>${detalj.rbr_epi}</td> | |
| <td>${detalj.rbr_pepi}</td> | |
| <td>${detalj.tip_pepi}</td> | |
| <td>${detalj.misljenje}</td> | |
| </tr>`; | |
| }); | |
| tabelaHtml += "</table>"; | |
| podaciPacijentaBox.style.display = "none"; // Sakrij textarea | |
| tableIcn.style.display = "none"; | |
| const kontejner = document.getElementById("detaljiTabelaKontejner"); | |
| kontejner.innerHTML = tabelaHtml; // Prikaz tabele | |
| kontejner.style.display = "block"; // Prikaz kontejnera tabele | |
| txtIcn.style.display = "block"; | |
| } else { | |
| // Generišite tekst za textarea | |
| detaljiTekst = detalji.map((detalj) => `${detalj.misljenje}`).join("\n"); | |
| const kontejner = document.getElementById("detaljiTabelaKontejner"); | |
| kontejner.style.display = "none"; // Sakrij tabelu | |
| txtIcn.style.display = "none"; // Prikaz | |
| podaciPacijentaBox.value = detaljiTekst; // Prikaz u textarea | |
| podaciPacijentaBox.style.display = "block"; // Prikaz textarea | |
| autoResizeTextarea(podaciPacijentaBox); | |
| tableIcn.style.display = "block"; | |
| } | |
| } | |
| toggleViewButton.addEventListener("click", toggleView); | |
| // Event listener za promenu izabranog ID-a pacijenta iz dropdown-a | |
| patientIdDropdown.addEventListener("change", function () { | |
| const selectedId = this.value; | |
| if (selectedId) { | |
| loadDetailsForId(selectedId); | |
| toggleViewButton.style.display = "block"; // Prikaz dugmeta samo kada je ID pacijenta odabran | |
| } else { | |
| toggleViewButton.style.display = "none"; // Sakrij dugme ako nije odabran nijedan ID | |
| } | |
| toggleActionButtonsState(); | |
| }); | |
| uploadButton.addEventListener("click", function () { | |
| fileInput.click(); // Trigger file input dialog when upload button is clicked | |
| }); | |
| fileInput.addEventListener("change", function () { | |
| const file = this.files[0]; | |
| if (file) { | |
| const reader = new FileReader(); | |
| reader.onload = function (e) { | |
| podaciPacijentaBox.value = e.target.result; | |
| toggleActionButtonsState(); // Update buttons' state based on the new content | |
| patientIdDropdown.value = ""; | |
| podaciPacijentaBox.style.display = "block"; | |
| const kontejner = document.getElementById("detaljiTabelaKontejner"); | |
| kontejner.style.display = "none"; | |
| // Sakrij dugme za promenu prikaza ako ne želite da bude dostupno dok se ne odabere specifičan ID pacijenta | |
| toggleViewButton.style.display = "none"; | |
| }; | |
| reader.readAsText(file); | |
| } | |
| }); | |
| const generateEpikrizaButton = document.getElementById( | |
| "generateEpikrizaButton" | |
| ); | |
| document.querySelectorAll("button").forEach((button) => { | |
| button.setAttribute("data-original-text", button.textContent); | |
| }); | |
| function setLoadingState(isLoading, button) { | |
| button.disabled = isLoading; | |
| button.textContent = isLoading | |
| ? "Обрада..." | |
| : button.getAttribute("data-original-text"); | |
| } | |
| function toggleActionButtonsState() { | |
| const isPodaciEmpty = !podaciPacijentaBox.value.trim(); | |
| const isEpikrizaEmpty = !epikrizaBox.value.trim(); | |
| postProcessButton.disabled = isEpikrizaEmpty; | |
| deleteButton.disabled = isPodaciEmpty; | |
| copyButton.disabled = isPodaciEmpty; | |
| generateEpikrizaButton.disabled = isPodaciEmpty; | |
| } | |
| // Na početku, inicijalno proverite stanje dugmadi | |
| toggleActionButtonsState(); | |
| postProcessButton.addEventListener("click", function () { | |
| var epikriza = epikrizaBox.value; | |
| setLoadingState(true, this); | |
| fetch("/postprocess", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json", | |
| }, | |
| body: JSON.stringify({ epikriza: epikriza }), | |
| }) | |
| .then((response) => response.json()) | |
| .then((data) => { | |
| epikrizaBox.value = data.processedEpikriza; | |
| toggleActionButtonsState(); | |
| }) | |
| .catch((error) => { | |
| console.error("Error:", error); | |
| }) | |
| .finally(() => { | |
| setLoadingState(false, this); | |
| }); | |
| }); | |
| podaciPacijentaBox.addEventListener("input", toggleActionButtonsState); | |
| epikrizaBox.addEventListener("input", toggleActionButtonsState); | |
| generateEpikrizaButton.addEventListener("click", function () { | |
| var podaci = podaciPacijentaBox.value; | |
| setLoadingState(true, this); | |
| fetch("/epikriza", { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json", | |
| }, | |
| body: JSON.stringify({ podaci: podaci }), | |
| }) | |
| .then((response) => response.json()) | |
| .then((data) => { | |
| epikrizaBox.value = data.epikriza; | |
| toggleActionButtonsState(); | |
| }) | |
| .catch((error) => { | |
| console.error("Error:", error); | |
| }) | |
| .finally(() => { | |
| setLoadingState(false, this); | |
| }); | |
| }); | |
| copyButton.addEventListener("click", () => { | |
| showCopyMessage("Tekst kopiran u clipboard."); | |
| }); | |
| function showCopyMessage(message) { | |
| epikrizaBox.select(); | |
| document.execCommand("copy"); | |
| copyMessage.textContent = message; | |
| copyMessage.classList.add("copyMessage-visible"); // Dodaje klasu za animaciju | |
| setTimeout(() => { | |
| copyMessage.classList.remove("copyMessage-visible"); // Uklanja klasu nakon 2 sekunde | |
| }, 1000); | |
| } | |
| deleteButton.addEventListener("click", () => { | |
| if (confirm("Да ли сте сигурни да желите да обришете текст?")) { | |
| podaciPacijentaBox.value = ""; | |
| epikrizaBox.value = ""; | |
| patientIdDropdown.value = ""; | |
| toggleViewButton.style.display = "none"; | |
| podaciPacijentaBox.style.display = "block"; | |
| const kontejner = document.getElementById("detaljiTabelaKontejner"); | |
| kontejner.style.display = "none"; | |
| toggleActionButtonsState(); | |
| } | |
| }); | |