-
Notifications
You must be signed in to change notification settings - Fork 7
/
prescription.js
86 lines (80 loc) · 2.39 KB
/
prescription.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
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
'use strict';
var _ = require('lodash');
module.exports = function (common) {
return {
/**
* Create a prescription
*
* @param {String} clinicId - id of the clinic
* @param {Object} prescription - prescription to create
* @param cb
* @returns {cb} cb(err, response)
*/
createPrescription: function (clinicId, prescription, cb) {
common.assertArgumentsSize(arguments, 3);
common.doPostWithToken(
`/v1/clinics/${clinicId}/prescriptions`,
prescription,
{ 201: function(res){ return res.body; }},
cb
);
},
/**
* Create a prescription revision
*
* @param {String} clinicId - id of the clinic
* @param {Object} revision - prescription revision to create
* @param {String} prescriptionId - prescription id to attach revision to
* @param cb
* @returns {cb} cb(err, response)
*/
createPrescriptionRevision: function (clinicId, revision, prescriptionId, cb) {
common.assertArgumentsSize(arguments, 4);
common.doPostWithToken(
`/v1/clinics/${clinicId}/prescriptions/${prescriptionId}/revisions`,
revision,
cb
);
},
/**
* Delete a prescription
*
* @param {String} clinicId - id of the clinic
* @param {String} prescriptionId - id of prescription to delete
* @param cb
* @returns {cb} cb(err, response)
*/
deletePrescription: function (clinicId, prescriptionId, cb) {
common.assertArgumentsSize(arguments, 3);
common.doDeleteWithToken(
`/v1/clinics/${clinicId}/prescriptions/${prescriptionId}`,
cb
);
},
/**
* Get all prescriptions for a clinic
*
* @param {String} clinicId - id of the clinic
* @param {Object} [options]
* @param {Number} [options.size] - Query result limit
* @param {Number} [options.page] - Query page offset
* @param cb*
* @returns {cb} cb(err, response)
*/
getPrescriptionsForClinic: function (clinicId, options = {}, cb) {
var url = `/v1/clinics/${clinicId}/prescriptions`;
if(_.isFunction(options) && _.isUndefined(cb)){
cb = options;
options = {};
}
if(!_.isEmpty(options)){
url += '?' + common.serialize(options);
}
common.doGetWithToken(
url,
{ 200: function(res){ return res.body; }, 404: [] },
cb
);
},
};
};