Exemple #1
0
def create_profile_solr(data):
    request_type = "POST"
    url = "%s/createProfile" % get_base_url()
    args = json.loads(data)
    if args['mobile'] and not not_duplicate_contact(args['mobile']):
        return {"message_summary": "Contact Already Registered"}

    barcode = get_barcode()
    args["barcode"] = str(barcode)
    data = json.dumps(args)
    from phr.phr.phr_api import get_response
    response = get_response(url, data, request_type)
    res = json.loads(response.text)
    if res and res.get('returncode') == 101:
        data = json.loads(data)
        path = get_image_path(barcode, res['entityid'])
        from phr.templates.pages.login import set_default_dashboard
        set_default_dashboard(res['entityid'])
        args = {
            "entityid": res.get('entityid'),
            "linking_id": data["linking_id"],
            "relationship": data["relationship"],
            "received_from": "Desktop"
        }
        request_type = "POST"
        url = "%s/linkprofile" % get_base_url()
        from phr.phr.phr_api import get_response
        response = get_response(url, json.dumps(args), request_type)
        res = json.loads(response.text)
        update_lphr_barcode(path, res.get('entityid'))
        return res
Exemple #2
0
def create_profile_solr(data):
    print data
    request_type = "POST"
    url = "%s/createProfile" % get_base_url()
    barcode = get_barcode()
    args = json.loads(data)
    args["barcode"] = str(barcode)
    data = json.dumps(args)
    from phr.phr.phr_api import get_response
    response = get_response(url, data, request_type)
    res = json.loads(response.text)
    print res
    if res and res.get('returncode') == 101:
        data = json.loads(data)
        path = get_image_path(barcode, res['entityid'])
        print "============================="
        print data
        args = {
            "entityid": res.get('entityid'),
            "linking_id": data["linking_id"],
            "relationship": data["relationship"],
            "received_from": "Desktop"
        }
        request_type = "POST"
        url = "%s/linkprofile" % get_base_url()
        from phr.phr.phr_api import get_response
        response = get_response(url, json.dumps(args), request_type)
        res = json.loads(response.text)
        update_lphr_barcode(path, res.get('entityid'))
        return res
Exemple #3
0
def create_profile_solr(data):
	request_type = "POST"
	url = "%s/createProfile"%get_base_url()
	args = json.loads(data)
	
	if args['mobile'] and not not_duplicate_contact(args['mobile']):
		return {"message_summary":"Contact Already Registered"}

	barcode = get_barcode()
	args["barcode"]=str(barcode)
	data=json.dumps(args)
	from phr.phr.phr_api import get_response
	response=get_response(url,data,request_type)
	res=json.loads(response.text)
	if res and res.get('returncode')==101:
		data = json.loads(data)
		path = get_image_path(barcode,res['entityid'])
		from phr.templates.pages.login import set_default_dashboard
		set_default_dashboard(res['entityid'])		
		args = {"entityid":res.get('entityid'),"linking_id":data["linking_id"],"relationship":data["relationship"],"received_from":"Desktop"}
		request_type="POST"
		url = "%s/linkprofile"%get_base_url()
		from phr.phr.phr_api import get_response
		response = get_response(url,json.dumps(args),request_type)
		res = json.loads(response.text)
		update_lphr_barcode(path,res.get('entityid'))
		return res
Exemple #4
0
def execute():
	for user in frappe.db.sql("""select name, profile_id from tabUser 
			where barcode is null 
				and access_type in ('Patient', 'Provider')""",as_dict=1):

		barcode = get_barcode()
		path = get_image_path(barcode, user['profile_id'])
		file_path = os.path.join('files', user['profile_id'], user['profile_id']+".svg")
		
		curr_user = frappe.get_doc('User', user['name'])
		curr_user.barcode = file_path
		curr_user.save(ignore_permissions=True)
Exemple #5
0
def execute():
    for user in frappe.db.sql("""select name, profile_id from tabUser 
			where barcode is null 
				and access_type in ('Patient', 'Provider')""",
                              as_dict=1):

        barcode = get_barcode()
        path = get_image_path(barcode, user['profile_id'])
        file_path = os.path.join('files', user['profile_id'],
                                 user['profile_id'] + ".svg")

        curr_user = frappe.get_doc('User', user['name'])
        curr_user.barcode = file_path
        curr_user.save(ignore_permissions=True)
