Example #1
0
def notify_to_do():
	profile_ids = get_profile_ids()
	print "########## TODO #############"
	print profile_ids
	if profile_ids:
		msg={}
		email_msg={}
		for profile in profile_ids:
			user = frappe.db.get_value("User",{"profile_id":profile['profile_id']},"name")
			todoobj = frappe.get_doc('ToDo',profile['name'])
			msgg = get_sms_template("todo",{"to_do":todoobj.description})
			if user:
				pobj = frappe.get_doc('User',user)
				send_phr_sms(pobj.contact,msg=msgg)
				send_phrs_mail(pobj.name,"PHR:To Do Alert","templates/emails/todo.html",{"todo":todoobj.description,"name":pobj.first_name})
			else:
				data = search_profile_data_from_solr(profile['profile_id'])
				
				if data:
					child = data['childProfile']
					
					if child['mobile'] and frappe.db.get_value("Mobile Verification",{"mobile_no":child['mobile'],"mflag":1},"name"):
						send_phr_sms(child['mobile'],msg=msgg)
					else:
						parent = data['parentProfile']
						send_phr_sms(parent['mobile'],msg=msgg)
					
					if child['email']:
						send_phrs_mail(child['email'],"PHR:To Do Alert","templates/emails/todo.html",{"todo":todoobj.description,"name":data["person_firstname"]})
					else:
						send_phrs_mail(parent['email'],"PHR:To Do Alert","templates/emails/todo.html",{"todo":todoobj.description,"name":data["person_firstname"]})	
Example #2
0
def add_profile_to_db(data,profile_id):
	res = json.loads(data)
	actdata = res['actualdata']		
	dt = json.loads(actdata)
	sub = dt['person_firstname']+" "+dt['person_lastname']+" "+"delinked Successfully"
	make_log(profile_id,"profile","delink",sub)
	args = {'person_firstname':dt['person_firstname'],'person_middlename':dt['person_middlename'],'person_lastname':dt['person_lastname'],'email':dt['email'],'mobile':dt['mobile'],'received_from':'Desktop','provider':'false'}
	
	cie = frappe.db.get_value("LinkedPHR Images",{"profile_id":res['entityid']}, ["barcode", "profile_image"], as_dict=1)

	path = ""
	if cie.get('barcode'):
		path = cie.get('barcode')
	else:
		path = ""

	if cie.get('profile_image'):
		args['user_image'] = cie.get('profile_image')
	else:
		args['user_image']= ""

	ret_res = create_profile_in_db(res['entityid'],args,res,path)
	user = frappe.get_doc("User",frappe.session.user)
	send_phrs_mail(user.email,"PHR:Linked PHR Account Delinked","templates/emails/delink_phr.html",{"name":args['person_firstname']})
	msg = get_sms_template("delink",{"phr_name":args['person_firstname']})
	if user.contact:
		rec_list = []
		rec_list.append(user.contact)
		send_sms(rec_list,msg=msg)
	sub = dt['person_firstname']+" "+dt['person_lastname']+" "+"Profile Created Successfully"
	make_log(profile_id,"profile","create",sub)
	return ret_res
Example #3
0
def send_notification(profile_list):
    print "##########Appointments#############"
    print profile_list
    msg = {}
    for profile in profile_list:
        user = frappe.db.get_value("User",
                                   {"profile_id": profile['profile_id']},
                                   "name")
        msgg = get_sms_template(
            "appointments", {
                "doctor_name": profile['provider_name'],
                "appointment_time": profile['time']
            })
        if user:
            pobj = frappe.get_doc('User', user)
            send_phr_sms(pobj.contact, msg=msgg)
        else:
            data = search_profile_data_from_solr(profile['profile_id'])
            if data:
                child = data['childProfile']
                parent = data['parentProfile']
                if child['mobile'] and frappe.db.get_value(
                        "Mobile Verification", {
                            "mobile_no": child['mobile'],
                            "mflag": 1
                        }, "name"):
                    send_phr_sms(child['mobile'], msg=msgg)
                else:
                    send_phr_sms(parent['mobile'], msg=msgg)
