-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
254 lines (225 loc) · 12.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html data-bs-theme="dark">
<head>
<title>Study Finder</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>
<body class="text-body-emphasis">
<div class="container mt-4">
<h2 class="mb-4 display-8 fw-semibold text-body-emphasis">Research PACS − Study Finder</h2>
<form id="myForm">
<div class="form-group mb-3">
<label for="acc_input">ACC # in Clinical PACS</label>
<textarea type="text" class="form-control mt-1" id="acc_input" placeholder="Accession # in production PACS" required rows="1" onKeyDown="clearResult()"></textarea>
</div>
<div class="form-group mb-3">
<label for="kid_input">Kerberos ID</label>
<input type="text" class="form-control mt-1" id="kid_input" placeholder="Enter the PI's Kerberos ID" required maxlength="10" onKeyDown="clearResult()">
</div>
<div class="form-group mb-3">
<label for="project_id">Project Name</label>
<input type="text" class="form-control mt-1" id="project_id" placeholder="Enter the project name" required onKeyDown="clearResult()">
</div>
<div class="form-group mb-4">
<label for="preset">Preset</label>
<select class="form-select mt-1" id="preset" onChange="presetSelect(this.selectedIndex);">
<option value="" disabled selected></option>
</select>
</div>
<div class="btn-toolbar justify-content-between form-group mt-4">
<div class="" >
<button type="submit" id="calc_btn" class="btn btn-primary"><i class="bi bi-calculator"></i> Calculate</button>
<button type="button" class="btn btn-secondary me-3" onclick="resetData()"><i class="bi bi-arrow-counterclockwise"></i> Reset</button>
</div>
<div class="btn-group" >
<button type="button" class="btn btn-success" disabled id="save_btn" onclick="savePreset()"><i class="bi bi-floppy"></i> Save</button>
<button type="button" class="btn btn-danger" disabled id="delete_btn" onclick="deletePreset()"><i class="bi bi-trash"></i> Delete</button>
</div>
</div>
</form>
<div class="form-group" style="margin-top: 30px;">
<label for="acc_output">ACC # in Research PACS</label>
<div class="input-group mt-1">
<textarea type="text" class="form-control " id="acc_output" placeholder="" readonly rows="1"></textarea>
<button class="input-group-text" id="btnGroupAddon" onclick="copyToClipboard()"><i class="bi bi-clipboard"></i></button>
</div>
</div>
</div>
<script>
var SipHash=function(){"use strict";function r(r,n){var t=r.l+n.l,h={h:r.h+n.h+(t/2>>>31)>>>0,l:t>>>0};r.h=h.h,r.l=h.l}function n(r,n){r.h^=n.h,r.h>>>=0,r.l^=n.l,r.l>>>=0}function t(r,n){var t={h:r.h<<n|r.l>>>32-n,l:r.l<<n|r.h>>>32-n};r.h=t.h,r.l=t.l}function h(r){var n=r.l;r.l=r.h,r.h=n}function e(e,l,o,u){r(e,l),r(o,u),t(l,13),t(u,16),n(l,e),n(u,o),h(e),r(o,l),r(e,u),t(l,17),t(u,21),n(l,o),n(u,e),h(o)}function l(r,n){return r[n+3]<<24|r[n+2]<<16|r[n+1]<<8|r[n]}function o(r,t){"string"==typeof t&&(t=u(t));var h={h:r[1]>>>0,l:r[0]>>>0},o={h:r[3]>>>0,l:r[2]>>>0},i={h:h.h,l:h.l},a=h,f={h:o.h,l:o.l},c=o,s=t.length,v=s-7,g=new Uint8Array(new ArrayBuffer(8));n(i,{h:1936682341,l:1886610805}),n(f,{h:1685025377,l:1852075885}),n(a,{h:1819895653,l:1852142177}),n(c,{h:1952801890,l:2037671283});for(var y=0;y<v;){var d={h:l(t,y+4),l:l(t,y)};n(c,d),e(i,f,a,c),e(i,f,a,c),n(i,d),y+=8}g[7]=s;for(var p=0;y<s;)g[p++]=t[y++];for(;p<7;)g[p++]=0;var w={h:g[7]<<24|g[6]<<16|g[5]<<8|g[4],l:g[3]<<24|g[2]<<16|g[1]<<8|g[0]};n(c,w),e(i,f,a,c),e(i,f,a,c),n(i,w),n(a,{h:0,l:255}),e(i,f,a,c),e(i,f,a,c),e(i,f,a,c),e(i,f,a,c);var _=i;return n(_,f),n(_,a),n(_,c),_}function u(r){if("function"==typeof TextEncoder)return(new TextEncoder).encode(r);r=unescape(encodeURIComponent(r));for(var n=new Uint8Array(r.length),t=0,h=r.length;t<h;t++)n[t]=r.charCodeAt(t);return n}return{hash:o,hash_hex:function(r,n){var t=o(r,n);return("0000000"+t.h.toString(16)).substr(-8)+("0000000"+t.l.toString(16)).substr(-8)},hash_uint:function(r,n){var t=o(r,n);return 4294967296*(2097151&t.h)+t.l},string16_to_key:function(r){var n=u(r);if(16!==n.length)throw Error("Key length must be 16 bytes");var t=new Uint32Array(4);return t[0]=l(n,0),t[1]=l(n,4),t[2]=l(n,8),t[3]=l(n,12),t},string_to_u8:u}}(),module=module||{},exports=module.exports=SipHash;
</script>
<script>
const Toast = Swal.mixin({
toast: true,
position: 'bottom',
iconColor: 'white',
customClass: {
popup: 'colored-toast',
},
color: "#dee2e6",
background: "#2b3035",
showConfirmButton: false,
timer: 1500,
timerProgressBar: true,
})
document.getElementById("myForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
// Get input values
var acc_input = document.getElementById("acc_input").value.toLowerCase();
var kid_input = document.getElementById("kid_input").value.toLowerCase();
var project_id = document.getElementById("project_id").value.toLowerCase();
var acc_inputs = acc_input.split(/\r?\n|\r|\n/g);
// Perform calculation
var key = SipHash.string16_to_key(kid_input.padEnd(16));
var result = "";
for (var i = 0; i < acc_inputs.length; i++) {
message = project_id+"-"+acc_inputs[i].trim(),
hash_hex = SipHash.hash_hex(key, message);
result += hash_hex.toUpperCase();
if (i < acc_inputs.length - 1) {
result += "\n";
}
}
// Display result
document.getElementById("acc_output").value = result;
acc_output_textarea = document.getElementById("acc_output");
acc_output_textarea.style.height = "";
acc_output_textarea.style.height = Math.min(acc_output_textarea.scrollHeight, 300) + "px";
document.getElementById("save_btn").disabled = false;
});
var acc_input_textarea = document.getElementById("acc_input");
acc_input_textarea.oninput = function() {
acc_input_textarea.style.height = "";
acc_input_textarea.style.height = Math.min(acc_input_textarea.scrollHeight, 300) + "px";
};
function savePreset() {
Swal.fire({
title: "Preset Name",
input: "text",
inputLabel: "Enter a name for the preset",
inputValue: "",
input: "text",
buttonsStyling: false,
customClass: {
confirmButton: 'btn btn-primary me-2',
cancelButton: 'btn btn-secondary',
},
color: "#FFFFFF",
background: "#212529",
showCancelButton: true,
inputValidator: (value) => {
if (!value) {
return "You need to write something!";
}
}
}).then((result) => {
if (result.isConfirmed) {
var preset = document.getElementById("kid_input").value+"#"+document.getElementById("project_id").value;
preset = preset.toLowerCase();
addOption(result.value, preset);
}
});
}
function deletePreset() {
Swal.fire({
title: 'Delete selected preset?',
showDenyButton: true,
confirmButtonText: 'Yes',
denyButtonText: 'No',
buttonsStyling: false,
customClass: {
confirmButton: 'btn btn-primary me-2',
denyButton: 'btn btn-secondary',
},
color: "#FFFFFF",
background: "#212529",
}).then((result) => {
if (result.isConfirmed) {
deleteOption();
}
}
);
}
function presetSelect(index) {
currentValue = document.getElementById("preset").value;
if ((index > 0) && (currentValue != "")) {
document.getElementById("delete_btn").disabled = false;
entries = currentValue.split("#");
if (entries.length < 2) {
return;
}
document.getElementById("kid_input").value = entries[0];
document.getElementById("project_id").value = entries[1];
if (document.getElementById("acc_input").value == "") {
document.getElementById("acc_input").focus();
} else {
document.getElementById("calc_btn").click();
}
} else {
document.getElementById("delete_btn").disabled = true;
}
}
// Function to load options from local storage
function loadOptions() {
var options = localStorage.getItem("presets");
if (options) {
var select = document.getElementById("preset");
select.innerHTML += options;
var sortedOptions = Array.from(select.options).sort((a, b) => a.text.localeCompare(b.text));
select.innerHTML = "";
counter = 0;
sortedOptions.forEach(option => { if ((counter > 0) && (option.name != "")) { select.add(option); } counter++; });
}
}
// Function to add an option to the select box and save it in local storage
function addOption(name, option) {
var select = document.getElementById("preset");
var newOption = document.createElement("option");
newOption.value = option;
newOption.text = name + " (" + option + ")";
select.add(newOption);
// Save options in local storage
localStorage.setItem("presets", select.innerHTML);
}
// Function to delete an option from the select box and remove it from local storage
function deleteOption() {
var select = document.getElementById("preset");
var options = select.options;
var currentIndex = select.selectedIndex;
if (currentIndex > 0) {
select.remove(currentIndex);
}
// Save updated options in local storage
localStorage.setItem("presets", select.innerHTML);
}
// Function to copy the result to the clipboard
function copyToClipboard() {
var copyText = document.getElementById("acc_output");
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
document.execCommand("copy");
Toast.fire({
icon: 'success',
title: 'ACC # copied to clipboard!',
})
}
function resetData() {
document.getElementById("acc_input").value = "";
document.getElementById("kid_input").value = "";
document.getElementById("project_id").value = "";
document.getElementById("delete_btn").disabled = true;
document.getElementById("save_btn").disabled = true;
document.getElementById("preset").value = 0;
}
function clearResult() {
document.getElementById("acc_output").value = "";
}
(function () {
loadOptions();
})();
</script>
</body>
</html>