Skip to content

Commit

Permalink
[UnblockHealth]Novu Integration to Register Form
Browse files Browse the repository at this point in the history
  • Loading branch information
bensonpaul committed Oct 31, 2023
1 parent 1694f64 commit 335cd64
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 36 deletions.
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ unsafe = true
topNavbarMenuLink = ["/","/about","/service","/register","/news","/press","/events","/blog","/faqs","/patient-impact-stories","/resources"]
footerNavbarMenu = ["Home","About","Services","Register","Sitemap","Privacy Policy", "Terms and Conditions"]
footerNavbarMenuLink = ["/","/about","/service","/register","/sitemap","/privacy-policy","/terms-and-conditions"]

novuBaseURL = "https://co.medigy.com/sendInvite/"
unblockHealthSupportEmail = "[email protected]"
Description = "The first-in-class comprehensive digital healthcare suite of patient advocacy tools for patients and consumers who are determined to be empowered in their health care journey. Unblock Health is revolutionizing patient autonomy and healthcare consumerism."
logotitle ="Comprehensive Healthcare Suite of Patient Advocacy Services designed for Patients and Consumers - Unblock Health"
footersectionaboutcontent ="Unblock Health rejects traditional barriers to patient health information. We empower patients to play an active role in their care and help HIM professionals deliver a positive experience."
Expand Down
2 changes: 2 additions & 0 deletions layouts/section/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ <h3 style="font-size:24px; line-height:34px;">{{ . }}</h3>
</div>
<input type="hidden" name="_subject" value="[UnBlock Health] - Contact Form Submission" />
<input type="hidden" name="_subject" value="[UnBlock Health] - Contact Form Submission" />
<input type="hidden" name="_novbaseurl" id="_novbaseurl" value={{.Site.Params.novuBaseURL}} />
<input type="hidden" name="_regformsupportemail" id="_regformsupportemail" value={{.Site.Params.unblockHealthSupportEmail}} />
</div>