Exemple #6
0
def delink_phr_solr(data, id, profile_id):
    solr_op = 'unlinkProfile'
    url = get_base_url() + solr_op
    request_type = 'POST'
    barcode = get_barcode()
    #jsonobj=json.loads(data)
    data["recieved_from"] = "Desktop"
    #data["barcode"]=str(barcode)
    jsonobj = {
        "entityid": id,
        "linking_id": profile_id,
        "received_from": "Desktop"
    }
    from phr.phr.phr_api import get_response
    response = get_response(url, json.dumps(jsonobj), request_type)
    res = json.loads(response.text)
    print res
    if res['returncode'] == 121:
        path = get_image_path(barcode, res['entityid'])
        print res
        sub = res['entityid'] + "delinked Successfully"
        make_log(profile_id, "profile", "delink", sub)
        actdata = res['actualdata']
        dt = json.loads(actdata)
        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',
            'barcode': str(barcode)
        }
        ret_res = create_profile_in_db(res['entityid'], args, res, path)
        return ret_res
Exemple #7
0
def update_oauth_user(user, data, provider):
	if isinstance(data.get("location"), dict):
		data["location"] = data.get("location").get("name")

	save = False
	barcode=get_barcode()
	args={
		"person_firstname":data.get("first_name") or data.get("given_name") or data.get("name"),
		"person_middlename":"add",
		"person_lastname": data.get("last_name") or data.get("family_name"),
		"email":data.get("email"),
		"mobile":"",
		"received_from":"Desktop",
		"provider":"false",
		"barcode":str(barcode)
	}

	if not frappe.db.exists("User", user):

		# is signup disabled?
		if frappe.utils.cint(frappe.db.get_single_value("Website Settings", "disable_signup")):
			raise SignupDisabledError
		
		
		profile_res=create_profile_in_solr(args)
		response=json.loads(profile_res)
		if response['returncode']==101:
			path=get_image_path(barcode,response['entityid'])
			file_path='/files/'+response['entityid']+'/'+response['entityid']+".svg"
			save = True
			user = frappe.new_doc("User")
			user.update({
				"doctype":"User",
				"profile_id":response['entityid'],
				"first_name": data.get("first_name") or data.get("given_name") or data.get("name"),
				"last_name": data.get("last_name") or data.get("family_name"),
				"email": data["email"],
				"gender": (data.get("gender") or "").title(),
				"enabled": 1,
				"new_password": frappe.generate_hash(data["email"]),
				"location": data.get("location"),
				"user_type": "Website User",
				"access_type":"Patient",
				"user_image": data.get("picture") or data.get("avatar_url"),
				"created_via":"Desktop",
				"barcode":file_path
			})

			db=set_default_dashboard(response['entityid'])
		else:
			save = True
			user = frappe.new_doc("User")
			user.update({
				"doctype":"User",
				"first_name": data.get("first_name") or data.get("given_name") or data.get("name"),
				"last_name": data.get("last_name") or data.get("family_name"),
				"email": data["email"],
				"gender": (data.get("gender") or "").title(),
				"enabled": 1,
				"new_password": frappe.generate_hash(data["email"]),
				"location": data.get("location"),
				"user_type": "Website User",
				"user_image": data.get("picture") or data.get("avatar_url")
			})

	else:
		user = frappe.get_doc("User", user)
		save = True
		if not user.profile_id and not user.access_type=="Provider":
			profile_res=create_profile_in_solr(args)
			if response['returncode']==101:
				path=get_image_path(barcode,response['entityid'])
				db=set_default_dashboard(response['entityid'])
				file_path='/files/'+response['entityid']+'/'+response['entityid']+".svg"
				if not barcode:
					user.update({
						"barcode":file_path,
						"profile_id":response['entityid']
					})
				else:
					user.update({
						"profile_id":response['entityid']
					}) 


	if provider=="facebook" and not user.get("fb_userid"):
		save = True
		user.update({
			"fb_username": data.get("username"),
			"fb_userid": data["id"],
			"user_image": "https://graph.facebook.com/{id}/picture".format(id=data["id"])
		})

	elif provider=="google" and not user.get("google_userid"):
		save = True
		user.google_userid = data["id"]

	elif provider=="github" and not user.get("github_userid"):
		save = True
		user.github_userid = data["id"]
		user.github_username = data["login"]

	if save:
		user.ignore_permissions = True
		user.no_welcome_mail = True
		user.save()