Example #4
0
def send_welcome_mail(password,profile_id,args, send_sms=True, is_provider=False):
	from frappe.utils import random_string, get_url
	key = random_string(32)
	db_set(args,"reset_password_key", key)
	link = get_url("/verify_email?id="+profile_id+"&key=" + key)

	mob_code = get_mob_code()
	update_verification_details(args,password,key,mob_code,link,profile_id, is_provider)
	mail_response = send_login_mail(args,"Verify Your Account", "templates/emails/new_user.html", {"link": link,"password":password,"verify_sms":send_sms})

	if send_sms:
		mob_already_v = frappe.db.get_value("Mobile Verification",{"mobile_no":args["mobile"],"mflag":1},"name")
		if not mob_already_v:
			from phr.templates.pages.profile import make_mobile_verification_entry
			if not frappe.db.get_value("Mobile Verification",{"mobile_no":args["mobile"]},"name"):
				make_mobile_verification_entry(args["mobile"],profile_id,mob_code)
			else:
				pass

			from phr.templates.pages.utils import get_sms_template
			sms = get_sms_template("registration",{ "mobile_code": mob_code })
			rec_list = []
			rec_list.append(args["mobile"])
			from erpnext.setup.doctype.sms_settings.sms_settings import send_sms
			send_sms(rec_list,sms)
		elif mob_already_v:
			vd = frappe.get_doc("Verification Details",profile_id)
			vd.mflag = 1
			vd.save(ignore_permissions=True)

	return mail_response
Example #5
0
def send_mobile_v_code(mobile,profile_id,mobile_code=None):
	if mobile_code:
		from phr.templates.pages.utils import get_sms_template
		sms = get_sms_template("registration",{ "mobile_code": mobile_code })
		rec_list = []
		rec_list.append(mobile)
		from erpnext.setup.doctype.sms_settings.sms_settings import send_sms
		send_sms(rec_list,sms)
		return "done"
Example #6
0
def send_mobile_v_code(mobile, profile_id, mobile_code=None):
    if mobile_code:
        from phr.templates.pages.utils import get_sms_template
        sms = get_sms_template("registration", {"mobile_code": mobile_code})
        rec_list = []
        rec_list.append(mobile)
        from erpnext.setup.doctype.sms_settings.sms_settings import send_sms
        send_sms(rec_list, sms)
        return "done"
Example #7
0
def notify_to_do():
    profile_ids = get_profile_ids()
    print "########## TODO #############"
    print profile_ids
    if profile_ids:
        msg = {}
        email_msg = {}
        for profile in profile_ids:
            user = frappe.db.get_value("User",
                                       {"profile_id": profile['profile_id']},
                                       "name")
            todoobj = frappe.get_doc('ToDo', profile['name'])
            msgg = get_sms_template("todo", {"to_do": todoobj.description})
            if user:
                pobj = frappe.get_doc('User', user)
                send_phr_sms(pobj.contact, msg=msgg)
                send_phrs_mail(pobj.name, "PHR:To Do Alert",
                               "templates/emails/todo.html", {
                                   "todo": todoobj.description,
                                   "name": pobj.first_name
                               })
            else:
                data = search_profile_data_from_solr(profile['profile_id'])

                if data:
                    child = data['childProfile']

                    if child['mobile'] and frappe.db.get_value(
                            "Mobile Verification", {
                                "mobile_no": child['mobile'],
                                "mflag": 1
                            }, "name"):
                        send_phr_sms(child['mobile'], msg=msgg)
                    else:
                        parent = data['parentProfile']
                        send_phr_sms(parent['mobile'], msg=msgg)

                    if child['email']:
                        send_phrs_mail(
                            child['email'], "PHR:To Do Alert",
                            "templates/emails/todo.html", {
                                "todo": todoobj.description,
                                "name": data["person_firstname"]
                            })
                    else:
                        send_phrs_mail(
                            parent['email'], "PHR:To Do Alert",
                            "templates/emails/todo.html", {
                                "todo": todoobj.description,
                                "name": data["person_firstname"]
                            })