<button class="slds-button slds-button_stretch slds-button_brand slds-p-around_medium slds-color__text_gray-1 slds-m-bottom_small" id="contact-submit-live">
Expand Down
127 changes: 92 additions & 35 deletions static/js/main-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ $(document).ready(function () {
)
}
var uid = uuidv4();
const date = new Date();
const todayDate = date.toLocaleString('en-US', {
timeZone: 'America/New_York',
weekday:"short",
year:"numeric",
month:"long",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
timeZoneName: "long",

});
$('#contact-submit-live').click(function (e) {
e.preventDefault();
var first_name = $('#name').val();
Expand All @@ -14,7 +27,7 @@ $('#contact-submit-live').click(function (e) {
var patientdetails = $('#patientoption').val();
var message = $('#message').val();
var o = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
console.log(" patientdetails -----------",first_name, email, subject, patientdetails);
//console.log(" patientdetails -----------",first_name, email, subject, patientdetails);

if (first_name == '') {
$('#namealert').css('display', 'block');
Expand Down Expand Up @@ -44,68 +57,112 @@ $('#contact-submit-live').click(function (e) {
else {
$('#patientalert').css('display', 'none');
}
/*Novu Integration For Sending Mail */
if(patientdetails == 'PA'){
var patientdetailsvalue = 'PPA';
} else if(patientdetails == 'HIM'){
var patientdetailsvalue = 'HIM';
} else {
var patientdetailsvalue = '';
}
$('.loader-form').show();
var concatenatedValues = first_name + "|" + email + "|" + patientdetailsvalue;

var form = new FormData();
form.append("grant_type", "client_credentials");
form.append("client_id", "93d80a68-5ad0-878d-a787-5da44425070f");
form.append("client_secret", "_S9UX^KZ&&t9W(aH");
var encodedValues = btoa(concatenatedValues);
var NovuBaseURL = $('#_novbaseurl').val();
var regformToEmail = $('#_regformsupportemail').val();
var inviteurl = NovuBaseURL+'token='+encodedValues;
var registerFormData = {
"name": "ubh-notify-user-registration",
"to": {
"subscriberId": regformToEmail,
"email": regformToEmail,
"firstName": first_name,
"lastName": ""
},
"payload": {
"requestor_email":email,
"invite_link": inviteurl,
"registration_type": patientdetailsvalue,
"registration_datetime": todayDate
}
};
var settings = {
"async": true,
"crossDomain": true,
"url": "https://crm.unblock.health/Api/access_token",
"url": "https://api.novu.infra.medigy.com/v1/events/trigger",
"method": "POST",
"timeout": 0,
"headers": {
"Accept": "application/vnd.api+json"
"Authorization": "ApiKey fa94fe1651ebb4d55a1bdfe6e5810a16",
"Content-Type": "application/json"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}

$.ajax(settings).done(function (response) {

var obj = $.parseJSON(response);
var access_token = obj.access_token;
"data": JSON.stringify(registerFormData),
};
/* End of Novu Integration */
$.ajax(settings).done(function(response) {
var form = new FormData();
form.append("grant_type", "client_credentials");
form.append("client_id", "93d80a68-5ad0-878d-a787-5da44425070f");
form.append("client_secret", "_S9UX^KZ&&t9W(aH");
var settings = {
"url": "https://crm.unblock.health/Api/V8/module",
"async": true,
"crossDomain": true,
"url": "https://crm.unblock.health/Api/access_token",
"method": "POST",
"headers": {
"Accept": "application/vnd.api+json",
"Authorization": "Bearer " + access_token + "",
"Content-Type": "application/json"
"Accept": "application/vnd.api+json"
},
"processData": false,
"data": "{\r\n \"data\": {\r\n \"type\": \"Contacts\",\r\n \"id\": \"" + uid + "\",\r\n \"attributes\": {\r\n \"first_name\":\"" + first_name + "\",\r\n \"email1\":\"" + email + "\"\r\n,\r\n \"lead_source\":\"Web Site\"\r\n,\r\n \"title\":\"" + patientdetails + "\"\r\n }\r\n }\r\n}\r\n"
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}

$.ajax(settings).done(function (response) {
console.log(response);
var contactid = response.data.id;

var obj = $.parseJSON(response);
var access_token = obj.access_token;
var settings = {
"async": true,
"crossDomain": true,
"url": "https://crm.unblock.health/Api/V8/module/Accounts/aba27ce2-d758-bdeb-adef-5da4294bf9e8/relationships",
"url": "https://crm.unblock.health/Api/V8/module",
"method": "POST",
"headers": {
"Accept": "application/vnd.api+json",
"Authorization": "Bearer " + access_token + "",
"Content-Type": "application/json"
},
"processData": false,
"data": "{ \r\n \"data\":{ \r\n \"type\":\"Contacts\",\r\n \"id\":\"" + contactid + "\"\r\n\t \r\n }\r\n}"
"data": "{\r\n \"data\": {\r\n \"type\": \"Contacts\",\r\n \"id\": \"" + uid + "\",\r\n \"attributes\": {\r\n \"first_name\":\"" + first_name + "\",\r\n \"email1\":\"" + email + "\"\r\n,\r\n \"lead_source\":\"Web Site\"\r\n,\r\n \"title\":\"" + patientdetails + "\"\r\n }\r\n }\r\n}\r\n"
}

$.ajax(settings).done(function (response) {
console.log(response);
if (response.meta.message != "") {
$('#name').val('');
$('#email').val('');
var $success = $('#success'); // get the reference of the div
$success.show().html('We appreciate your registration with Unblock Health.');
var contactid = response.data.id;
var settings = {
"async": true,
"crossDomain": true,
"url": "https://crm.unblock.health/Api/V8/module/Accounts/aba27ce2-d758-bdeb-adef-5da4294bf9e8/relationships",
"method": "POST",
"headers": {
"Accept": "application/vnd.api+json",
"Authorization": "Bearer " + access_token + "",
"Content-Type": "application/json"
},
"processData": false,
"data": "{ \r\n \"data\":{ \r\n \"type\":\"Contacts\",\r\n \"id\":\"" + contactid + "\"\r\n\t \r\n }\r\n}"
}

$.ajax(settings).done(function (response) {
console.log(response);
if (response.meta.message != "") {
$('#name').val('');
$('#email').val('');
var $success = $('#success'); // get the reference of the div
$success.show().html('We appreciate your registration with Unblock Health.');
}
});
});
});
}).fail(function(error) {
console.error("API call error:", error);
});
});

Expand Down

0 comments on commit 335cd64

Please sign in to comment.