Can there be more than one "If" statement in SMS macro?

Setting up SMS appointment reminders and following the excellent advice here I've got them sending reminders for consultation or xxx procedure where xxx is appropriately anything but consultation (ie surgical, dental, desexing) using code below.

 

expr:if($appointment.appointmentType.entity.name = 'Consultation',
concat(expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),
                     ' appointment at ' , $location.name,' is confirmed for ', date:formatDate($appointment.startTime, 'short'),
                     ' @ ', date:formatTime($appointment.startTime, 'short'), $nl,$nl,
                     'Due to Covid 19 restrictions, only one fully vaccinated person may enter the clinic. Proof of vaccination will be required.',$nl,$nl,
                     'If you prefer, we can still provide contactless service.  When you arrive in our car park phone us on 9312-2500.',$nl,$nl,
                     'Please wear your face mask at all times whilst attending the clinic and when speaking with our staff.',$nl,
                      'Thank you.',$nl,
                      'Sunshine Vets',$nl,$nl,
        'If queries phone ', party:getTelephone($location)
        ),

concat(expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),
                     ' appointment for a ', $appointment.appointmentType.entity.name, ' procedure is confirmed for ',date:format($appointment.startTime,' EEEE d-MMM-yy.') ,$nl,$nl,
                     'Please drop your pet off between 8:30 and 10:30am; pick up will be sometime between 5-7pm.',$nl,$nl,
                      $patient.name,' may have dinner around 6-7pm the evening before and then no more food is to be given before the procedure. Water does not need to be restricted, ', $patient.name,'  may continue to drink water.',$nl,$nl,
                      'When you arrive in our car park, remain in your car and phone us on 93122500. Please wear your face mask when speaking with our staff.',$nl,
                      'Thank you.',$nl,
                      'Sunshine Vets',$nl,$nl,
       'Please do not reply this text message; if you wish to speak with staff please call  ', party:getTelephone($location))
        )

Is it possible to add another "if" for "vaccination"?  At the moment the SMS reminder would say "Vaccination Procedure" and give the "no food" spiel  if appointment type is set to vaccination.
Copying the first "if" expression and renaming "consultation" to "vaccination" only resulted in an expression error.

Yuri.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Can there be more than one "If" statement in SMS macro?

You can chain them:

expr:if(condition1, then1,
        expr:if(condition2, then2,
                expr:if(condition3, then3, else3)))

E.g.:

expr:if($appointment.appointmentType.entity.name = 'Consultation', concat(...)
        expr:if($appointment.appointmentType.entity.name = 'Vaccination', concat(....),
                concat(...)))

You may have to change that $patient.name to an expr:ifempty(), to handle appointments where the patient isn't set.

expr:ifempty(expr:var('patient.name'), 'Your patient')

Re: Can there be more than one "If" statement in SMS macro?

I've intermittently struggled with this code to try to get it to work, copying exactly the format of the consult and vaccination block as per your advice above.   A macro with either the Consultation section or the Vaccination section works perfectly but as soon as I try to add both "if" statements I get "invalid Xpath" and Syntax error after: 'expr:i'

I've checked matching braces, checked comma placement but can't get it to work.

Attached is what I'm trying to do following your format above.

It's probably a simple coding error I've mane but after many hours I can't see it.

Assistance very gratefully accepted.

Yuri.

 

AttachmentSize
appointment_reminder_macro.txt 2.86 KB

Re: Can there be more than one "If" statement in SMS macro?

You're missing a comma on line 11 and a trailing ). Try:

expr:if($appointment.appointmentType.entity.name = 'Consultation',
concat(expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),
             ' appointment at ' , $location.name,' is confirmed for ', date:formatDate($appointment.startTime, 'short'),
             ' @ ', date:formatTime($appointment.startTime, 'short'), $nl,$nl,
             'Due to Covid 19 restrictions, only one fully vaccinated person may enter the clinic. Proof of vaccination will be required.',$nl,$nl,
             'If you prefer, we can still provide contactless service.  When you arrive in our car park phone us on 9312-2500.',$nl,$nl,
             'Please wear your face mask at all times whilst attending the clinic and when speaking with our staff.',$nl,
             'Thank you.',$nl,
             'Sunshine Vets',$nl,$nl,
             'If queries phone ', party:getTelephone($location)
        ),

       expr:if($appointment.appointmentType.entity.name = 'Vaccination',
       concat(expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),
                     ' appointment at ' , $location.name,' is confirmed for ', date:formatDate($appointment.startTime, 'short'),
                     ' @ ', date:formatTime($appointment.startTime, 'short'), $nl,$nl,
                     'Due to Covid 19 restrictions, only one fully vaccinated person may enter the clinic. Proof of vaccination will be required.',$nl,$nl,
                     'If you prefer, we can still provide contactless service.  When you arrive in our car park phone us on 9312-2500.',$nl,$nl,
                     'Please wear your face mask at all times whilst attending the clinic and when speaking with our staff.',$nl,
                      'Thank you.',$nl,
                      'Sunshine Vets',$nl,$nl,
                      'If queries phone ', party:getTelephone($location)
        ),

