6 thoughts on ““Send detailed email to parents” functionality on the Office Visits page

  1. Jose Calahorrano

    Thank you very much for sharing this code. I have made it work in a test environment. Now I can see how to create and send an email.

    One thing is happening which I have researched and have not found a solution. The subject is displaying with the characters one sees on a web link when there are spaces in a file name for example. Here is a sample of what I am trying to describe: Smith13%2C%20A%27%20Mya%20M.R.%26nbsp%3B%uFFFD%20Health%20Office%20visit%20on%2004/07/2015%20at%2001%3A46%20PM.

    This happens in Firefox and IE. I have found this PowerSource article: PowerSchool HTML Tags (https://powersource.pearsonschoolsystems.com/article/72592). But I don’t see how to apply it. Have you run into this problem and solved it?

    Like

    Reply
  2. Jose Calahorrano

    OK Here is what I did that seems to work. I replaced the dash (-) in the var sSubject declaration of the function createEmailSubject() with (-) without the (). The other change I made was to remove the escape function around the variable msgSubj in the function openEmailMessage. Please let me know if I broke anything.

    Like

    Reply
  3. Jose Calahorrano

    I neglected to mention that my district is on version 8.2.1. Furthermore, I have been able to take your code and make it a page fragment so that you don’t have to customize the home_officevisit.html file at all. You simply create a txt file with the name: home_officevisit..content.footer.txt.

    Here is the code you put in the file:

    /* the info image */
    #imgInfo{
    /* set the size */
    width: 12px;
    height: 12px;
    }

    // Define a function that will get today’s date in MM/DD/YYYY format.
    function getTodaysDate(){
    var fullDate = new Date();
    var twoDigitMonth = (fullDate.getMonth() + 1) + “”;
    if(twoDigitMonth.length==+1) twoDigitMonth = “0” + twoDigitMonth;
    var twoDigitDate = fullDate.getDate() + “”;
    if(twoDigitDate.length==+1) twoDigitDate = “0” + twoDigitDate;
    var currentDate = twoDigitMonth + “/” + twoDigitDate + “/” + fullDate.getFullYear();
    return currentDate;
    }
    // Define a function that will get the current time (if delayMins is specified than it adds delayMins minutes to the current time).
    function getCurrentTime(delayMins){
    var today=new Date();
    var todayGetTime = today.getTime();
    if (delayMins != “” && typeof delayMins != “undefined”) today.setTime(todayGetTime + delayMins * 60 * 1000);
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    var ampm=h >= 12 ? ‘PM’ : ‘AM’;
    h = h % 12;
    h= h ? h : 12;
    h = h < 10 ? '0'+h : h;
    m = m < 10 ? '0'+m : m;
    var currentTime = h + ":" + m + " " + ampm;
    return currentTime;
    }
    // The following function will pre-populate several fields on the page.
    function prePopulateFields(){
    //Provider Name = Username
    $j("#officevisits_screenerName").val("~[x:username]");
    //Provider Type = "Nurse" (value = 10029 in my system – it might differ in yours!)
    $j("#officevisits_officeVisitScreenerTypeLUID").val("10002");
    //Visit Date is today's date
    $j("#officevisits_visitDate").val(getTodaysDate());
    //Visit Time In is the current time
    $j("#officevisits_visitTimeIni18").val(getCurrentTime());
    //Visit Time Out is the current time + 15 min
    $j("#officevisits_visitTimeOuti18").val(getCurrentTime(15));
    }
    // The next function creates the email button (defined by btnName and btnText) and adds it after element defined by afterWhichElem (as HTML Object).
    function createEmailBtn(btnName, btnText, afterWhichElem){
    var btnEmail = "” + btnText + ““;
    afterWhichElem.after(btnEmail);
    }
    // The following three functions build the email’s recipient(s), subject and body (the way the nurses wanted the email to look like).
    //builds the email’s recipient(s)
    function createEmailTo(){
    var sEmailTo = “~(GuardianEmail)”;
    return sEmailTo;
    }
    //builds the email’s subject
    function createEmailSubject(){
    var sSubject = “~(LastFirst) – Health Office visit on ” + $j(“#officevisits_visitDate”).val() + ” at ” + $j(“#officevisits_visitTimeIni18”).val();
    return sSubject;
    }
    //builds the email’s body
    function createEmailBody(){
    var sBody = “Visit details:\n”;
    if ($j(‘#officevisits_visitTypeLUID :selected’).val() != “”) sBody += “\tVisit Type: \n\t\t” + $j(‘#officevisits_visitTypeLUID :selected’).text() + “\n”;
    if ($j(“#officevisits_screenerName”).val() != “”){
    sBody += “\tProvider Name: \n\t\t” + $j(“#officevisits_screenerName”).val();
    if ($j(“#officevisits_officeVisitScreenerTypeLUID :selected”).val() != “”) sBody += ” (” + $j(“#officevisits_officeVisitScreenerTypeLUID :selected”).text() + “)”;
    sBody += “\n”;
    }
    sBody += “\nVisit reasons:\n”;
    if ($j(“#officevisits_visitReasonDesc”).val() != “”) sBody += “\tIssue: \n\t\t” + $j(“#officevisits_visitReasonDesc”).val().replace(/\n/g,”\n\t\t”) + “\n”;
    if ($j(“#officevisits_assessment”).val() != “”) sBody += “\tAssessment: \n\t\t” + $j(“#officevisits_assessment”).val().replace(/\n/g,”\n\t\t”) + “\n”;
    sBody += “\nOutcome and Actions:\n”;
    if ($j(“#officevisits_visitOutcomeLUID :selected”).val() != “”) sBody += “\tVisit outcome: \n\t\t” + $j(“#officevisits_visitOutcomeLUID :selected”).text() + “\n”;
    if ($j(“#officevisits_actions”).val().replace(/\n/g,”\n\t\t”) != “”) sBody += “\tActions: \n\t\t” + $j(“#officevisits_actions”).val().replace(/\n/g,”\n\t\t”) + “\n\n”;
    return sBody;
    }
    // This function opens a new email message in the default email client with the parameters specified by msgEmail, msgSubj and msgBody.
    function openEmailMessage(msgEmail,msgSubj,msgBody){
    var msgMail = “mailto:” + escape(msgEmail) + “?subject=” + msgSubj + “&body=” + escape(msgBody);
    window.location.href = msgMail;
    }
    // Define a function that checks if the “Contact with Parent” check box is checked or not, and if it isn’t then checks it.
    function checkContact(chkGuardCntct){
    if (chkGuardCntct.not(“:checked”)) {chkGuardCntct.attr(“checked”, “checked”)};
    }
    // Inside the “on document ready” jQuery function $j(document).ready(function() { …… } (if there isn’t one, add it) add the following piece of code:
    $j(document).ready(function() {
    //on clicking on the “+Add” button on the page
    $j(“#add_screening_button”).click(function() {
    //pre-populate fields
    prePopulateFields();
    //add the Info icon (displaying the student’s parent details)
    $j(“#officevisits_isGuardianContacted”).after(“”);
    //build the image’s title
    var imgTitle = “~([01]father) (~(ISB_contact1_relationship;if.blank.then=Contact 1;smartcase)): ~([01]fatherdayphone)\n~([01]mother) (~(ISB_contact2_relationship;if.blank.then=Contact 2;smartcase)): ~([01]motherdayphone)”;
    //assign the title to the image
    $j(“#imgInfo”).attr(“title”,imgTitle);
    });
    //define variables
    //button’s name and text
    var btnName = “email”;
    var btnText = “Email Guardian(s)”;
    //the element you want the Email Button inserted after (here: the Cancel button at the bottom of the page)
    var afterWhichElem = $j(“#cancel_officevisits_button”);
    //”Contact with Parent” checkbox
    var chkGuardCntct = $j(“#officevisits_isGuardianContacted”);
    //create the actual Email Button
    createEmailBtn(btnName,btnText,afterWhichElem);
    //on clicking on the freshly-created Email Button
    $j(“#screeningtable-email-officevisits-button”).on(“click”,function(){
    //check the checkbox
    checkContact(chkGuardCntct);
    //open the email message
    openEmailMessage(createEmailTo(),createEmailSubject(),createEmailBody());
    });
    });

    I had to put the dash(-) back in instead of using the html entity code.

    Thanks again for posting these customizations.

    Like

    Reply
  4. Jose Calahorrano

    Sorry again. I keep forgetting that the web plays havoc on the code. The name of the file should be: home_officevisit.putyourcustomnamehere.content.footer.txt

    Remember to place the style and script opening and closing tags.

    Like

    Reply

Leave a comment