Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
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
Beispiel #9
0
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)
Beispiel #10
0
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
Beispiel #11
0
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
Beispiel #12
0
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)
Beispiel #13
0
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)
Beispiel #14
0
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)
Beispiel #15
0
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)
Beispiel #16
0
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
Beispiel #17
0
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
Beispiel #18
0
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
Beispiel #19
0
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
Beispiel #20
0
def getDefaultSubscribers():
    providerCursor = queryAPI.findDefaultProviders()
    return ndb_json.dumps(providerCursor)
Beispiel #21
0
def getDefaultSubscribers():
	providerCursor = queryAPI.findDefaultProviders()
	return ndb_json.dumps(providerCursor)