// ==UserScript==
// @name Pagescraper V4 JY Care Connect, Pharmacare, copyable Phone links
// @namespace Stanscripts
// @description adds demographic details to echart with helpful links
// @include */casemgmt/forward.jsp?action=view&demographic*
// @include *careconnect*
// @include *eforms.healthbc.org*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
// @grant GM.setValue
// @grant GM.getValue
// @version 18 Fixed email for FF ESR 91.3; remove Doxy.me, email, and QuickLinks; add Pharmanet
// ==/UserScript==
const PROVIDER_NAME = "yap, john";
var hasSetPHN = false;
var hasSetProvider = false;
if (window.location.href.indexOf("careconnect") != -1) {
(async () => {
var phn = await GM.getValue("LinkPHN");
if (phn != undefined) {
console.log("Filled PHN from GM global value for CareConnect");
$('#search').val(phn);
}
})();
} else if (window.location.href.indexOf("eforms.healthbc") != -1) {
(async () => {
var phn = await GM.getValue("LinkPHN");
if (phn != undefined) {
console.log("Filled PHN from GM global value for PharmaCare");
}
setInterval(() => {
try {
// Can we see the element?
const patientField = document.getElementById("patientId");
if (phn != undefined && !hasSetPHN) {
if (patientField.offsetParent != null) {
patientField.value = phn;
document.getElementById("btn-patient-search").click();
hasSetPHN = true;
}
}
} catch (e) {}
try {
const providerField = document.getElementById("providername");
if (!hasSetProvider) {
if (providerField.offsetParent != null) {
providerField.value = PROVIDER_NAME;
document.getElementById("btn-provider-search").click();
hasSetProvider = true;
}
}
} catch (e) {}
}, 1000);
})();
} else {
//Reserve line in header
var header = document.getElementById('encounterHeader');
var headerReserve = header.innerHTML
header.innerHTML += '
'
var elements = (window.location.pathname.split('/', 2))
firstElement = (elements.slice(1))
//vPath = ('https://' + location.host + '/' + firstElement + '/')
vPath = '../'
var myParam = location.search.split('demographicNo=')[1]
var res = myParam.indexOf('&')
var demo_no = myParam.substring(0, res)
var demoArray = [
'Cell Phone',
'Email',
'Phone(H)',
'Address',
'City',
'Postal',
'Age',
'Health Ins',
'Phone(W)'
]
var demoArrayVal = []
function getMeasures(measure) {
xmlhttp = new XMLHttpRequest();
var pathArray = window.location.pathname.split('/');
var newURL = vPath + '/demographic/demographiccontrol.jsp?demographic_no=' + demo_no + '&displaymode=edit&dboperation=search_detail'
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//alert(xmlhttp.responseText)
//var str = xmlhttp.responseText.replace(/\s/g, '')
var str = xmlhttp.responseText
if (!str) {
return;
}
switch (measure) {
case "Phone(H)":
var myReString = '[\n\r\t]*\s*' + 'Phone' + '[(][' + 'H' + '][)]' + '(.|[\n])*'
break;
case "Phone(W)":
var myReString = '[\n\r\t]*\s*' + 'Phone' + '[(][' + 'W' + '][)]' + '(.|[\n])*'
break;
default:
var myReString = '[\n\r\t]*\s*' + measure + '(.|[\n])*'
}
var myRe = new RegExp(myReString, 'g');
var myArray
while ((myArray = myRe.exec(str)) !== null) {
y = myArray.toString()
//alert(y)
var z = y.indexOf('info')
var mycode = y.substring(z + 6)
var mycode2 = mycode.indexOf('')
var mycode3 = mycode.substring(mycode + 9, mycode2) //alert(j+measure + ' is ' + mycode3)
demoArrayVal[j] = mycode3
}
}
}
xmlhttp.open('GET', newURL, false);
xmlhttp.send();
}
function telLink(number){
var numberl = number.replace(/\D/g,'');
var l = ""+number+" ";
return l;
}
$(document).ready(function() {
for (j = 0; j < demoArray.length; j++) {
getMeasures(demoArray[j]);
}
//alert(demoArrayVal)
var passPHN = demoArrayVal[7].substr(0, 10);
localStorage.setItem("LinkPHN", passPHN); //STORE PHN
GM.setValue("LinkPHN", passPHN);
console.log(`Saved PHN to GM global values: ${passPHN}`);
var HCN = demoArrayVal[7]
res = HCN.slice(0, 10)
HCN = res
header.innerHTML = headerReserve
var headerExtra1 = 'Cell: '
var headerExtra2 = 'Age: '
var headerExtra3 = 'File#: '
var headerExtra4 = 'PHN: '
var headerExtra5 = 'Address: '
var headerExtra6 = 'Work: '
var headerExtra7 = 'Home: '
header.innerHTML += (headerExtra7.bold() + telLink(demoArrayVal[2]) + headerExtra1.bold() + telLink(demoArrayVal[0]) + headerExtra6.bold() + telLink(demoArrayVal[8]) + headerExtra5.bold() + demoArrayVal[3] + ', ' + demoArrayVal[4] + ', ' + demoArrayVal[5] + ' ' + headerExtra4.bold() + "" + HCN + "" +
'
' +
' eMail: '.bold() + "" + demoArrayVal[1] + "" +
' ' +
// 'Send eMail' +
' ' +
// '' +
// ' ' +
// '' +
// ' ' +
// '' +
// ' ' +
'' +
' ' +
''
);
/*
document.getElementById("button10").onclick = do_email;
document.getElementById("button10").setAttribute('style', 'font-size:10px; color:green;');
//var str = $('.Header > a:nth-child(1)').text()
var str = document.querySelector('[title="Master Record"]').innerHTML;
//alert(str)
var res = str.split(" ");
var ptname = res[1] + ' ' + res[0]
ptname = ptname.replace(",", " ");
//alert(ptname)
function do_email() {
//alert(demoArrayVal[1])
//var email = demoArrayVal[1]
var email = ptname + '<' + demoArrayVal[1] + '>'
var mailto_link = 'mailto:' + email + '?Subject=Confidential medical information'
window = window.open(mailto_link, 'emailWindow')
}
*/
// document.getElementById("button11").onclick = ButtonFunction11;
// document.getElementById("button11").setAttribute('style', 'font-size:10px; color:green;');
// //document.body.appendChild(input11);
// function ButtonFunction11() {
// window.open("https://doxy.me/account/dashboard", "newWindow", target = "_blank")
// }
// document.getElementById("button12").onclick = ButtonFunction12;
// document.getElementById("button12").setAttribute('style', 'font-size:10px; color:green;');
// function ButtonFunction12() {
// QuickLink = ('eform/efmformadd_data.jsp?fid=1009&demographic_no=')
// window.open(vPath + QuickLink + myParam, target = "_blank")
// }
document.getElementById("button13").onclick = ButtonFunction13;
document.getElementById("button13").setAttribute('style', 'font-size:10px; color:green;');
function ButtonFunction13() {
window.open("https://health.careconnect.ca?" + passPHN, "newWindow", target = "_blank")
}
document.getElementById("button14").onclick = ButtonFunction14;
document.getElementById("button14").setAttribute('style', 'font-size:10px; color:green;');
function ButtonFunction14() {
window.open("https://www.eforms.healthbc.org/login", "newWindow", target = "_blank")
}
var Clipboard=document.createElement("input");
Clipboard.type="button";
Clipboard.value="Clipboard:";
Clipboard.setAttribute("style", "position:absolute; top:32px; left:580px; width:75px; font-size:12px; text-align:center; background-color:pink;");
document.body.appendChild(Clipboard);
$(".copyable").click(function() {
var textArea = document.createElement("textarea");
textArea.value = this.innerHTML;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
$(this).css('background-color', 'pink')
textArea.setAttribute('style', 'position:absolute; top:32px; left:660px; width:250px; height:20px; font-size:13px; resize:none;');
textArea.setAttribute('title', 'Clipboard');
// textArea.remove(); // to hide text area
})
})
$(document).ready(function() {
$('#enTemplate').width("160px"); //widens search field
});
}