concat(expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),
           ' appointment for a ', $appointment.appointmentType.entity.name, ' procedure is confirmed for ',date:format($appointment.startTime,' EEEE d-MMM-yy.') ,$nl,$nl,
           'Please drop your pet off between 8:30 and 10:30am; pick up will be sometime between 5-7pm.',$nl,$nl,
            $patient.name,' may have dinner around 6-7pm the evening before and then no more food is to be given before the procedure. Water does not need to be restricted, ', $patient.name,'  may continue to drink water.',$nl,$nl,
            'When you arrive in our car park, remain in your car and phone us on 93122500. Please wear your face mask when speaking with our staff.',$nl,
            'Thank you.',$nl,
            'Sunshine Vets',$nl,$nl,
            'Please do not reply this text message; if you wish to speak with staff please call  ', party:getTelephone($location))
        ))

Re: Can there be more than one "If" statement in SMS macro?

1.  Aah, I'd not included that line 11 comma - as per your example in the second code box above.  And I missed that last bracket.

2.  The macro as you've posted now works...... however vaccinations are still given the "no food/admission" component of the macro, not the "consultation" section. 

Going forward I think I'll limit Consultation Schedule Types to "Consultation" only and have "Vaccination" and "Annual Health Check" and other items listed in the "Visit Reason" field.  I've just noticed that the "Visit Reason" field is what appears under the Client / Patient name in the Appointment Schedule - that seems to be what staff and vets tell me they need to see.

Sorted.

Thanks.

Yuri.

 

 

Re: Can there be more than one "If" statement in SMS macro?

Make sure the name of the Appointment Type is an exact match to that in the xpath expression. The text is case-sensitive.

Also, both the Consultation and Vaccination text seem to be identical. You can simplify the expression to:

expr:if($appointment.appointmentType.entity.name = 'Consultation' or $appointment.appointmentType.entity.name = 'Vaccination',
concat(expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),
             ' appointment at ' , $location.name,' is confirmed for ', date:formatDate($appointment.startTime, 'short'),
             ' @ ', date:formatTime($appointment.startTime, 'short'), $nl,$nl,
             'Due to Covid 19 restrictions, only one fully vaccinated person may enter the clinic. Proof of vaccination will be required.',$nl,$nl,
             'If you prefer, we can still provide contactless service.  When you arrive in our car park phone us on 9312-2500.',$nl,$nl,
             'Please wear your face mask at all times whilst attending the clinic and when speaking with our staff.',$nl,
             'Thank you.',$nl,
             'Sunshine Vets',$nl,$nl,
             'If queries phone ', party:getTelephone($location)
        ),

concat(expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),
           ' appointment for a ', $appointment.appointmentType.entity.name, ' procedure is confirmed for ',date:format($appointment.startTime,' EEEE d-MMM-yy.') ,$nl,$nl,
           'Please drop your pet off between 8:30 and 10:30am; pick up will be sometime between 5-7pm.',$nl,$nl,
            $patient.name,' may have dinner around 6-7pm the evening before and then no more food is to be given before the procedure. Water does not need to be restricted, ', $patient.name,'  may continue to drink water.',$nl,$nl,
            'When you arrive in our car park, remain in your car and phone us on 93122500. Please wear your face mask when speaking with our staff.',$nl,
            'Thank you.',$nl,
            'Sunshine Vets',$nl,$nl,
            'Please do not reply this text message; if you wish to speak with staff please call  ', party:getTelephone($location))
        )

 

Re: Can there be more than one "If" statement in SMS macro?

>Also, both the Consultation and Vaccination text seem to be identical.

Yes, I was going to have slightly different scripts but was initially trying just to get the macro to work so had copied the section I knew worked.  I had fiddled with an "or" option but must've messed up the syntax <g!>.  This latest version works perfectly* so thank you very much for your assistance. 

Yuri.

(* now transferred to the category of "if it's not broken, don't fix it!")

 

 

Blank patient.name field error

Me again (can never leave "well enough" alone).

The original macro above says, inter alia,

expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your')

.... which I assume is supposed to insert Your for patient.name istead of, say,  Fred's if it was left blank in the appointment  (my coding reading/writing skills are at "nuisance" level (the level just above "rank amateur")). 

However if an appoinment is made without patient name being set, the reminder sms doesn't get sent with a "red bell" icon in Schedule View and with error message "Failed to evaluate the expression in Default Appointment Reminder SMS Template".

Upthread you did suggest using this code to handle appointments where patient isn't set:

expr:ifempty(expr:var('patient.name'), 'Your patient')

So I changed the code snippet in original macro from

