I am trying to pull the patient's last DOS into a text component using the following code...
{IF(APPT_PRIOR() "") THEN sub(str(APPT_PRIOR()), 1, 10) ELSE "" ENDIF}
When the patient has a prior appointment it works just fine, however if they haven't been in yet, instead of getting a blank, I am getting this error...
{IF(APPT_PRIOR() "") THEN sub(str(APPT_PRIOR()), 1, 10) ELSE "" ENDIF <-Bad length
Any help would be much appreciated. Thanks!
You are missing an operator in your if statement. You want something like this:
{IF(APPT_PRIOR() <> “”) THEN sub(str(APPT_PRIOR()), 1, 10) ELSE “” ENDIF}
With out the <> it sounds like it is just returning as true based on the error you are seeing.
The formula I'm using does have the
For some reason it didn't copy over into my original post.
Try:
{IF(APPT_PRIOR() <> “”) and (size(APPT_PRIOR()) >= 10 THEN sub(str(APPT_PRIOR()), 1, 10) ELSE “” ENDIF}
Since we know the forum here loves to strip out operation text:
if APPT_PRIOR() doesn't equal "" and size(APPT_PRIOR() is greater than or equal to 10) then ...
I believe that the data symbol returns a blank space (if memory serves correctly), which is not the same as being NULL, hence why you are seeing that error. The addition of the size check will ensure that the value returned is at least 10 characters, which is required for the sub function.
Footnote - whenever using sub, it is always a good idea to check the size of the string before invoking it, otherwise it will throw an error. If the size is less than 'expected', you might use 'else userok("Unexpected Data Format, Please screenshot and notify (whomever) of this error" + HRET + string value here)'. It will aid in determining an appropriate course of action.
Hope this helps!
That worked perfectly. Thanks!
And great idea, I'll keep that in mind.