Example #8
0
def add_profile_to_db(data, profile_id):
    res = json.loads(data)
    actdata = res['actualdata']
    dt = json.loads(actdata)
    sub = dt['person_firstname'] + " " + dt[
        'person_lastname'] + " " + "delinked Successfully"
    make_log(profile_id, "profile", "delink", sub)
    args = {
        'person_firstname': dt['person_firstname'],
        'person_middlename': dt['person_middlename'],
        'person_lastname': dt['person_lastname'],
        'email': dt['email'],
        'mobile': dt['mobile'],
        'received_from': 'Desktop',
        'provider': 'false'
    }

    cie = frappe.db.get_value("LinkedPHR Images",
                              {"profile_id": res['entityid']},
                              ["barcode", "profile_image"],
                              as_dict=1)

    path = ""
    if cie.get('barcode'):
        path = cie.get('barcode')
    else:
        path = ""

    if cie.get('profile_image'):
        args['user_image'] = cie.get('profile_image')
    else:
        args['user_image'] = ""

    ret_res = create_profile_in_db(res['entityid'], args, res, path)
    user = frappe.get_doc("User", frappe.session.user)
    send_phrs_mail(user.email, "PHR:Linked PHR Account Delinked",
                   "templates/emails/delink_phr.html",
                   {"name": args['person_firstname']})
    msg = get_sms_template("delink", {"phr_name": args['person_firstname']})
    if user.contact:
        rec_list = []
        rec_list.append(user.contact)
        send_sms(rec_list, msg=msg)
    sub = dt['person_firstname'] + " " + dt[
        'person_lastname'] + " " + "Profile Created Successfully"
    make_log(profile_id, "profile", "create", sub)
    return ret_res
Example #9
0
def notify_provider(provider_id,patient,template,args,email_msg=None):
	provider_info = frappe.db.get_value("Provider",{"provider_id":provider_id},"name")
	if provider_info:
		provider = frappe.get_doc("Provider",provider_info)
		if provider.mobile_number:
			from phr.templates.pages.utils import get_sms_template
			msg = get_sms_template(template,args)
			recipient_list = []
			recipient_list.append(provider.mobile_number)
			from erpnext.setup.doctype.sms_settings.sms_settings import send_sms
			send_sms(recipient_list,msg=msg)

		if provider.email and email_msg:
			from frappe.utils.email_lib import sendmail
			sendmail(provider.email, subject="HealthSnapp Updates:Data Shared With You", msg=email_msg)
			
		return "done"
Example #10
0
def send_welcome_mail(password,
                      profile_id,
                      args,
                      send_sms=True,
                      is_provider=False):
    from frappe.utils import random_string, get_url
    key = random_string(32)
    db_set(args, "reset_password_key", key)
    link = get_url("/verify_email?id=" + profile_id + "&key=" + key)

    mob_code = get_mob_code()
    update_verification_details(args, password, key, mob_code, link,
                                profile_id, is_provider)
    mail_response = send_login_mail(args, "Verify Your Account",
                                    "templates/emails/new_user.html", {
                                        "link": link,
                                        "password": password,
                                        "verify_sms": send_sms
                                    })

    if send_sms:
        mob_already_v = frappe.db.get_value("Mobile Verification", {
            "mobile_no": args["mobile"],
            "mflag": 1
        }, "name")
        if not mob_already_v:
            from phr.templates.pages.profile import make_mobile_verification_entry
            if not frappe.db.get_value("Mobile Verification",
                                       {"mobile_no": args["mobile"]}, "name"):
                make_mobile_verification_entry(args["mobile"], profile_id,
                                               mob_code)
            else:
                pass

            from phr.templates.pages.utils import get_sms_template
            sms = get_sms_template("registration", {"mobile_code": mob_code})
            rec_list = []
            rec_list.append(args["mobile"])
            from erpnext.setup.doctype.sms_settings.sms_settings import send_sms
            send_sms(rec_list, sms)
        elif mob_already_v:
            vd = frappe.get_doc("Verification Details", profile_id)
            vd.mflag = 1
            vd.save(ignore_permissions=True)

    return mail_response
Example #11
0
def send_notification(profile_list):
	print "##########Appointments#############"
	print profile_list
	msg={}
	for profile in profile_list:
		user = frappe.db.get_value("User",{"profile_id":profile['profile_id']},"name")
		msgg = get_sms_template("appointments",{"doctor_name":profile['provider_name'],"appointment_time":profile['time']})
		if user:
			pobj = frappe.get_doc('User',user)
			send_phr_sms(pobj.contact,msg=msgg)
		else:
			data = search_profile_data_from_solr(profile['profile_id'])
			if data:
				child = data['childProfile']
				parent = data['parentProfile']
				if child['mobile'] and frappe.db.get_value("Mobile Verification",{"mobile_no":child['mobile'],"mflag":1},"name"):
					send_phr_sms(child['mobile'],msg=msgg)
				else:
					send_phr_sms(parent['mobile'],msg=msgg)		
