Smarty Translation

I was asked to add the ability to delete prescriptions.

I used

     let msg = 'Do you really want to delete ';
     let choice = confirm(msg + d);

However, I could not find a way to translate the msg since it is in smarty and inside ajax in my mind.

suggestions, please. @mdsupport @rhausam

Just wanted to repeat my review comment here for those that may be unaware of this functionality.

For 5.0.3 you can use
let msg = xl('Do you really want to delete ‘);
I’m unsure if utility.js is in scope for this smarty but you can try.
Or:
let isPromise = top.jsFetchGlobals(‘e_rx’);
isPromise.then(msg => {
alert(msg.e_rx.deleteWarn’);
… add rest of your delete ajax function within resolved promise
});
Then add your translation in library/ajax/phpvars_to_js.php. (this will also work in v5.0.2) but best choice is the new JS xl() function for 5.0.3 even if you have to include utility.js to forms scope.(note that utility.js is included automatic if the Header class is used.)

1 Like

We reserve use of native javascript constructs like input, confirm and alert to development mode. But if you must, you do have option of using ajax or passing the object.

A bigger concern while looking at the patch is you are deleting the Rx record. Considering prescriptions have external aspect (either print or transmission), I would strongly encourage use of delete flag rather than actual deletion. A related benefit of that mechanism is we skip the prompt altogether and replace e.g. fa-trash by fa-undo on the screen. Now user has an option to undo their action in case of a mistake as long as the screen does not transition. Once the screen is changed/refreshed, undo action will not be possible.

While I understand and appreciate the flag rather than the deletion of the record altogether. The EU was focus on prescriptions that were in the patients record by mistake. Those are the entries that they want to delete because they saw no purpose in having the drug in the patient’s chart if it was entered by mistake. The flag would hide the mistake but it would still be apart of the record even in the background. So, they are focus on the complete removal of the record. They will use the active and inactive as designed.

As always, I appreciate the input.

hi, Placed another option on the PR since this is within a php context (although in smarty), do have option of using standard openemr php translation/escaping functions. Although I agree using the cool openemr javascript xl() function is also a nice option (if do not need to backport to 5.0.2).

I knew we had this option but I can never remember how to use them in smarty. Probably should have been the goto in this case.

Probably coolest new function we’ve added in a while.

1 Like