Created
March 16, 2015 21:55
-
-
Save mkusher/221c67e8b30dee553d16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rpc = require('../../custom_node_modules/rabbitmq-rpc')(); | |
var Q = require('q'); | |
api = { | |
patient: null, | |
promiseMap: {}, | |
call: function(addr, data, token){ | |
var deferred = Q.defer(); | |
token = token || 'NURSE'; | |
rpc.call( | |
data, | |
addr, | |
function(response){ | |
var nResponse = JSON.parse(response); | |
if(200 === nResponse.status) | |
deferred.resolve(nResponse.result); | |
else | |
deferred.reject(nResponse); | |
}, | |
token | |
); | |
return deferred.promise; | |
}, | |
createPatient: function(model){ | |
var api = this; | |
var p = this.call( | |
'/test/patient/create/', | |
{'patient':model} | |
).then(function(patient){ | |
api.patient = patient; | |
return patient; | |
}); | |
api.promiseMap.patient = p; | |
return p; | |
}, | |
getPatient: function(){ | |
var api = this; | |
if(!api.patient && !api.promiseMap.patient){ | |
return api.createPatient({ | |
'firstName': 'firstName', | |
'lastName': 'lastName' | |
}); | |
} | |
if(!api.patient) | |
return api.promiseMap.patient; | |
return Q.fcall(function(){ | |
return api.patient; | |
}); | |
}, | |
getAppointment: function(){ | |
return Q.fcall(function(){ | |
return { | |
id: 1396, | |
duration: 900, | |
patient: { | |
id: 659 | |
} | |
}; | |
}); | |
} | |
}; | |
module.exports = api; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment