def handlePrescriptionOnUpload(args): print 'todo - handle prescription on upload' cref = args['cref'] blobKey = args['blob_key'] failureResult = { 'result' : 'Failure', 'message' : '' } successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference in prescription upload - ' + str(cref) return failureResult if not cwf.fullfillmentWF: cwf.fullfillmentWF = subscriber.FulfillmentWF() cwf.fullfillmentWF.prescription_ref = blobKey cwf.fullfillmentWF.prescriptionTS = datetime.datetime.now() cwf.fullfillmentWF.fulfillmentStatus = 1 cwf.put() successResult['reference'] = cref 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 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 handlePrescriptionOnUpload(args): print 'todo - handle prescription on upload' cref = args['cref'] blobKey = args['blob_key'] failureResult = {'result': 'Failure', 'message': ''} successResult = {'result': 'Success', 'message': '', 'reference': ''} # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult[ 'message'] = 'Invalid CWF Reference in prescription upload - ' + str( cref) return failureResult if not cwf.fullfillmentWF: cwf.fullfillmentWF = subscriber.FulfillmentWF() cwf.fullfillmentWF.prescription_ref = blobKey cwf.fullfillmentWF.prescriptionTS = datetime.datetime.now() cwf.fullfillmentWF.fulfillmentStatus = 1 cwf.put() successResult['reference'] = cref return successResult
def changePatientInfo(args): # print 'todo - implement change patient info' # return { 'result' : 'Failure', 'message' : 'implementing change patient info shortly' } cref = args['cref']; patientName = args['patientName'] patientAge = args['patientAge'] patientSex = args['patientSex'] patientPhone = args['patientPhone'] consultationModePreference = args['consult_mode_pref'] 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 # allow the patient info change only before the meeting, not after the meeting if(cwf.meetingWF == None): failureResult['message'] = 'Invalid CWF/Meeting State '+str(cref) return failureResult if(cwf.patientDetailsWF == None): failureResult['message'] = 'Invalid CWF/PatientDetails State '+str(cref) return failureResult if(cwf.meetingWF.meetingStatus >= 3): failureResult['message'] = 'Cannot change patient details after the meeting '+str(cref) return failureResult if(cwf.overallStatus >= 3): failureResult['message'] = 'Cannot change patient details after the consultation is complete '+str(cref) return failureResult cwf.patientDetailsWF.patientName = patientName cwf.patientDetailsWF.patientAge = patientAge cwf.patientDetailsWF.patientSex = patientSex cwf.patientDetailsWF.patientPhone = patientPhone cwf.patientDetailsWF.answerText[0] = problemSummary cwf.meetingWF.meetingType = consultationModePreference cwf.put() return { 'result' : 'Success', 'message' : 'Patient info change completed ', 'cref' : cref }
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 forcePaymentComplete(args): cref = args['cref'] paidAmount = args['paidAmount'] paymentRef = args['paymentRef'] try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref to force payment - ' + str( cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult[ 'message'] = 'Invalid CWF Reference in force payment processing - ' + str( cref) return failureResult if not cwf.paymentWF: cwf.paymentWF = subscriber.PaymemtWF() cwf.paymentWF.totalPaidAmount = float(paidAmount) if not cwf.paymentWF.paymentConfirmToken: cwf.paymentWF.paymentConfirmToken = [paymentRef] else: cwf.paymentWF.paymentConfirmToken.append(paymentRef) if cwf.paymentWF.paymentConfirmTS: cwf.paymentWF.paymentConfirmTS.append(datetime.datetime.now()) else: cwf.paymentWF.paymentConfirmTS = [datetime.datetime.now()] # 3 = payment_successful, #4 = payment_rejected cwf.paymentWF.paymentStatus = 3 if cwf.paymentWF.paymentStatusChain: cwf.paymentWF.paymentStatusChain.append(cwf.paymentWF.paymentStatus) else: cwf.paymentWF.paymentStatusChain = [cwf.paymentWF.paymentStatus] cwf.put() return { 'result': 'Success', 'message': 'Payment force completed', 'cref': cref }
def getSubscriptionDocByBlobKey(cref, blobkey): failureResult = { 'result' : 'Failure', 'message' : '' } successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference in prescription upload - ' + str(cref) return failureResult return cwf.patientDetailsWF.getDocument(blobkey)
def doSendSMS2Provider(args): print "doSendSMS2Provider called with post", args cref = args['cref'] try: cwf = queryAPI.findConsultationWFById(cref) except: print "Error: doSendSMS2Provider: Invalid cref ", cref return {'result':'Failure'} providerId = cwf.provider.id() provider = queryAPI.findEntityByKey('Subscriber', providerId) if( provider == None): # raise Exception('Invalid provider with key', providerkey ); print "Error: doSendSMS2Provider: Invalid provider ", providerId return {'result':'Failure'} providerPhone = provider.phone[-1] taccount_sid = hmpconstants.TwilioSetup.account_sid taccount_auth = hmpconstants.TwilioSetup.auth_token # taccount_app = hmpconstants.TwilioSetup.application_sid client = TwilioRestClient(taccount_sid, taccount_auth) try: # find provider's timezone and convert appropriately. for now, hardcoded to IST requestedTimeInIndiaTZ = cwf.apptWF.requestedTS.replace(tzinfo=tzoffset("IST", +5*60*60)) # fmt1 = requestedTimeInIndiaTZ.strftime('%Y-%m-%d %H:%M:%S %Z') fmt2 = requestedTimeInIndiaTZ.strftime('%a, %b %d, %I:%M %p %Z') smsbody = "Appt request for "+str(fmt2)+". Accept or reschedule at remedysquare.com" print smsbody client.messages.create( to=providerPhone, from_=hmpconstants.TwilioSetup.hmp_owned_number_sms, body=smsbody ) print "twilio call to send sms completed" except: e = sys.exc_info()[0] print "Error: doSendSMS2Provider: problem sending it to Twilio ", cref, e traceback.print_exc(file=sys.stdout) return {'result':'Failure'} return {'result':'Success'}
def doSendSMS2User(args): print "doSendSMS2User called with post", args cref = args['cref'] apptWFStateCd = args['apptWFStateCd'] try: cwf = queryAPI.findConsultationWFById(cref) except: print "Error: doSendSMS2User: Invalid cref ", cref return {'result':'Failure'} taccount_sid = hmpconstants.TwilioSetup.account_sid taccount_auth = hmpconstants.TwilioSetup.auth_token # taccount_app = hmpconstants.TwilioSetup.application_sid client = TwilioRestClient(taccount_sid, taccount_auth) try: # find user's timezone and convert appropriately. for now, hardcoded to IST confirmedTimeInIndiaTZ = cwf.apptWF.confirmedTS.replace(tzinfo=tzoffset("IST", 5*60*60)) userPhone = cwf.patientDetailsWF.patientPhone providerName = cwf.providerName fmt2 = confirmedTimeInIndiaTZ.strftime('%a, %b %d, %I:%M %p %Z') if(apptWFStateCd == 3): smsbody = "Dr "+str(providerName)+" @remedysquare.com has confirmed your appointment at "+str(fmt2)+" " elif(apptWFStateCd == 5): smsbody = "Dr "+str(providerName)+" @remedysquare.com has rescheduled your appointment at "+str(fmt2)+". Go to remedysquare.com to confirm or further reschedule " print smsbody client.messages.create( to=userPhone, from_=hmpconstants.TwilioSetup.hmp_owned_number_sms, body=smsbody ) print "twilio call to send user sms completed" except: e = sys.exc_info()[0] print "Error: doSendSMS2User: problem sending it to Twilio ", cref, e traceback.print_exc(file=sys.stdout) return {'result':'Failure'} return {'result':'Success'}
def getSubscriptionDocByBlobKey(cref, blobkey): failureResult = {'result': 'Failure', 'message': ''} successResult = {'result': 'Success', 'message': '', 'reference': ''} # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult[ 'message'] = 'Invalid CWF Reference in prescription upload - ' + str( cref) return failureResult return cwf.patientDetailsWF.getDocument(blobkey)
def forcePaymentComplete(args): cref = args['cref']; paidAmount = args['paidAmount'] paymentRef = args['paymentRef'] try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref to force payment - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference in force payment processing - ' + str(cref) return failureResult if not cwf.paymentWF: cwf.paymentWF = subscriber.PaymemtWF() cwf.paymentWF.totalPaidAmount = float(paidAmount) if not cwf.paymentWF.paymentConfirmToken: cwf.paymentWF.paymentConfirmToken = [paymentRef] else: cwf.paymentWF.paymentConfirmToken.append(paymentRef) if cwf.paymentWF.paymentConfirmTS: cwf.paymentWF.paymentConfirmTS.append( datetime.datetime.now() ) else: cwf.paymentWF.paymentConfirmTS = [datetime.datetime.now()] # 3 = payment_successful, #4 = payment_rejected cwf.paymentWF.paymentStatus = 3 if cwf.paymentWF.paymentStatusChain: cwf.paymentWF.paymentStatusChain.append( cwf.paymentWF.paymentStatus ) else: cwf.paymentWF.paymentStatusChain = [cwf.paymentWF.paymentStatus] cwf.put() return { 'result' : 'Success', 'message' : 'Payment force completed', 'cref' : cref }
def handleSubscriberDocumentOnUpload(args): print 'handle subscriber on upload', args cref = args['cref'] blobKey = args['blob_key'] documentNo = args['documentNo'] filename = args['filename'] filesummary = args['filesummary'] failureResult = {'result': 'Failure', 'message': ''} successResult = {'result': 'Success', 'message': '', 'reference': ''} # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult[ 'message'] = 'Invalid CWF Reference in prescription upload - ' + str( cref) return failureResult patientDocument = subscriber.SubscriberDoc() patientDocument.fileBlobKey = blobKey patientDocument.fileName = filename patientDocument.fileSummary = filesummary if not cwf.patientDetailsWF.patientDocuments: cwf.patientDetailsWF.patientDocuments = [patientDocument] else: cwf.patientDetailsWF.patientDocuments.append(patientDocument) cwf.put() successResult['reference'] = cref return successResult
def handleSubscriberDocumentOnUpload(args): print 'handle subscriber on upload', args cref = args['cref'] blobKey = args['blob_key'] documentNo = args['documentNo'] filename = args['filename'] filesummary = args['filesummary'] failureResult = { 'result' : 'Failure', 'message' : '' } successResult = {'result' : 'Success', 'message' : '','reference':'' } # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference in prescription upload - ' + str(cref) return failureResult patientDocument = subscriber.SubscriberDoc() patientDocument.fileBlobKey = blobKey patientDocument.fileName = filename patientDocument.fileSummary = filesummary if not cwf.patientDetailsWF.patientDocuments: cwf.patientDetailsWF.patientDocuments = [patientDocument] else: cwf.patientDetailsWF.patientDocuments.append(patientDocument) cwf.put() successResult['reference'] = cref return successResult
def applyPaymentCoupon(args): cref = args['cref']; couponCode = args['couponCode'] failureResult = { 'result' : 'Failure', 'message' : '' } try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref. Unable to apply coupon. ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference. Cannot apply coupon - ' + str(cref) return failureResult # for now, I am hardcoding the payment to be completed on any coupon value, but... # todo - first fetch the coupon object # check that the coupon is valid and has not expired # also fetch what is the value of the coupon # now subtract the expected money with the coupon value # if the expected money is now zero or less than zero, update the # payment status as successful and return appropriate response # so that the browser can take the user past the payment page # couponObj = subscriber.PaymentCouponStruc() couponObj.couponProvider = "RemedySquare" couponObj.couponCode = "PRE-LAUNCH" couponObj.couponValue = 500.0 until30Days = datetime.timedelta(days=30) couponObj.couponValidUntil = datetime.datetime.now() + until30Days if not couponCode=='PRE-LAUNCH': failureResult['message'] = 'Invalid Coupon Code. Cannot apply coupon - ' + str(couponCode) return failureResult if not cwf.paymentWF: cwf.paymentWF = subscriber.PaymemtWF() adjustedExpectedAmount = cwf.paymentWF.applyCoupon(couponObj) # check the expected amount now, after applying coupon if(adjustedExpectedAmount > 0.0): pass else: cwf.paymentWF.paymentProviderId = hmpconstants.PaymentProvider.REMEDY_SQUARE cwf.paymentWF.totalPaidAmount = 0.0 if not cwf.paymentWF.paymentConfirmToken: cwf.paymentWF.paymentConfirmToken = [couponObj.couponCode] else: cwf.paymentWF.paymentConfirmToken.append(couponObj.couponCode) if cwf.paymentWF.paymentConfirmTS: cwf.paymentWF.paymentConfirmTS.append( datetime.datetime.now() ) else: cwf.paymentWF.paymentConfirmTS = [datetime.datetime.now()] # 3 = payment_successful, #4 = payment_rejected cwf.paymentWF.paymentStatus = 3 if cwf.paymentWF.paymentStatusChain: cwf.paymentWF.paymentStatusChain.append( cwf.paymentWF.paymentStatus ) else: cwf.paymentWF.paymentStatusChain = [cwf.paymentWF.paymentStatus] cwf.put() return { 'result' : 'Success', 'message' : 'Coupon applied', 'cref' : cref, 'expected_payment' : cwf.paymentWF.ttlExpAmt }
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_updatePayment(args): # secretWord = 'MjRiZmYxZjQtZjcwZi00NDE3LWIzOWEtODUwMGFmOWFkYWJj' secretWord = 'MDdlOWJlZmYtOTUzMS00OTRhLTgzOGMtYmIzZDFiMzlkZjU1' # accountNo = '901274976' accountNo = '901307406' key = args['key'] order_number = args['order_number'] demo_order_no = '1' invoice_id = args['invoice_id'] paymentProcessed = args['credit_card_processed'] total = args['total'] cref = args['li_0_product_id'] m = hashlib.md5() m.update(secretWord) m.update(accountNo) # change it to use actual order number m.update(demo_order_no) m.update(total) # calculatedKey = m.digest() calculatedKey2 = m.hexdigest().upper() print 'payment key', key, 'calculatedKey as digest', calculatedKey2 failureResult = {'result': 'Failure', 'message': ''} successResult = {'result': 'Success', 'message': '', 'reference': ''} if (key != calculatedKey2): failureResult['message'] = 'Invalid payment update for cref ' + str( cref) + ', order no ' + str(order_number) + ', invoice_id ' + str( invoice_id) return failureResult # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult[ 'message'] = 'Invalid Cref on receiving payment confirmation - ' + str( cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult[ 'message'] = 'Invalid CWF Reference in payment processing handback - ' + str( cref) return failureResult if not cwf.paymentWF: cwf.paymentWF = subscriber.PaymemtWF() cwf.paymentWF.totalPaidAmount = float(total) if not cwf.paymentWF.paymentConfirmToken: cwf.paymentWF.paymentConfirmToken = [invoice_id] else: cwf.paymentWF.paymentConfirmToken.append(invoice_id) if cwf.paymentWF.paymentConfirmTS: cwf.paymentWF.paymentConfirmTS.append(datetime.datetime.now()) else: cwf.paymentWF.paymentConfirmTS = [datetime.datetime.now()] # 3 = payment_successful, #4 = payment_rejected cwf.paymentWF.paymentStatus = 3 if paymentProcessed == 'Y' else 4 paymentProcessed if cwf.paymentWF.paymentStatusChain: cwf.paymentWF.paymentStatusChain.append(cwf.paymentWF.paymentStatus) else: cwf.paymentWF.paymentStatusChain = [cwf.paymentWF.paymentStatus] cwf.put() successResult = { 'result': 'Success', 'message': 'Payment Processed Recorded', 'reference': cref } 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 consultWF_updatePayment(args): # secretWord = 'MjRiZmYxZjQtZjcwZi00NDE3LWIzOWEtODUwMGFmOWFkYWJj' secretWord = 'MDdlOWJlZmYtOTUzMS00OTRhLTgzOGMtYmIzZDFiMzlkZjU1' # accountNo = '901274976' accountNo = '901307406' key = args['key'] order_number = args['order_number'] demo_order_no = '1' invoice_id = args['invoice_id'] paymentProcessed = args['credit_card_processed'] total = args['total'] cref = args['li_0_product_id'] m = hashlib.md5() m.update(secretWord) m.update(accountNo) # change it to use actual order number m.update(demo_order_no) m.update(total) # calculatedKey = m.digest() calculatedKey2 = m.hexdigest().upper() print 'payment key', key, 'calculatedKey as digest', calculatedKey2 failureResult = { 'result' : 'Failure', 'message' : '' } successResult = {'result' : 'Success', 'message' : '','reference':'' } if(key != calculatedKey2): failureResult['message'] = 'Invalid payment update for cref ' + str(cref) +', order no '+ str(order_number)+ ', invoice_id '+ str(invoice_id) return failureResult # try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult['message'] = 'Invalid Cref on receiving payment confirmation - ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult['message'] = 'Invalid CWF Reference in payment processing handback - ' + str(cref) return failureResult if not cwf.paymentWF: cwf.paymentWF = subscriber.PaymemtWF() cwf.paymentWF.totalPaidAmount = float(total) if not cwf.paymentWF.paymentConfirmToken: cwf.paymentWF.paymentConfirmToken = [invoice_id] else: cwf.paymentWF.paymentConfirmToken.append(invoice_id) if cwf.paymentWF.paymentConfirmTS: cwf.paymentWF.paymentConfirmTS.append( datetime.datetime.now() ) else: cwf.paymentWF.paymentConfirmTS = [datetime.datetime.now()] # 3 = payment_successful, #4 = payment_rejected cwf.paymentWF.paymentStatus = 3 if paymentProcessed == 'Y' else 4 paymentProcessed if cwf.paymentWF.paymentStatusChain: cwf.paymentWF.paymentStatusChain.append( cwf.paymentWF.paymentStatus ) else: cwf.paymentWF.paymentStatusChain = [cwf.paymentWF.paymentStatus] cwf.put() successResult = {'result' : 'Success', 'message' : 'Payment Processed Recorded','reference': cref } 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 changePatientInfo(args): # print 'todo - implement change patient info' # return { 'result' : 'Failure', 'message' : 'implementing change patient info shortly' } cref = args['cref'] patientName = args['patientName'] patientAge = args['patientAge'] patientSex = args['patientSex'] patientPhone = args['patientPhone'] consultationModePreference = args['consult_mode_pref'] 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 # allow the patient info change only before the meeting, not after the meeting if (cwf.meetingWF == None): failureResult['message'] = 'Invalid CWF/Meeting State ' + str(cref) return failureResult if (cwf.patientDetailsWF == None): failureResult['message'] = 'Invalid CWF/PatientDetails State ' + str( cref) return failureResult if (cwf.meetingWF.meetingStatus >= 3): failureResult[ 'message'] = 'Cannot change patient details after the meeting ' + str( cref) return failureResult if (cwf.overallStatus >= 3): failureResult[ 'message'] = 'Cannot change patient details after the consultation is complete ' + str( cref) return failureResult cwf.patientDetailsWF.patientName = patientName cwf.patientDetailsWF.patientAge = patientAge cwf.patientDetailsWF.patientSex = patientSex cwf.patientDetailsWF.patientPhone = patientPhone cwf.patientDetailsWF.answerText[0] = problemSummary cwf.meetingWF.meetingType = consultationModePreference cwf.put() return { 'result': 'Success', 'message': 'Patient info change completed ', 'cref': cref }
def applyPaymentCoupon(args): cref = args['cref'] couponCode = args['couponCode'] failureResult = {'result': 'Failure', 'message': ''} try: cwf = queryAPI.findConsultationWFById(int(cref)) except: failureResult[ 'message'] = 'Invalid Cref. Unable to apply coupon. ' + str(cref) # todo - log the payment handback errors return failureResult if (cwf == None): failureResult[ 'message'] = 'Invalid CWF Reference. Cannot apply coupon - ' + str( cref) return failureResult # for now, I am hardcoding the payment to be completed on any coupon value, but... # todo - first fetch the coupon object # check that the coupon is valid and has not expired # also fetch what is the value of the coupon # now subtract the expected money with the coupon value # if the expected money is now zero or less than zero, update the # payment status as successful and return appropriate response # so that the browser can take the user past the payment page # couponObj = subscriber.PaymentCouponStruc() couponObj.couponProvider = "RemedySquare" couponObj.couponCode = "PRE-LAUNCH" couponObj.couponValue = 500.0 until30Days = datetime.timedelta(days=30) couponObj.couponValidUntil = datetime.datetime.now() + until30Days if not couponCode == 'PRE-LAUNCH': failureResult[ 'message'] = 'Invalid Coupon Code. Cannot apply coupon - ' + str( couponCode) return failureResult if not cwf.paymentWF: cwf.paymentWF = subscriber.PaymemtWF() adjustedExpectedAmount = cwf.paymentWF.applyCoupon(couponObj) # check the expected amount now, after applying coupon if (adjustedExpectedAmount > 0.0): pass else: cwf.paymentWF.paymentProviderId = hmpconstants.PaymentProvider.REMEDY_SQUARE cwf.paymentWF.totalPaidAmount = 0.0 if not cwf.paymentWF.paymentConfirmToken: cwf.paymentWF.paymentConfirmToken = [couponObj.couponCode] else: cwf.paymentWF.paymentConfirmToken.append(couponObj.couponCode) if cwf.paymentWF.paymentConfirmTS: cwf.paymentWF.paymentConfirmTS.append(datetime.datetime.now()) else: cwf.paymentWF.paymentConfirmTS = [datetime.datetime.now()] # 3 = payment_successful, #4 = payment_rejected cwf.paymentWF.paymentStatus = 3 if cwf.paymentWF.paymentStatusChain: cwf.paymentWF.paymentStatusChain.append( cwf.paymentWF.paymentStatus) else: cwf.paymentWF.paymentStatusChain = [cwf.paymentWF.paymentStatus] cwf.put() return { 'result': 'Success', 'message': 'Coupon applied', 'cref': cref, 'expected_payment': cwf.paymentWF.ttlExpAmt }