-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.html
167 lines (142 loc) · 6.97 KB
/
upload.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Lane</title>
<!--CSS-->
<link rel="stylesheet" href="./dist/output.css">
<!--ICONS-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/fonts/remixicon.min.css">
<!--Fonts-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=Jost:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<!-- <link rel="stylesheet" href="css/swiper-bundle.min.css"> -->
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css">
<script type="module" src="./js/sign-up.js" defer></script>
<script src="https://www.gstatic.com/firebasejs/10.13.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.13.2/firebase-storage.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tesseract.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.10.377/pdf.min.js"></script>
</head>
<body>
<!--Navbar-->
<header class="sticky top-0 h-[90px] shadow-xl z-30 bg-white">
<div class="container mx-auto flex justify-between h-full items-center">
<a href="#">
<img src="./assets/logo.jpeg" alt="" class="w-[200px]">
</a>
<nav>
<div class="cursor-pointer lg:hidden" id="nav_trigger_btn">
<i class="ri-menu-4-line text-4xl text-primary"></i>
</div>
<ul class="fixed w-full h-0 p-0 bg-white overflow-hidden border-t top-[90px] left-0 right-0 flex flex-col gap-4 lg:relative lg:flex-row lg:p-0 lg:top-0 lg:border-none lg:h-full transition-all duration-300" id="nav_menu">
<li class="p-2"><a href="./caretaker-dashboard.html">Dashboard</a></li>
<li class="p-2"><a href="./index.html">Home</a></li>
<li class="p-2"><a href="./index.html#about">About</a></li>
<li class="p-2"><a href="./index.html#contact">Contact Us</a></li>
<!-- Placeholder for user info or sign-in button -->
<div id="user-auth-section">
<button class="btn-accent w-[120px] h-[50px] lg:p-0 p-2 rounded-lg">
<a href="./sign-up.html" class="text-white hover:text-black" id="auth-btn">Sign Up</a>
</button>
</div>
</ul>
</nav>
</div>
</header>
<main class="max-w-[1920px] mx-auto bg-white overflow-hidden">
<h2 class="flex justify-center items-center mt-10 h2">Upload Prescription</h1>
<form id="uploadForm" enctype="multipart/form-data" class="mb-6 flex justify-center items-center gap-4 mt-8">
<input type="file" id="fileInput" accept="image/*,application/pdf" class="block p-2 border border-gray-300 rounded-md" required>
<button type="submit" class="btn-accent text-white px-6 py-2 rounded-lg">Upload</button>
</form>
<div id="ocrResult" class="mt-4 mx-auto w-full max-w-md">
<h3 class="h3 flex justify-center items-center">Patients Medicines</h2>
<ul id="medicineList" class="list-none space-y-2"></ul>
</div>
</main>
<script src="./js/main.js"></script>
<script>
const uploadForm = document.getElementById('uploadForm');
const medicineList = document.getElementById('medicineList');
if (uploadForm) {
uploadForm.addEventListener('submit', (event) => {
event.preventDefault();
const file = document.getElementById('fileInput').files[0];
if (!file) {
alert('Please select a file.');
return;
}
// Use FileReader to read the file and process it for OCR
const reader = new FileReader();
reader.onload = function(e) {
const fileURL = e.target.result;
if (file.type.includes('image')) {
processImageOCR(fileURL);
} else {
alert('PDF OCR is not implemented yet.');
}
};
reader.readAsDataURL(file);
});
}
function processImageOCR(imageURL) {
Tesseract.recognize(
imageURL,
'eng',
{ logger: (m) => console.log(m) }
).then(({ data: { text } }) => {
console.log('Extracted text:', text);
displayExtractedMedicines(extractMedicineNamesAndDosages(text));
}).catch(err => {
console.error('OCR failed:', err);
});
}
function extractMedicineNamesAndDosages(text) {
const dementiaMedicines = [
"Donepezil", "Rivastigmine", "Galantamine", "Memantine",
"Namenda", "Exelon", "Razadyne", "Aricept", "Namzaric",
"Olanzapine", "Risperidone"
];
const dosagePattern = /(\d+(\.\d+)?\s*(mg|ml|tablets|capsules|pills|mcg|g))/gi;
const extractedMedicines = [];
dementiaMedicines.forEach(medicine => {
const regex = new RegExp(`${medicine}.{0,30}${dosagePattern.source}`, 'gi');
const match = text.match(regex);
if (match) {
const dosage = match[0].match(dosagePattern);
extractedMedicines.push({
"Medicine Name": medicine,
"Dosage": dosage ? dosage[0] : "No dosage found"
});
}
});
return extractedMedicines;
}
function displayExtractedMedicines(medicines) {
if (medicines.length === 0) {
alert('No dementia medicines found.');
return;
}
medicineList.innerHTML = ''; // Clear previous results
// Save extracted medicines to localStorage
localStorage.setItem('extractedMedicines', JSON.stringify(medicines));
medicines.forEach(medicine => {
const listItem = document.createElement('li');
listItem.innerHTML = `
<input type="checkbox" class="mr-2 rounded-md">
${medicine['Medicine Name']} - ${medicine['Dosage']}
`;
listItem.querySelector('input').addEventListener('change', function() {
listItem.classList.toggle('line-through');
listItem.classList.toggle('bg-green-100');
});
listItem.classList.add('flex', 'items-center', 'bg-green-50', 'px-4', 'py-2', 'rounded-lg', 'shadow-sm');
medicineList.appendChild(listItem);
});
}
</script>
</body>
</html>