LukaVidakovic commited on
Commit
e2eeb49
·
verified ·
1 Parent(s): 17f7b09

Update src/static/js/record.js

Browse files
Files changed (1) hide show
  1. src/static/js/record.js +151 -1
src/static/js/record.js CHANGED
@@ -8,6 +8,143 @@ const deleteButton = document.getElementById("deleteButton");
8
  const postProcessButton = document.getElementById("postProcessButton");
9
  const uploadButton = document.getElementById("uploadButton");
10
  const fileInput = document.getElementById("fileInput");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  uploadButton.addEventListener("click", function () {
13
  fileInput.click(); // Trigger file input dialog when upload button is clicked
@@ -19,7 +156,15 @@ fileInput.addEventListener("change", function () {
19
  const reader = new FileReader();
20
  reader.onload = function (e) {
21
  podaciPacijentaBox.value = e.target.result;
 
22
  toggleActionButtonsState(); // Update buttons' state based on the new content
 
 
 
 
 
 
 
23
  };
24
  reader.readAsText(file);
25
  }
@@ -114,9 +259,14 @@ function showCopyMessage(message) {
114
  }
115
 
116
  deleteButton.addEventListener("click", () => {
117
- if (confirm("Да ли сте сигурни да желите да обришете текстове?")) {
118
  podaciPacijentaBox.value = "";
119
  epikrizaBox.value = "";
 
 
 
 
 
120
  toggleActionButtonsState();
121
  }
122
  });
 
8
  const postProcessButton = document.getElementById("postProcessButton");
9
  const uploadButton = document.getElementById("uploadButton");
10
  const fileInput = document.getElementById("fileInput");
11
+ const uploadCsvButton = document.getElementById("uploadCsvButton");
12
+ const csvInput = document.getElementById("csvInput");
13
+ const patientIdDropdown = document.getElementById("patientIdDropdown");
14
+ const toggleViewButton = document.getElementById("toggleViewButton");
15
+ const tableIcn = document.getElementById("tableIcn");
16
+ const txtIcn = document.getElementById("txtIcn");
17
+
18
+ let isTableView = false;
19
+ let detaljiPoId = {};
20
+ function autoResizeTextarea(textarea) {
21
+ // Postavljanje visine na 'auto' osigurava da se visina prilagodi sadržaju
22
+ textarea.style.height = "auto";
23
+ // Postavljanje visine na scrollHeight + "px" omogućava precizno prilagođavanje
24
+ textarea.style.height = textarea.scrollHeight + "px";
25
+ }
26
+
27
+ uploadCsvButton.addEventListener("click", function () {
28
+ csvInput.click(); // Trigger file input dialog when upload CSV button is clicked
29
+ });
30
+
31
+ function toggleView() {
32
+ isTableView = !isTableView; // Promeni stanje prikaza
33
+ loadDetailsForId(patientIdDropdown.value); // Ponovo učitaj detalje za trenutno izabrani ID
34
+ }
35
+
36
+ const expectedHeaders = [
37
+ "id_pacijenta",
38
+ "rbr_epi",
39
+ "rbr_pepi",
40
+ "tip_pepi",
41
+ "misljenje",
42
+ ];
43
+
44
+ function isValidCsv(headers) {
45
+ // Proverava da li su sva očekivana zaglavlja prisutna
46
+ return expectedHeaders.every((header) => headers.includes(header));
47
+ }
48
+
49
+ csvInput.addEventListener("change", function () {
50
+ const file = this.files[0];
51
+ if (file) {
52
+ Papa.parse(file, {
53
+ complete: function (results) {
54
+ const actualHeaders = results.meta.fields; // Papa Parse pruža zaglavlja u `meta.fields`
55
+ if (isValidCsv(actualHeaders)) {
56
+ // Ako fajl sadrži očekivana zaglavlja, obradi podatke
57
+ processCsvResults(results.data);
58
+ } else {
59
+ // Ako fajl ne sadrži očekivana zaglavlja, obavesti korisnika
60
+ alert("Fajl nije važeći. Molimo učitajte ispravan CSV fajl.");
61
+ patientIdDropdown.style.display = "none"; // Opciono sakrij dropdown
62
+ toggleViewButton.style.display = "none"; // Sakrij dugme za promenu prikaza
63
+ }
64
+ },
65
+ header: true,
66
+ skipEmptyLines: true,
67
+ delimiter: "\t", // Ako je potrebno, prilagodite delimiter; uklonite ovu liniju ako želite da Papa Parse automatski detektuje delimiter
68
+ });
69
+ }
70
+ });
71
+
72
+ function processCsvResults(data) {
73
+ detaljiPoId = {}; // Resetovanje za svaki novi upload
74
+ data.forEach((row) => {
75
+ const idPacijenta = row["id_pacijenta"];
76
+ const rbr_epi = row["rbr_epi"];
77
+ const rbr_pepi = row["rbr_pepi"];
78
+ const tip_pepi = row["tip_pepi"];
79
+ const misljenje = row["misljenje"];
80
+ if (!detaljiPoId[idPacijenta]) {
81
+ detaljiPoId[idPacijenta] = [];
82
+ }
83
+ detaljiPoId[idPacijenta].push({ rbr_epi, rbr_pepi, tip_pepi, misljenje });
84
+ });
85
+
86
+ populateDropdown(Object.keys(detaljiPoId));
87
+ }
88
+
89
+ function populateDropdown(ids) {
90
+ patientIdDropdown.innerHTML =
91
+ '<option value="">Izaberite ID pacijenta</option>';
92
+ ids.forEach((id) => {
93
+ const option = document.createElement("option");
94
+ option.value = option.textContent = id;
95
+ patientIdDropdown.appendChild(option);
96
+ });
97
+ patientIdDropdown.style.display = "block";
98
+ }
99
+ function loadDetailsForId(idPacijenta) {
100
+ const detalji = detaljiPoId[idPacijenta];
101
+ let detaljiTekst = "";
102
+ let tabelaHtml = "";
103
+
104
+ if (isTableView) {
105
+ // Generišite HTML za tabelu
106
+ tabelaHtml =
107
+ '<table border="1"><tr><th>Epi</th><th>Pepi</th><th>Tip</th><th>Mišljenje</th></tr>';
108
+ detalji.forEach((detalj) => {
109
+ tabelaHtml += `<tr>
110
+ <td>${detalj.rbr_epi}</td>
111
+ <td>${detalj.rbr_pepi}</td>
112
+ <td>${detalj.tip_pepi}</td>
113
+ <td>${detalj.misljenje}</td>
114
+ </tr>`;
115
+ });
116
+ tabelaHtml += "</table>";
117
+ podaciPacijentaBox.style.display = "none"; // Sakrij textarea
118
+ tableIcn.style.display = "none";
119
+ const kontejner = document.getElementById("detaljiTabelaKontejner");
120
+ kontejner.innerHTML = tabelaHtml; // Prikaz tabele
121
+ kontejner.style.display = "block"; // Prikaz kontejnera tabele
122
+ txtIcn.style.display = "block";
123
+ } else {
124
+ // Generišite tekst za textarea
125
+ detaljiTekst = detalji.map((detalj) => `${detalj.misljenje}`).join("\n");
126
+ const kontejner = document.getElementById("detaljiTabelaKontejner");
127
+ kontejner.style.display = "none"; // Sakrij tabelu
128
+ txtIcn.style.display = "none"; // Prikaz
129
+ podaciPacijentaBox.value = detaljiTekst; // Prikaz u textarea
130
+ podaciPacijentaBox.style.display = "block"; // Prikaz textarea
131
+ autoResizeTextarea(podaciPacijentaBox);
132
+ tableIcn.style.display = "block";
133
+ }
134
+ }
135
+
136
+ toggleViewButton.addEventListener("click", toggleView);
137
+ // Event listener za promenu izabranog ID-a pacijenta iz dropdown-a
138
+ patientIdDropdown.addEventListener("change", function () {
139
+ const selectedId = this.value;
140
+ if (selectedId) {
141
+ loadDetailsForId(selectedId);
142
+ toggleViewButton.style.display = "block"; // Prikaz dugmeta samo kada je ID pacijenta odabran
143
+ } else {
144
+ toggleViewButton.style.display = "none"; // Sakrij dugme ako nije odabran nijedan ID
145
+ }
146
+ toggleActionButtonsState();
147
+ });
148
 
149
  uploadButton.addEventListener("click", function () {
150
  fileInput.click(); // Trigger file input dialog when upload button is clicked
 
156
  const reader = new FileReader();
157
  reader.onload = function (e) {
158
  podaciPacijentaBox.value = e.target.result;
159
+
160
  toggleActionButtonsState(); // Update buttons' state based on the new content
161
+
162
+ patientIdDropdown.value = "";
163
+ podaciPacijentaBox.style.display = "block";
164
+ const kontejner = document.getElementById("detaljiTabelaKontejner");
165
+ kontejner.style.display = "none";
166
+ // Sakrij dugme za promenu prikaza ako ne želite da bude dostupno dok se ne odabere specifičan ID pacijenta
167
+ toggleViewButton.style.display = "none";
168
  };
169
  reader.readAsText(file);
170
  }
 
259
  }
260
 
261
  deleteButton.addEventListener("click", () => {
262
+ if (confirm("Да ли сте сигурни да желите да обришете текст?")) {
263
  podaciPacijentaBox.value = "";
264
  epikrizaBox.value = "";
265
+ patientIdDropdown.value = "";
266
+ toggleViewButton.style.display = "none";
267
+ podaciPacijentaBox.style.display = "block";
268
+ const kontejner = document.getElementById("detaljiTabelaKontejner");
269
+ kontejner.style.display = "none";
270
  toggleActionButtonsState();
271
  }
272
  });