concat(  expr:if(expr:var('patient.name') != '', concat(expr:var('patient.name'), "'s"), 'Your'),

to

concat(  expr:ifempty(expr:var('patient.name'),  concat("Your pet","'s")),

It tested ok in the "Sample SMS window" and (sort of*) worked if there was a patient.name in the appointment but likewise returned the same error message above if the patient field was blank.  (*The ifempty function returns the content of patient.name if it's not empty, so there's no apostrophe + s attached.  This is probably why the original code was written the way it was.)

This only occurs in that proportion of appointment reminders for clients with new pets that don't have a name for their new pet at the time of making the appointment.

Our current workaround is a bit clunky - put  a new patient with name of "Unnamed" and its species (they're the only two fields required to add a patient)  then let reception change patient.name on admission.

Suggestions welcomed.

Yuri.

Re: Blank patient.name field error

What's the complete expression?

The above fragment looks like it will just generate Your pet's if the patient name is empty.

 

Re: Blank patient.name field error

>What's the complete expression?
>The above fragment looks like it will just generate Your pet's if the patient name is empty.

That's what I thought.  Complete expression below. 

If appointment has client name and pet name, it sends the SMS perfectly. It correctly selects the component of the expression for consultation/vaccination or surgical/dental procedure.

If the pet name is blank, the appointment reminder is not sent and flags with a "red bell" warning.  If you try to send SMS via the Remind button, this error message is returned:

  • "Failed to evaluate the expression in Default Appointment Reminder SMS Template"
expr:if($appointment.appointmentType.entity.name = 'consultation' or $appointment.appointmentType.entity.name = 'vaccination',

             concat(  concat(expr:ifempty(expr:var('patient.name'), "Your pet"), "'s"),

             ' appointment for a ',$appointment.appointmentType.entity.name,' at ' , $location.name,' is confirmed for ',
             date:format($appointment.startTime,' EEEE d-MMM-yy.') ,
             ' @ ', date:formatTime($appointment.startTime, 'short'), $nl,$nl,
             'Due to Covid 19 restrictions, only one fully vaccinated person may enter the clinic. Proof of vaccination will be required.',$nl,$nl,
             'If you prefer, we can still provide contactless service.  When you arrive in our car park phone us on 9312-2500.',$nl,$nl,
             'Please wear your face mask at all times whilst attending the clinic and when speaking with our staff.',$nl,
             'Thank you.',$nl,
             'Sunshine Vets',$nl,$nl,
             'If queries phone ', party:getTelephone($location)
        ),

concat(  concat(expr:ifempty(expr:var('patient.name'), "Your pet"), "'s"),

           ' appointment for a ', $appointment.appointmentType.entity.name, ' procedure is confirmed for ',
            date:format($appointment.startTime,' EEEE d-MMM-yy.') ,
            $nl,$nl,
           'Please drop your pet off between 8:30 and 10:30am; pick up will be sometime between 5-7pm.',$nl,$nl,
            $patient.name,' may have dinner around 6-7pm the evening before and then no more food is to be given before the procedure. Water does not need to be restricted, ',
            $patient.name,'  may continue to drink water.',$nl,$nl,
            'When you arrive in our car park, remain in your car and phone us on 93122500. Please wear your face mask when speaking with our staff.',$nl,
            'Thank you.',$nl,
            'Sunshine Vets',$nl,$nl,
            'Please do not reply this text message; if you wish to speak with staff please call  ', party:getTelephone($location))
        )

Yuri.

Re: Blank patient.name field error

That's because you are using $patient.name. You can't use variables directly if there is a chance they might not be defined. You need to use something like:

expr:ifempty(expr:var('patient.name'), "your pet")

Re: Blank patient.name field error

Nothing like a fresh set of eyes! 

Thank you.

I'd replaced the patient.name everywhere except in the second part of the expression having completely forgotten that it had been personalised as well.

Having now made the changes, it works perfectly, named pet or not.

Re: Can there be more than one "If" statement in SMS macro?

Next question:

Staff want "review" added to appoinment types but reminder SMS returns the surgical procedure section of the SMS.  I've  added "consultation for review" to appointment types.

Original ine of code:

expr:if($appointment.appointmentType.entity.name = 'consultation' or $appointment.appointmentType.entity.name = 'vaccination', 

I see that there is a "substring" in xpath. 

I've tried to add it to the first line of code (original line of code above) so that the "if" condition would catch both "consultation" and "consultation for review" -  I figure I'm close with this.....

expr:if(substring($appointment.appointmentType.entity.name,1,7) = 'consult' or $appointment.appointmentType.entity.name = 'vaccination',. 

.... and it works syntactically (is that a word?), but it doesn't return the consultation section of the expression. 

I've tried 1,6,   1,7,   0,6    0,7.  Am I close?

Supplementary question, assuming I can get code above working:  Can xpath find a substring that's not in a fixed position (as "review consultation" would read better in an SMS than "consultation for review" )?

Advice welcome.

Yuri.

Re: Can there be more than one "If" statement in SMS macro?

Ok, I've got it!  I had the wrong command.

I needed to use the contains function which returns true or false to satisfy the "if" condition:

:if(contains($appointment.appointmentType.entity.name,'consult') or $appointment.appointmentType.entity.name = 'vaccination',

It now picks up "review consultation" perfectly.

Yuri.

Syndicate content