Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hai 750 #254

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions configuration/pih/scripts/global/zl.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,88 @@ function updateLastCheckboxRequired(containerSelector) {

// Add the updateLastCheckboxRequired function to the beforeSubmit array to call it before form submission.
beforeSubmit.push(updateLastCheckbox);
}

usePatientAddressAsContactAddress();

function usePatientAddressAsContactAddress(){
jq(document).ready(function() {

// change the ckeckbox message based on the languade
var message='';
var url = window.location.href;
var urlParams = new URLSearchParams(new URL(url).search);
var langParam = urlParams.get('lang');
message=langParam === 'fr'? "Utilisez l'adresse du patient ?":"Use the patient address ?"

//target the div containing the contact address
const divElement = jq('#contactQuestionLabel div');

//creating a check, to be checked if clinician wants to use patient address as contact one
const checkboxElement = jq("<input>", {
type: "checkbox",
id: "question_address",
name: "question_address"
});

//Creating a label to show the checkbox title
const labelElement = jq("<label>", {
for: "question_address",
text: message
});

//creating a break line to push other elements a litle bit down
const brElement = $("<br>");
divElement.prepend(checkboxElement, labelElement, brElement);

// checkbox event occurs here
jq('#question_address').on('change', function() {
if (this.checked) {
//disable other input if the want to use the patient address as contact address
isInputDisabled(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try removing this line? I think disabling the inputs result it in not getting saved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean @mogoodrich line 434?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly @Dutervil

// get and set the new address detail from patient to contact
getPatienAddressInfo();

} else {
//Enable the inputs to put value manually
isInputDisabled(false);
clearInputValue();
}
});
});

}

function getPatienAddressInfo(){

//creating an array to store patient adress
var valuesArray = [];
var manualEntryAddress;
jq("#personAddressQuestion div input[type='text']").each(function() {
valuesArray.push(jq(this).val());
});
manualEntryAddress=$("#personAddressQuestion div input[type='text']:last").val()
jq("#contactQuestionLabel div input[type='text']:last").val(manualEntryAddress);


// target the contact address input and set the new value
jq("#contactQuestionLabel div input[type='text']").each(function(index) {
if (index < valuesArray.length) {
jq(this).val(valuesArray[index]);
Copy link
Member

@mogoodrich mogoodrich Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a line: " jq(this).data('legalValues', [ valuesArray[index] ])" which I think needs to happen for the entry to be considered "valid" (see my overall comments).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added focused class to the autocomplete when the checkbox is checked. I hoped that would help. it stil does not save in DB

//No need to show this error if value presents
jq("#contactQuestionLabel .field-error").val('');
}
});
}

function isInputDisabled(value){
jq("#contactQuestionLabel div input[type='text']").each(function() {
jq(this).prop("disabled", value);
});
}
function clearInputValue(){
jq("#contactQuestionLabel div input[type='text']").each(function(index) {
jq(this).val('');
});

}