Hello,
Has anyone had success with adding MEL code to a history or letter view?
I have a function that works perfectly in a form, however when you add it to the history view it doesn't work, or gives unhelpful error messages.
Some functions such as ADDDATES don't work at all.
Thanks
I use MEL in Histories, Letters, Handouts, and Forms all the time. There is usually some slight flukes that you have to be aware of, and some MEL codes specifically say in the Help file that they only work in specific sections of CPS (such as QuickText only, or in a Form only).
If you post the code, I would be happy to take a look at it. Hopefully we can get the functionality you are looking for.
Here's what I have so far, this works in a form, however it does not work in a history view,
One of the problems is that it gives me an error message for the ADDDATES, If i remove it, it runs, but i need a date, not a datetime
Another problem is that the if statement in the result gets an error message, if i remove the if statements it runs.
What I am trying to accomplish is to pull in all of a certain vaccine, and display it, I got this to work
However, I need this function to filter out duplicate vaccines (any vaccine that was given on the same day).
{!fn fnTextTransImmunHx(Vaccine) {
//gets vaccine
local hold = getfield(IMMUN_GETLIST("Vaccine", "all"), "|", "")
local temp
local temp1
local temp2
local temp3
local temp4
local temp5
local temp6
global rslt = ""
for i = size(hold), i > 0, i = i - 1 do
temp = getfield(hold[i], "^", "")
//Puts the series in the temporary variable
cond
case i = 6 temp1 = ADDDATES(temp[30],"0","0","0")
case i = 5 temp2 = ADDDATES(temp[30],"0","0","0")
case i = 4 temp3 = ADDDATES(temp[30],"0","0","0")
case i = 3 temp4 = ADDDATES(temp[30],"0","0","0")
case i = 2 temp5 = ADDDATES(temp[30],"0","0","0")
case i = 1 temp6 = ADDDATES(temp[30],"0","0","0")
endcond
//Removes duplicates
cond
case temp1 = temp2 temp2 = ""
case temp1 = temp3 temp3 = ""
case temp1 = temp4 temp4 = ""
case temp1 = temp5 temp5 = ""
case temp1 = temp6 temp2 = ""
case temp2 = temp3 temp3 = ""
case temp2 = temp4 temp4 = ""
case temp2 = temp5 temp5 = ""
case temp2 = temp6 temp6 = ""
case temp3 = temp4 temp4 = ""
case temp3 = temp5 temp5 = ""
case temp3 = temp6 temp6 = ""
case temp4 = temp5 temp5 = ""
case temp4 = temp6 temp6 = ""
case temp5 = temp6 temp6 = ""
endcond
endfor
//For formating the list, so that there are no empty spaces
return
if temp1 == "" then "" else temp1 + HRET endif +
if temp2 == "" then "" else temp2 + HRET endif +
if temp3 == "" then "" else temp3 + HRET endif +
if temp4 == "" then "" else temp4 + HRET endif +
if temp5 == "" then "" else temp5 + HRET endif +
if temp6 == "" then "" else temp6 + HRET endif
}}
May i ask which help file you are referring to? Is it in CPS or in vfe?
Thanks for the help
It is the HELP file in CPS. just press F1, and then look in the table of contents to find the section on MEL. if you know the name of the code, you can also search for it.
I'll look into the code and get back to you after some testing. Thank you for posting it. 🙂
I think the issue is that you are calling the function fnTextTransImmunHx(Vaccine), passing the vaccine name in as argument #1. However, when you declare the variable "hold", you are passing "Vaccine" as argument #1, which is a literal string of characters "Vaccine" and not the value you passed to the function.
Hello again!
Chaddix is correct that the issue lies in the way it is called. I removed the quotes from Vaccine and it ran great. Here is the full code I stuck in my Hx view.
{!fn fnTextTransImmunHx(Vaccine) {
//gets vaccine
local hold = getfield(IMMUN_GETLIST(Vaccine, "all"), "|", "")
local temp
local temp1
local temp2
local temp3
local temp4
local temp5
local temp6
global rslt = ""
for i = size(hold), i > 0, i = i - 1 do
temp = getfield(hold[i], "^", "")
//Puts the series in the temporary variable
cond
case i = 6 temp1 = ADDDATES(temp[30],"0","0","0")
case i = 5 temp2 = ADDDATES(temp[30],"0","0","0")
case i = 4 temp3 = ADDDATES(temp[30],"0","0","0")
case i = 3 temp4 = ADDDATES(temp[30],"0","0","0")
case i = 2 temp5 = ADDDATES(temp[30],"0","0","0")
case i = 1 temp6 = ADDDATES(temp[30],"0","0","0")
endcond
//Removes duplicates
cond
case temp1 = temp2 temp2 = ""
case temp1 = temp3 temp3 = ""
case temp1 = temp4 temp4 = ""
case temp1 = temp5 temp5 = ""
case temp1 = temp6 temp2 = ""
case temp2 = temp3 temp3 = ""
case temp2 = temp4 temp4 = ""
case temp2 = temp5 temp5 = ""
case temp2 = temp6 temp6 = ""
case temp3 = temp4 temp4 = ""
case temp3 = temp5 temp5 = ""
case temp3 = temp6 temp6 = ""
case temp4 = temp5 temp5 = ""
case temp4 = temp6 temp6 = ""
case temp5 = temp6 temp6 = ""
endcond
endfor
//For formating the list, so that there are no empty spaces
return
if temp1 == "" then "" else temp1 + HRET endif +
if temp2 == "" then "" else temp2 + HRET endif +
if temp3 == "" then "" else temp3 + HRET endif +
if temp4 == "" then "" else temp4 + HRET endif +
if temp5 == "" then "" else temp5 + HRET endif +
if temp6 == "" then "" else temp6 + HRET endif
}}
{fnTextTransImmunHx("Influenza")}
I got back the dates of my test patient's flue shots, so it looks like it is going great! 🙂 Try it out and let us know if it works.
It runs, but unfortunately the problem of the duplicates still persists.
Similarly to your test patient, where it shows that he got two flu vaccines on the same day, that is what i am trying to remove with my case statements.
Thanks for all of your help!
I was playing with the code, and it was having some flukes with comparing values. I re-wrote it to be shorter, and to check for duplicates and build the results string at the same time.
I was able to get it to return all the flu vaccinces in the same patient with no duplicates. please try this out and let me know how it works.
{!fn fnTextTransImmunHx(Vaccine) {
//gets vaccine
local hold = getfield(IMMUN_GETLIST(Vaccine, "all"), "|", "")
local temp = ""
local rslt = ""
for i =1, i <= size(hold), i = i + 1 do
temp = getfield(hold[i], "^", "")
//Puts the series in the temporary variable
if (match(rslt,ADDDATES(temp[30],"0","0","0")) == 0) then
rslt = rslt + ADDDATES(temp[30],"0","0","0") + HRET
endif
endfor
return rslt}}
It works perfectly!
Thank you so much!
A bit late, but may i ask how you came to the conclusion to use the match function?
I was going through the list of symbols that were available in the history view, and it is not there, at the same time some of the symbols i am using don't seem to work, however they are in the list of available symbols.
Thanks again for all of the advice
Sure thing! I have used the match function in several of my own forms and letters to check if a specific string (like a date) is in a long list like the result the function builds. Since we justwant to make sure the same date is not in the list we have already built, match seemed like the go to choice.
With the symbols list, I have found that only a few of the functions actually specify where it Cannot be used at. besided that, it is just a matter of trial and error. I usually have a TEST handout and TEST letter to try new things just to make sure it will work. And when I am just baffled completely, I do exactly what you did and check the CHUG boards. Please let me know if you have any questions and I'll try my best to answer it. ^_^
Thank you,
Daniel Carpenter
Interesting, do you by any chance have a handy dandy method of sorting a group/ array of dates in a letter view? My method was to convert them to a yyyymmdd string, use mel SORT, and then convert it back to a date, which works!!
However it only works in a form and not a history view. Double checking the centricity help library, tells me that all of the functions i used can be used in "MEL expressions", which I assume includes the history view... Any ideas?
I do not have a function like that built, but your method sounds like it is probably the best way to do it! If you post the code, or email me ([email protected]) then I can try to help you get the code working in your letters.
Thank you,
Daniel Carpenter
This works in a form, so maybe it will help a random chugger, but otherwise it gives me strange errors in the history view.
The main problem is that its not liking the way I'm converting the dates to a string and then back to dates. But i need to do that to sort the array of dates, Maybe there's an easier way to sort it that I am unaware of,
What it does is,
1)Pulls in all rows for a certain vaccine
2)Only takes the datetime then converts it to a date
4) Makes sure the vaccine was actually given
3) Removes duplicates
4)Converts the date to a string
5) Sorts it (You cant sort unless its in a string)
6) Converts back to a date
7) Removes blanks from array
/**Converts the date to a string**/
{fn convertDateYear(d,f) {
local retStr = ""
local dateArray
cond
case d == "": /*Do Nothing*/
case match(d, 1, "/") <= 0: /*Do Nothing*/
else:
dateArray = getfield(d, "/", "")
if size(dateArray) == 3 then
cond
case f == "yyyymmdd": retStr = dateArray[3] + dateArray[1] + dateArray[2]
endcond
endif
endcond
return retStr
}}
/**Converts the string to a date**/
{fn convertStringToDate(d,f)
{
local retStr = ""
cond
case d == "": /*Do Nothing*/
case size(d) == 8:
cond
case f == "mm/dd/yyyy": retStr = sub(d, 5, 2) + "/" + sub(d, 7, 2) + "/" + sub(d, 1, 4)
endcond
endcond
return retStr
}}
/**Main code - gets row, takes only the date, removes duplicates, sorts and displays***************/
{fn fnImmunoHxTesting(Vaccine) {
//gets vaccine
local hold = getfield(IMMUN_GETLIST(Vaccine, "all"), "|", "")
local temp = ""
local rslt = ""
local tempGiven = ""
local aArray = array()
local ttemp = ""
local tRslt = ""
local tArray = array()
local temp2 = ""
local fRslt = ""
local finalArray = array()
local testingRslt = ""
for i =1, i <= size(hold), i = i + 1 do
temp = getfield(hold[i], "^", "")
tempGiven = temp[7]
if (tempGiven <> "Y") then ""
else
if (match(rslt,ADDDATES(temp[30],"0","0","0")) == 0) then
rslt = ADDDATES(temp[30],"0","0","0")
rslt = convertDateYear(rslt,"yyyymmdd")
insert(aArray,i,rslt)
endif
endif
endfor
sort(aArray,false)
for j =1, j <= size(aArray), j = j + 1 do
ttemp = get(aArray,j)
if (match(tRslt,ttemp) == 0) then
tRslt = ttemp
fRslt = convertStringToDate(tRslt,"mm/dd/yyyy")+ hret
insert(tArray,i,fRslt)
endif
endfor
for k =size(tArray), k >= 1, k = k - 1 do
finalArray = tArray
temp2 = get(tArray,k)
if (temp2 == "") then remove(finalArray,k)
else testingRslt = testingRslt + get(finalArray,k)
endif
endfor
return testingRslt
}}
Thanks for taking a look!
I'm back! I was able to test your function in a letter and it all seemed to work fine. I don't know if you have to make sure the functions are inserted in the order you will be using them, but I happened to copy paste them in that order anyway. below the dash line is the letter I built with the code you posted here. try to paste this into a letter and see if it works.
--------------------------------------------------------------------------------------------------------------------
{fn convertDateYear(d,f) {
local retStr = ""
local dateArray
cond
case d == "": /*Do Nothing*/
case match(d, 1, "/") <= 0: /*Do Nothing*/
else:
dateArray = getfield(d, "/", "")
if size(dateArray) == 3 then
cond
case f == "yyyymmdd": retStr = dateArray[3] + dateArray[1] + dateArray[2]
endcond
endif
endcond
return retStr
}}
{fn convertStringToDate(d,f)
{
local retStr = ""
cond
case d == "": /*Do Nothing*/
case size(d) == 8:
cond
case f == "mm/dd/yyyy": retStr = sub(d, 5, 2) + "/" + sub(d, 7, 2) + "/" + sub(d, 1, 4)
endcond
endcond
return retStr
}}
{fn fnImmunoHxTesting(Vaccine) {
//gets vaccine
local hold = getfield(IMMUN_GETLIST(Vaccine, "all"), "|", "")
local temp = ""
local rslt = ""
local tempGiven = ""
local aArray = array()
local ttemp = ""
local tRslt = ""
local tArray = array()
local temp2 = ""
local fRslt = ""
local finalArray = array()
local testingRslt = ""
for i =1, i <= size(hold), i = i + 1 do
temp = getfield(hold[i], "^", "")
tempGiven = temp[7]
if (tempGiven <> "Y") then ""
else
if (match(rslt,ADDDATES(temp[30],"0","0","0")) == 0) then
rslt = ADDDATES(temp[30],"0","0","0")
rslt = convertDateYear(rslt,"yyyymmdd")
insert(aArray,i,rslt)
endif
endif
endfor
sort(aArray,false)
for j =1, j <= size(aArray), j = j + 1 do
ttemp = get(aArray,j)
if (match(tRslt,ttemp) == 0) then
tRslt = ttemp
fRslt = convertStringToDate(tRslt,"mm/dd/yyyy")+ hret
insert(tArray,i,fRslt)
endif
endfor
for k =size(tArray), k >= 1, k = k - 1 do
finalArray = tArray
temp2 = get(tArray,k)
if (temp2 == "") then remove(finalArray,k)
else testingRslt = testingRslt + get(finalArray,k)
endif
endfor
return testingRslt
}}
Dtap: {fnImmunoHxTesting("DTAP")}