def getConsultWF (args): cref = args['cref']; user = args['user'] failureResult = { 'result' : 'Failure', 'message' : '' } #successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if(cwf.user.id() != user.key.id() and cwf.provider.id() != user.key.id()): failureResult['message'] = 'Invalid Appointment Request. C-Ref belongs to another user' return failureResult successResult = ndb_json.dumps(cwf) #successResult['result'] = 'Success' return successResult
def getConsultWF(args): cref = args['cref'] user = args['user'] failureResult = {'result': 'Failure', 'message': ''} #successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if (cwf.user.id() != user.key.id() and cwf.provider.id() != user.key.id()): failureResult[ 'message'] = 'Invalid Appointment Request. C-Ref belongs to another user' return failureResult successResult = ndb_json.dumps(cwf) #successResult['result'] = 'Success' return successResult
def getProviderByKey(providerId): providerObj = queryAPI.findProviderById(providerId) if (providerObj != None): return ndb_json.dumps(providerObj) else: rs = { "result": "Failure", "code": 'S4001', "message": 'Unknown Provider ' + providerId } return rs
def getProviderByKey(providerId): providerObj = queryAPI.findProviderById(providerId) if(providerObj != None): return ndb_json.dumps(providerObj) else: rs = { "result" : "Failure", "code" : 'S4001', "message" : 'Unknown Provider '+providerId } return rs
def querySubscriberByEmail(queryJSON): if (queryJSON['email'] != None): subscrList = queryAPI.findSubscriberByEmail(queryJSON['email']) return ndb_json.dumps(subscrList) else: rs = { "result": "Failure", "code": 'S4001', "message": 'Query not supported' } return rs
def getSubscriberByKey(subscriberId): subscriberObj = queryAPI.findSubscriberById(subscriberId) if(subscriberObj != None): return ndb_json.dumps(subscriberObj) else: rs = { "result" : "Failure", "code" : 'S4002', "message" : 'Unknown Subscriber '+subscriberId } return rs
def getSubscriberByKey(subscriberId): subscriberObj = queryAPI.findSubscriberById(subscriberId) if (subscriberObj != None): return ndb_json.dumps(subscriberObj) else: rs = { "result": "Failure", "code": 'S4002', "message": 'Unknown Subscriber ' + subscriberId } return rs
def querySubscriberByEmail(queryJSON): if ( queryJSON['email'] != None): subscrList = queryAPI.findSubscriberByEmail ( queryJSON['email'] ) return ndb_json.dumps(subscrList) else: rs = { "result" : "Failure", "code" : 'S4001', "message" : 'Query not supported' } return rs
def getFeedback(feedbackId): if(feedbackId == None): rs = { "result" : "Failure", "code" : 'S4001', "message" : 'No known feedback '+str(feedbackId) } return rs else: feedback = queryAPI.findFeedbackById(int(feedbackId)) return ndb_json.dumps(feedback)
def patientQuestionWF(args): print 'patientQuestionWF args', args cref = args['_id'] user = args['user'] failureResult = {'result': 'Failure', 'message': ''} successResult = {'result': 'Success', 'message': '', 'reference': ''} # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if (cwf.user.id() != user.key.id()): failureResult[ 'message'] = 'Invalid Appointment Request. C-Ref belongs to another user' return failureResult # cwf.patientDetailsWF.questionId = [] # cwf.patientDetailsWF.answerText = [] # for k in sorted(args.keys()): # if (k != 'cref' and k != 'reference' and k != 'user'): # cwf.patientDetailsWF.questionId.append (k) # cwf.patientDetailsWF.answerText.append (args[k]) # reset all existing answers, if there are any, but leave the first one because it is summary of the appointment cwf.patientDetailsWF.answerText[1:] = [] for i in range(len(args['patientDetailsWF']['answerText'][1:])): # print 'qkey'+str(i+1), args['patientDetailsWF']['answerText'][i+1] cwf.patientDetailsWF.questionId.append('qkey' + str(i + 1)) cwf.patientDetailsWF.answerText.append( args['patientDetailsWF']['answerText'][i + 1]) # In-Progress # cwf.overallStatus = 2 cwf.put() successResult['message'] = 'Patient Questionnaire Information Stored' successResult['reference'] = cwf.key.id() successResult['cwf'] = ndb_json.dumps(cwf) return successResult
def patientQuestionWF (args): print 'patientQuestionWF args', args cref = args['_id'] user = args['user'] failureResult = { 'result' : 'Failure', 'message' : '' } successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if(cwf.user.id() != user.key.id()): failureResult['message'] = 'Invalid Appointment Request. C-Ref belongs to another user' return failureResult # cwf.patientDetailsWF.questionId = [] # cwf.patientDetailsWF.answerText = [] # for k in sorted(args.keys()): # if (k != 'cref' and k != 'reference' and k != 'user'): # cwf.patientDetailsWF.questionId.append (k) # cwf.patientDetailsWF.answerText.append (args[k]) # reset all existing answers, if there are any, but leave the first one because it is summary of the appointment cwf.patientDetailsWF.answerText[1:] = [] for i in range(len(args['patientDetailsWF']['answerText'][1:])): # print 'qkey'+str(i+1), args['patientDetailsWF']['answerText'][i+1] cwf.patientDetailsWF.questionId.append ('qkey'+str(i+1)) cwf.patientDetailsWF.answerText.append (args['patientDetailsWF']['answerText'][i+1]) # In-Progress # cwf.overallStatus = 2 cwf.put() successResult['message'] = 'Patient Questionnaire Information Stored' successResult['reference'] = cwf.key.id() successResult['cwf'] = ndb_json.dumps(cwf) return successResult
def getRecentAppointmentsForProvider(args): provider = args['user'] failureResult = {'result': 'Failure', 'message': ''} successResult = {'result': 'Success', 'message': '', 'reference': ''} # try: providerId = provider.key.id() appts = queryAPI.findConsultationByProviderId(provider.key.id()) except Exception as ex: print 'exception raised is ', ex failureResult['message'] = 'Invalid provider - ' + str(providerId) return failureResult return ndb_json.dumps(appts)
def setupProfile(profileJSON): print 'json input is ', profileJSON # check if this email is already registered subscrList = queryAPI.findSubscriberByEmail(profileJSON['email']) if (len(subscrList) == 0): # failure response print 'Subscriber email not found to setup profile', profileJSON[ 'email'] rs = { "result": "Failure", "code": 'S4001', "message": 'Unrecognized Subscriber' } return rs else: # check if the profile already exists profileList = queryAPI.findProfileByProviderId(subscrList[0].key.id()) if (len(profileList) == 0): if ('_id' in profileJSON): rs = { "result": "Failure", "code": 'S4002', "message": '_id provided for a new profile' } return rs # it is new case # create a new session entry profile = providerProfile.PbProfile() profile.subscriber = subscrList[0].key else: # setup profile for the first time # profileId = profileJSON['_id'] # profile = queryAPI.findProfileByID(profileId) profile = profileList[0] profileJSON['name'] = subscrList[0].name # createDefaultProfile(profile) profile.updateWithJSONInput(profileJSON) profile.put() return ndb_json.dumps(profile)
def getRecentAppointmentsForProvider (args): provider = args['user'] failureResult = { 'result' : 'Failure', 'message' : '' } successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: providerId = provider.key.id() appts = queryAPI.findConsultationByProviderId(provider.key.id()) except Exception as ex: print 'exception raised is ', ex failureResult['message'] = 'Invalid provider - ' + str(providerId) return failureResult return ndb_json.dumps(appts)
def getProfile(providerId): if (providerId == None): rs = { "result": "Failure", "code": 'S4001', "message": 'Unrecognized Provider ' + str(providerId) } return rs else: profileList = queryAPI.findProfileByProviderId(int(providerId)) size = len(profileList) if (size == 1): return ndb_json.dumps(profileList[0]) elif (size == 0): raise Exception('Not a valid provider', providerId) else: print 'something wrong in this provider configuration. There is more than one profile available', providerId raise Exception('Profile is not available', providerId)
def apptRequestWF (args): cref = args['cref']; patientName = args['patientName'] patientAge = args['age'] patientSex = args['sex'] patientPhone = args['patientPhone'] requestTSStr = args['requestedTS'] consultationModePreference = args['consult_mode_pref'] print 'requestTSStr received', requestTSStr problemSummary = args['problemSummary'] user = args['user'] failureResult = { 'result' : 'Failure', 'message' : '' } successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(cref) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if(cwf.user.id() != user.key.id()): failureResult['message'] = 'Invalid Appointment Request. C-Ref belongs to another user' return failureResult cwf.apptWF = subscriber.ApptWF() cwf.apptWF.requestedTS = dateutil.parser.parse(requestTSStr).replace(tzinfo=None) print 'requestTS into python', cwf.apptWF.requestedTS cwf.apptWF.confirmedTS = dateutil.parser.parse(requestTSStr).replace(tzinfo=None) cwf.apptWF.apptStatusChain = [2] cwf.apptWF.apptStatus = 2 # cwf = subscriber.ConsultationWF() # cwf.provider = provider.key # cwf.user = user.key cwf.patientDetailsWF = subscriber.PatientDetailsWF() cwf.patientDetailsWF.patientName = patientName cwf.patientDetailsWF.patientAge = patientAge cwf.patientDetailsWF.patientSex = patientSex cwf.patientDetailsWF.patientPhone = patientPhone cwf.patientDetailsWF.questionId = ['Summary'] cwf.patientDetailsWF.answerText = [problemSummary] cwf.statusWF = subscriber.StatusWF() cwf.statusWF.overallStatusChain = [1] cwf.statusWF.overallStatus = 1 # create paymentWF and populate expected amount cwf.paymentWF = subscriber.PaymemtWF() # get the provider profile to populate expected payment profileList = queryAPI.findProfileByProviderId(cwf.provider.id()) if(profileList == None or len(profileList) == 0): failureResult['message'] = 'Invalid Provider - ' + str(cwf.provider.id()) return failureResult profile = profileList[0] cwf.paymentWF.prExpAmt = profile.feeStruc.regularFee cwf.paymentWF.plExpAmt = profile.feeStruc.platformFee # platformAPI.getPlatformFee(cwf) cwf.paymentWF.txExpAmt = 0 cwf.paymentWF.expCurr = profile.feeStruc.baseCurrency cwf.paymentWF.deriveTotalExpectedAmount() cwf.paymentWF.paymentStatus = 1 cwf.paymentWF.paymentStatusChain = [1] # create meetingWF and set the meeting type to consultation_mode_preference[phone, video or anything] cwf.meetingWF = subscriber.MeetingWF() cwf.meetingWF.meetingType = consultationModePreference # In-Progress cwf.overallStatus = 2 cwf.put() dispatcher.sendSMSToProvider(cref, 2) successResult['message'] = 'Consultation request sent to Doctor. Waiting for his confirmation' successResult['reference'] = cwf.key.id() successResult['cwf'] = ndb_json.dumps(cwf) return successResult
def consultWF_setApptState(args): cref = args['cref'] user = args['user'] aptWFCd = args['aptWFCd'] failureResult = { 'result' : 'Failure', 'message' : '' } #successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if(cwf.user.id() != user.key.id() and cwf.provider.id() != user.key.id() ): failureResult['message'] = 'Invalid Appointment Request. C-Ref belongs to another user/provider' return failureResult # def rescheduleByProvider(): # rescheduleDt = args['rescheduleDt'] # reason = args['reason'] # cwf.apptWF.rescheduleTimeByProvider(rescheduleDt, reason) stateMap = {3:"confirmTimeByProvider",30:"confirmTimeByUser", 4: "rescheduleTimeByUser", 5: "rescheduleTimeByProvider", 6: "cancelByUser", 7: "cancelByProvider"} if(aptWFCd not in stateMap): failureResult['message'] = 'Invalid workflow state - '+ str(aptWFCd) return failureResult # rescheduleDtIfProvided = args['rescheduledDt'] # reasonIfProvided = args['reason'] rescheduleDtIfProvided = args.get('rescheduledDt', None) reasonIfProvided = args.get('reason', None) print 'statemap/aptWFCd', aptWFCd, stateMap[aptWFCd], cwf if(cwf.apptWF == None): # delete this junk(unfinished) appointment cwf.key.delete() return {'result' : 'Success', 'message' : 'Unfinished Appointment Deleted','reference':cref } statusAction = getattr(cwf.apptWF, stateMap[aptWFCd]) if(statusAction != None): getattr(cwf.apptWF, stateMap[aptWFCd])(reasonIfProvided, rescheduleDtIfProvided ) else: # appt wf object does not exist so we just junk it now. pass cwf.put() if(aptWFCd == 3 or aptWFCd == 5): dispatcher.sendSMSToUser(cref, aptWFCd) elif(aptWFCd == 4): dispatcher.sendSMSToProvider(cref, aptWFCd) successResult = ndb_json.dumps(cwf) #successResult['result'] = 'Success' return successResult
def consultWF_setApptState(args): cref = args['cref'] user = args['user'] aptWFCd = args['aptWFCd'] failureResult = {'result': 'Failure', 'message': ''} #successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if (cwf.user.id() != user.key.id() and cwf.provider.id() != user.key.id()): failureResult[ 'message'] = 'Invalid Appointment Request. C-Ref belongs to another user/provider' return failureResult # def rescheduleByProvider(): # rescheduleDt = args['rescheduleDt'] # reason = args['reason'] # cwf.apptWF.rescheduleTimeByProvider(rescheduleDt, reason) stateMap = { 3: "confirmTimeByProvider", 30: "confirmTimeByUser", 4: "rescheduleTimeByUser", 5: "rescheduleTimeByProvider", 6: "cancelByUser", 7: "cancelByProvider" } if (aptWFCd not in stateMap): failureResult['message'] = 'Invalid workflow state - ' + str(aptWFCd) return failureResult # rescheduleDtIfProvided = args['rescheduledDt'] # reasonIfProvided = args['reason'] rescheduleDtIfProvided = args.get('rescheduledDt', None) reasonIfProvided = args.get('reason', None) print 'statemap/aptWFCd', aptWFCd, stateMap[aptWFCd], cwf if (cwf.apptWF == None): # delete this junk(unfinished) appointment cwf.key.delete() return { 'result': 'Success', 'message': 'Unfinished Appointment Deleted', 'reference': cref } statusAction = getattr(cwf.apptWF, stateMap[aptWFCd]) if (statusAction != None): getattr(cwf.apptWF, stateMap[aptWFCd])(reasonIfProvided, rescheduleDtIfProvided) else: # appt wf object does not exist so we just junk it now. pass cwf.put() if (aptWFCd == 3 or aptWFCd == 5): dispatcher.sendSMSToUser(cref, aptWFCd) elif (aptWFCd == 4): dispatcher.sendSMSToProvider(cref, aptWFCd) successResult = ndb_json.dumps(cwf) #successResult['result'] = 'Success' return successResult
def apptRequestWF(args): cref = args['cref'] patientName = args['patientName'] patientAge = args['age'] patientSex = args['sex'] patientPhone = args['patientPhone'] requestTSStr = args['requestedTS'] consultationModePreference = args['consult_mode_pref'] print 'requestTSStr received', requestTSStr problemSummary = args['problemSummary'] user = args['user'] failureResult = {'result': 'Failure', 'message': ''} successResult = {'result': 'Success', 'message': '', 'reference': ''} # try: cwf = queryAPI.findConsultationWFById(cref) except: failureResult['message'] = 'Invalid Reference - ' + str(cref) return failureResult # check that cwf was initiated by this same user if (cwf.user.id() != user.key.id()): failureResult[ 'message'] = 'Invalid Appointment Request. C-Ref belongs to another user' return failureResult cwf.apptWF = subscriber.ApptWF() cwf.apptWF.requestedTS = dateutil.parser.parse(requestTSStr).replace( tzinfo=None) print 'requestTS into python', cwf.apptWF.requestedTS cwf.apptWF.confirmedTS = dateutil.parser.parse(requestTSStr).replace( tzinfo=None) cwf.apptWF.apptStatusChain = [2] cwf.apptWF.apptStatus = 2 # cwf = subscriber.ConsultationWF() # cwf.provider = provider.key # cwf.user = user.key cwf.patientDetailsWF = subscriber.PatientDetailsWF() cwf.patientDetailsWF.patientName = patientName cwf.patientDetailsWF.patientAge = patientAge cwf.patientDetailsWF.patientSex = patientSex cwf.patientDetailsWF.patientPhone = patientPhone cwf.patientDetailsWF.questionId = ['Summary'] cwf.patientDetailsWF.answerText = [problemSummary] cwf.statusWF = subscriber.StatusWF() cwf.statusWF.overallStatusChain = [1] cwf.statusWF.overallStatus = 1 # create paymentWF and populate expected amount cwf.paymentWF = subscriber.PaymemtWF() # get the provider profile to populate expected payment profileList = queryAPI.findProfileByProviderId(cwf.provider.id()) if (profileList == None or len(profileList) == 0): failureResult['message'] = 'Invalid Provider - ' + str( cwf.provider.id()) return failureResult profile = profileList[0] cwf.paymentWF.prExpAmt = profile.feeStruc.regularFee cwf.paymentWF.plExpAmt = profile.feeStruc.platformFee # platformAPI.getPlatformFee(cwf) cwf.paymentWF.txExpAmt = 0 cwf.paymentWF.expCurr = profile.feeStruc.baseCurrency cwf.paymentWF.deriveTotalExpectedAmount() cwf.paymentWF.paymentStatus = 1 cwf.paymentWF.paymentStatusChain = [1] # create meetingWF and set the meeting type to consultation_mode_preference[phone, video or anything] cwf.meetingWF = subscriber.MeetingWF() cwf.meetingWF.meetingType = consultationModePreference # In-Progress cwf.overallStatus = 2 cwf.put() dispatcher.sendSMSToProvider(cref, 2) successResult[ 'message'] = 'Consultation request sent to Doctor. Waiting for his confirmation' successResult['reference'] = cwf.key.id() successResult['cwf'] = ndb_json.dumps(cwf) return successResult
def getDefaultSubscribers(): providerCursor = queryAPI.findDefaultProviders() return ndb_json.dumps(providerCursor)