Example #12
0
def notify_provider(provider_id, patient, template, args, email_msg=None):
    provider_info = frappe.db.get_value("Provider",
                                        {"provider_id": provider_id}, "name")
    if provider_info:
        provider = frappe.get_doc("Provider", provider_info)
        if provider.mobile_number:
            from phr.templates.pages.utils import get_sms_template
            msg = get_sms_template(template, args)
            recipient_list = []
            recipient_list.append(provider.mobile_number)
            from erpnext.setup.doctype.sms_settings.sms_settings import send_sms
            send_sms(recipient_list, msg=msg)

        if provider.email and email_msg:
            from frappe.utils.email_lib import sendmail
            sendmail(provider.email,
                     subject="HealthSnapp Updates:Data Shared With You",
                     msg=email_msg)

        return "done"
Example #13
0
def fetch_data_from_medications(med_list, recipient_list):
    if med_list:
        msg = {}
        for md in med_list:
            sms_send = True
            mobj = frappe.get_doc("Medication", md)
            week = [
                'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
                'Saturday', 'Sunday'
            ]
            import datetime
            now_day = datetime.datetime.today().weekday()
            fobj = frappe.get_doc("Dosage", mobj.dosage)
            options = json.loads(mobj.options)

            if mobj.dosage == "Weekly":
                if options['day'] != week[now_day]:
                    sms_send = False

            if sms_send:
                for d in fobj.get('dosage_fields'):
                    time_diff = 0
                    if d.fieldtype == "time":
                        time_now = datetime.datetime.strftime(
                            datetime.datetime.now(), '%H:%M')
                        if options.get(d.fieldname):
                            med_time = datetime.datetime.strptime(
                                options[d.fieldname],
                                '%I:%M %p').strftime('%H:%M')
                            time_diff = cint(
                                (datetime.datetime.strptime(time_now, '%H:%M')
                                 - datetime.datetime.strptime(
                                     med_time, '%H:%M')).total_seconds() / 60)

                    elif d.fieldname == "datetime":
                        now_time = datetime.datetime.strftime(
                            datetime.datetime.now(), '%Y-%m-%d %H:%M:%S.%f')
                        now_time_str = datetime.datetime.strptime(
                            now_time, '%Y-%m-%d %H:%M:%S.%f')
                        if options.get(d.fieldname):
                            med_time = datetime.datetime.strptime(
                                options[d.fieldname], '%Y-%m-%d %H:%M:%S.%f')
                            time_diff = cint(
                                (now_time - med_time).total_seconds() / 60)

                    if time_diff and (time_diff >= 0 and time_diff <= 5):
                        uexists = frappe.db.get_value(
                            "User", {"profile_id": mobj.profile_id}, "name")
                        msgg = get_sms_template(
                            "medication",
                            {"medication": mobj.get('medicine_name')})
                        if uexists:
                            user = frappe.get_doc("User", uexists)
                            send_phr_sms(user.contact, msg=msgg)
                        else:
                            data = search_profile_data_from_solr(
                                mobj.profile_id)
                            if data:
                                child = data['childProfile']
                                if child['mobile'] and frappe.db.get_value(
                                        "Mobile Verification", {
                                            "mobile_no": child['mobile'],
                                            "mflag": 1
                                        }, "name"):
                                    send_phr_sms(child['mobile'], msg=msgg)
                                else:
                                    parent = data['parentProfile']
                                    send_phr_sms(parent['mobile'], msg=msgg)
        return "done"
Example #14
0
def check_templates(profile_id):
	msg = get_sms_template("appointments",{"doctor_name":"ahahha","appointment_time":"4.25"})
Example #15
0
def check_templates(profile_id):
    msg = get_sms_template("appointments", {
        "doctor_name": "ahahha",
        "appointment_time": "4.25"
    })
Example #16
0
def send_adv_sms(adv):
	sms = get_sms_template("Advertisement Notification", adv)
	send_sms(adv.get("notify_to"),sms)