-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
180 lines (169 loc) · 6.33 KB
/
App.tsx
File metadata and controls
180 lines (169 loc) · 6.33 KB
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
import { useEffect, useState } from "react";
import type { Schema } from "../amplify/data/resource";
import { generateClient } from "aws-amplify/data";
import './App.css'
const client = generateClient<Schema>();
function App() {
const [patients, setPatients] = useState<Array<Schema["Patient"]["type"]>>([]);
const [showForm, setShowForm] = useState(false);
const [name, setName] = useState('');
const [gender, setGender] = useState<Schema["Patient"]["type"]["gender"]>('unknown');
const [birthDate, setBirthDate] = useState('');
const [selectedPatients, setSelectedPatients] = useState<string[]>([]); //To track selected patients
const [searchQuery, setSearchQuery] = useState(''); //New state for search query
const [filteredPatients, setFilteredPatients] = useState<Array<Schema["Patient"]["type"]>>([]); //State for filtered patients
const [phoneNumber, setPhoneNumber] = useState('');
const [active, setActive] = useState(false);
useEffect(() => {
const subscription = client.models.Patient.observeQuery().subscribe({
next: (data) => setPatients([...data.items]),
});
return () => subscription.unsubscribe();
}, []);
useEffect(() => {
const filtered = patients.filter((patient) =>
patient.name.toLowerCase().includes(searchQuery.toLowerCase())
);
setFilteredPatients(filtered);
}, [searchQuery, patients]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!name || !gender || !birthDate) {
alert("Please fill all fields.");
return;
}
try {
await client.models.Patient.create({
name,
gender,
birthDate,
// active: true,
identifiers: [],
address: [],
contact: [phoneNumber],
active,
});
setName('');
setGender('unknown');
setBirthDate('');
setShowForm(false); //Hide the form after submission
} catch (error) {
console.error("Error creating patient:", error);
alert("Error creating patient. Please try again.");
}
};
const handleCheckboxChange = (patientId: string) => {
const updatedSelectedPatients = selectedPatients.includes(patientId)
? selectedPatients.filter((id) => id !== patientId) //remove if already selected
: [...selectedPatients, patientId]; //add if not selected
setSelectedPatients(updatedSelectedPatients);
};
const handleSelectAll = () => {
setSelectedPatients(patients.map((patient) => patient.id));
};
const handleDeselectAll = () => {
setSelectedPatients([]);
};
return (
<main>
<nav className="navbar">
<ul className="navbar-list">
<li className="navbar-item">
<a href="#" className="navbar-link">Reports</a>
</li>
<li className="navbar-item">
<a href="#" className="navbar-link">Settings</a>
</li>
</ul>
</nav>
<h2>Patient Records</h2>
<div className="search-container"> {/* Added a container for styling */}
<input
className="search-bar"
type="text"
placeholder="Search by name..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
/>
<img src="/search.svg" alt="Search" className="search-icon" /> {/* Added search icon */}
</div>
{/* <button onClick={() => setShowForm(true)}>+ Add New Patient</button> */}
{showForm && (
<form onSubmit={handleSubmit}>
{/* Form content remains the same */}
<label>
Name:
<input type="text" value={name} onChange={(e) => setName(e.target.value)} required />
</label>
<br />
<label>
Gender:
<select value={gender ?? ''} onChange={(e) => setGender(e.target.value as Schema["Patient"]["type"]["gender"])} required>
<option value="">Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
<option value="unknown">Unknown</option>
</select>
</label>
<br />
<label>
Birth Date (YYYY-MM-DD):
<input type="date" value={birthDate} onChange={(e) => setBirthDate(e.target.value)} required />
</label>
<br />
<label>
Phone Number:
<input
type="tel"
value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)}
required
/>
</label>
<br />
<label>
Active:
<input type="checkbox" checked={active} onChange={(e) => setActive(e.target.checked)} />
</label>
<br />
<button type="submit">Add Patient</button>
<button type="button" onClick={() => setShowForm(false)}>Cancel</button>
</form>
)}
<div>
<button onClick={handleSelectAll}>Select All</button>
<button onClick={handleDeselectAll}>Deselect All</button>
</div>
<ul>
{filteredPatients.map((patient) => (
<li key={patient.id} className="patient-list-item">
<input
type="checkbox"
id={patient.id}
checked={selectedPatients.includes(patient.id)}
onChange={() => handleCheckboxChange(patient.id)}
/>
{patient.active ?
<div className="patient-consent">
{ "AI consent" }
</div>
:
<div className="no-patient-consent">
{ "No AI consent"}
</div>}
<div className="patient-info"> {/* Added class for styling */}
<span className="patient-name">{patient.name}</span>
{patient.contact?.[0] && <span className="patient-phone">{patient.contact?.[0]}</span>}
</div>
</li>
))}
</ul>
<div style={{ display: 'flex', justifyContent: 'center', }}> {/* Center the button */}
<button style={{backgroundColor: '#00FF00', borderRadius: '50%', padding:"0.5em"}}>
<img src="/phone.svg" alt="" style={{ width: '3em', height: '3em' }}/>
</button> </div>
</main>
);
}
export default App;