-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-appointment.js
61 lines (52 loc) · 1.54 KB
/
create-appointment.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
56
57
58
59
60
61
'use strict';
var aws = require('aws-sdk');
var db = new aws.DynamoDB.DocumentClient();
const RESPONSE = {
OK : {
statusCode : 200,
message: {},
},
ERROR : {
status : 400,
message: "Unexpected Error. Please try again."
}
};
exports.handler = (event, context, callback) => {
var newAppointment = event;
// Format startTime
var date = new Date();
var startTime = new Date(newAppointment.startTime);
var startTime_s = String(startTime.toJSON());
// Format endTime
var endTime = new Date(startTime_s);
var endTime_date = new Date(endTime.setHours(endTime.getHours() + 1));
var newAppointment = {
id: uuid(),
status: "REQUESTED",
created: String(date.toJSON()),
lastUpdated: String(date.toJSON()),
startTime: String(startTime.toJSON()),
endTime: String(endTime_date.toJSON()),
location: "Office",
comment: event.comment,
providerId: event.providerId,
patient: event.patient,
patientId: event.patientId
};
db.put({ TableName: 'appointments', Item: newAppointment },function(err, data) {
if (err) { RESPONSE.ERROR.message = err; callback(null, RESPONSE.ERROR); }
else {
RESPONSE.OK = newAppointment;
callback(null, RESPONSE.OK);
}
});
};
function uuid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}