-
Notifications
You must be signed in to change notification settings - Fork 0
/
r_script.js
55 lines (49 loc) · 1.89 KB
/
r_script.js
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
async function sendDataToServer(data) {
try {
const response = await fetch('http://localhost:3000/sendData', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error('Помилка відправки даних на сервер');
}
const responseData = await response.text();
console.log(responseData);
} catch (error) {
console.error('Помилка:', error.message);
}
}
document.getElementById('directionForm').addEventListener('submit', async (event) => {
event.preventDefault();
const patientFullName = document.getElementById('patientFullName').value;
const familyDoctorName = document.getElementById('doctorName').value;
const issueDate = document.getElementById('issueDate').value;
const healthCareFacility = document.getElementById('healthCareFacility').value;
const phoneNumber = document.getElementById('phoneNumber').value;
const priority = document.getElementById('priority').value;
const validityPeriod = document.getElementById('expiryDate').value;
const serviceCode = document.getElementById('serviceCode').value;
const edrpouCode = document.getElementById('healthCareCode').value;
let type;
if (familyDoctorName) {
type = 'Ц';
} else {
type = 'Д';
}
const data = {
type: type,
patientFullName: patientFullName,
familyDoctorName: familyDoctorName,
issueDate: issueDate,
healthCareFacility: healthCareFacility,
phoneNumber: phoneNumber,
priority: priority,
validityPeriod: validityPeriod,
serviceCode: serviceCode,
edrpouCode: edrpouCode
};
await sendDataToServer(data);
});