I need help writing and using a function to translate the patient's age in months to formatted text, ie infant, child, adolescent, young adult, adult, middle-aged adult, late middle-aged adult, early elderly adult, or elderly adult. I'm not quite sure about the syntax of writing a function for this purpose or how to insert that function in my normal physical exam. Here is what I have so far:
{! fn fnAGE(PATIENT._AGEINMONTHS){
if PATIENT._AGEINMONTHS <> "" then
COND
CASE PATIENT._AGEINMONTHS <1
result= "newborn "
CASE PATIENT._AGEINMONTHS >=1 and PATIENT._AGEINMONTHS <12
result= "infant "
CASE PATIENT._AGEINMONTHS >=12 and PATIENT._AGEINMONTHS <120
result= "child "
CASE PATIENT._AGEINMONTHS >=120 and PATIENT._AGEINMONTHS <216
result= "adolescent"
CASE PATIENT._AGEINMONTHS >=216 and PATIENT._AGEINMONTHS <300
result= "young adult "
CASE PATIENT._AGEINMONTHS >=300 and PATIENT._AGEINMONTHS <480
result= "adult "
CASE PATIENT._AGEINMONTHS >=480 and PATIENT._AGEINMONTHS <720
result= "middle-aged adult "
CASE PATIENT._AGEINMONTHS >=720 and PATIENT._AGEINMONTHS <780
result= "late middle-aged adult "
CASE PATIENT._AGEINMONTHS >=780 and PATIENT._AGEINMONTHS <840
result= "early elderly adult "
CASE PATIENT._AGEINMONTHS >=840
result= "elderly adult "
else result=""
endif
}
}
I would greatly appreciate any suggestions for proper syntax to make this work and clarification on what I have to write in the Set Value field of my normal button to make this happen. I want the normal exam to read as follows: "Well appearing middle-aged obese male, alert, no distress. Vitals reviewed." Once I have this age component figured out, I'll do the same thing for BMI ranges and patient.sex.
Thanks!
Chris McCracken, MD
here is what I used for BMI, the idea is pretty similar. For PATIENT._AGEINMONTHS you will need to use parenthesis around the values and CPS tweaks out on infant patients.
{
if PATIENT_AGE() >= 21 and OBSNOW("weight") <> "" then
local currentProblems=PROB_AFTER("list")
COND
CASE VAL(DOCUMENT.BODY_MASS_IN) > 0 and VAL(DOCUMENT.BODY_MASS_IN) <=19 and match(currentProblems,"BMI equal to or less than 19,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI equal to or less than 19,adult", "ICD10-Z68.1", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 20.0 and VAL(DOCUMENT.BODY_MASS_IN) < 21 and match(currentProblems,"BMI 20.0-20.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 20.0-20.9,adult", "ICD10-Z68.20", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 21.0 and VAL(DOCUMENT.BODY_MASS_IN) < 22 and match(currentProblems,"BMI 21.0-21.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 21.0-21.9,adult", "ICD10-Z68.21", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 22.0 and VAL(DOCUMENT.BODY_MASS_IN) < 23 and match(currentProblems,"BMI 22.0-22.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 22.0-22.9,adult", "ICD10-Z68.22", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 23.0 and VAL(DOCUMENT.BODY_MASS_IN) < 24 and match(currentProblems,"BMI 23.0-23.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 23.0-23.9,adult", "ICD10-Z68.23", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 24.0 and VAL(DOCUMENT.BODY_MASS_IN) < 25 and match(currentProblems,"BMI 24.0-24.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 24.0-24.9,adult", "ICD10-Z68.24", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 25.0 and VAL(DOCUMENT.BODY_MASS_IN) < 26 and match(currentProblems,"BMI 25.0-25.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 25.0-25.9,adult", "ICD10-Z68.25", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 26.0 and VAL(DOCUMENT.BODY_MASS_IN) < 27 and match(currentProblems,"BMI 26.0-26.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 26.0-26.9,adult", "ICD10-Z68.26", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 27.0 and VAL(DOCUMENT.BODY_MASS_IN) < 28 and match(currentProblems,"BMI 27.0-27.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 27.0-27.9,adult", "ICD10-Z68.27", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 28.0 and VAL(DOCUMENT.BODY_MASS_IN) < 29 and match(currentProblems,"BMI 28.0-28.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 28.0-28.9,adult", "ICD10-Z68.28", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 29.0 and VAL(DOCUMENT.BODY_MASS_IN) < 30 and match(currentProblems,"BMI 29.0-29.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 29.0-29.9,adult", "ICD10-Z68.29", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 30.0 and VAL(DOCUMENT.BODY_MASS_IN) < 31 and match(currentProblems,"BMI 30.0-30.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 30.0-30.9,adult", "ICD10-Z68.30", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 31.0 and VAL(DOCUMENT.BODY_MASS_IN) < 32 and match(currentProblems,"BMI 31.0-31.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 31.0-31.9,adult", "ICD10-Z68.31", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 32.0 and VAL(DOCUMENT.BODY_MASS_IN) < 33 and match(currentProblems,"BMI 32.0-32.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 32.0-32.9,adult", "ICD10-Z68.32", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 33.0 and VAL(DOCUMENT.BODY_MASS_IN) < 34 and match(currentProblems,"BMI 33.0-33.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 33.0-33.9,adult", "ICD10-Z68.33", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 34.0 and VAL(DOCUMENT.BODY_MASS_IN) < 35 and match(currentProblems,"BMI 34.0-34.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 34.0-34.9,adult", "ICD10-Z68.34", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 35.0 and VAL(DOCUMENT.BODY_MASS_IN) < 36 and match(currentProblems,"BMI 35.0-35.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 35.0-35.9,adult", "ICD10-Z68.35", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 36.0 and VAL(DOCUMENT.BODY_MASS_IN) < 37 and match(currentProblems,"BMI 36.0-36.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 36.0-36.9,adult", "ICD10-Z68.36", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 37.0 and VAL(DOCUMENT.BODY_MASS_IN) < 38 and match(currentProblems,"BMI 37.0-37.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 37.0-37.9,adult", "ICD10-Z68.37", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 38.0 and VAL(DOCUMENT.BODY_MASS_IN) < 39 and match(currentProblems,"BMI 38.0-38.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 38.0-38.9,adult", "ICD10-Z68.38", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 39.0 and VAL(DOCUMENT.BODY_MASS_IN) < 40 and match(currentProblems,"BMI 39.0-39.9,adult")==0 MEL_ADD_PROBLEM("dx of", "BMI 39.0-39.9,adult", "ICD10-Z68.39", str(._TODAYSDATE), "", "") CASE VAL(DOCUMENT.BODY_MASS_IN) >= 40.0 and match(currentProblems,"BMI 40.0 and over,adult")==0
MEL_ADD_PROBLEM("dx of", "BMI 40.0 and over,adult", "ICD10-Z68.4", str(._TODAYSDATE), "", "")
ENDCOND
else ""
endif
}
Here is what I have with val() used around Patient._AGEINMONTHS and <1 month taken out. I also added a return result.
{! fn fnAGE(val(PATIENT._AGEINMONTHS)){
if val(PATIENT._AGEINMONTHS) <> "" then
COND
CASE val(PATIENT._AGEINMONTHS) >=1 and val(PATIENT._AGEINMONTHS) <12 result= "infant "
CASE val(PATIENT._AGEINMONTHS) >=12 and val(PATIENT._AGEINMONTHS) <120 result= "child "
CASE val(PATIENT._AGEINMONTHS) >=120 and val(PATIENT._AGEINMONTHS) <216 result= "adolescent"
CASE val(PATIENT._AGEINMONTHS)>=216 and val(PATIENT._AGEINMONTHS) <300 result= "young adult "
CASE val(PATIENT._AGEINMONTHS) >=300 and val(PATIENT._AGEINMONTHS) <480 result= "adult "
CASE val(PATIENT._AGEINMONTHS) >=480 and val(PATIENT._AGEINMONTHS) <720 result= "middle-aged adult "
CASE val(PATIENT._AGEINMONTHS) >=720 and val(PATIENT._AGEINMONTHS) <780 result= "late middle-aged adult "
CASE val(PATIENT._AGEINMONTHS) >=780 and val(PATIENT._AGEINMONTHS) <840 result= "early elderly adult "
CASE val(PATIENT._AGEINMONTHS) >=840 result= "elderly adult "
else result=""
endif
return result}}
Other changes to make? How do I use the function in text? Like this? "Well appearing fnAGE(Val(PATIENT._AGEINMONTHS)), alert no distress."
Does the function need {} around it or some other way to tell CPS to run and return the result of the function in the text? Thanks!
One thing, Christopher, that I noticed is that you do not have an "EndCond" statement prior to your "EndIf" statement.
{! fn fnAGE(val(PATIENT._AGEINMONTHS))} would probably be your calling statement from your data display field where as the code in the window on the right side would probably look something like:
fn fnAGE(numAgeMonths)
{if numAgeMonths <> "" then
COND
CASE numAgeMonths >=1 and numAgeMonths <12 result= "infant "
CASE numAgeMonths >=12 and numAgeMonths <120 result= "child "
CASE numAgeMonths >=120 and numAgeMonths <216 result= "adolescent"
CASE numAgeMonths>=216 and numAgeMonths <300 result= "young adult "
CASE numAgeMonths >=300 and numAgeMonths <480 result= "adult "
CASE numAgeMonths >=480 and numAgeMonths <720 result= "middle-aged adult "
CASE numAgeMonths >=720 and numAgeMonths <780 result= "late middle-aged adult "
CASE numAgeMonths >=780 and numAgeMonths <840 result= "early elderly adult "
CASE numAgeMonths >=840 result= "elderly adult "
else result=""
EndCond
endif
return result
}
at the very top of your function, where it says
{! fn fnAGE(val(PATIENT._AGEINMONTHS)){
You should either user a variable, like so: {! fn fnAGE(ageVar)}{..., or if you want to always use PATIENT._AGEINMONTHS in this function, you can even leave the parentheses empty {! fn fnAGE()}{...
As to your other question. to use the code in your text, it would look like this:
{"Well Appearing " + fnAge() + ", alert no distress"}
The function can olny be used in an area that allows MEL code to run.
Here is what I would build for the function, since it looks like you always want to use val(PATIENT._AGEINMONTHS) to calculate it out. (I fixed a few errors as well.)
{! fn fnAGE(){
result = ""
if val(PATIENT._AGEINMONTHS) <> "" then
COND
CASE val(PATIENT._AGEINMONTHS) >=1 and val(PATIENT._AGEINMONTHS) <12 result= "infant "
CASE val(PATIENT._AGEINMONTHS) >=12 and val(PATIENT._AGEINMONTHS) <120 result= "child "
CASE val(PATIENT._AGEINMONTHS) >=120 and val(PATIENT._AGEINMONTHS) <216 result= "adolescent"
CASE val(PATIENT._AGEINMONTHS)>=216 and val(PATIENT._AGEINMONTHS) <300 result= "young adult "
CASE val(PATIENT._AGEINMONTHS) >=300 and val(PATIENT._AGEINMONTHS) <480 result= "adult "
CASE val(PATIENT._AGEINMONTHS) >=480 and val(PATIENT._AGEINMONTHS) <720 result= "middle-aged adult "
CASE val(PATIENT._AGEINMONTHS) >=720 and val(PATIENT._AGEINMONTHS) <780 result= "late middle-aged adult "
CASE val(PATIENT._AGEINMONTHS) >=780 and val(PATIENT._AGEINMONTHS) <840 result= "early elderly adult "
CASE val(PATIENT._AGEINMONTHS) >=840 result= "elderly adult "
endcond
endif
return result}}
email me at [email protected] if you need more info on using functions. 🙂
Dan
I've got everything entered as listed above. Plugging the function into my "normal" button as a set value seems to break the button. It stops anything from resulting.
Do you know if a Set Value field in a button is an acceptable place to use MEL?
Thanks
Chris
The SetValues button can be used for mel code. I made a mistake in my code using the val MEL code. I corrected it and tested it to make sure it works. here is the working code.
{! fn fnAGE(){
result = ""
if (PATIENT._AGEINMONTHS) <> "" then
COND
CASE (PATIENT._AGEINMONTHS) >=1 and (PATIENT._AGEINMONTHS) <12 result= "infant "
CASE (PATIENT._AGEINMONTHS) >=12 and (PATIENT._AGEINMONTHS) <120 result= "child "
CASE (PATIENT._AGEINMONTHS) >=120 and (PATIENT._AGEINMONTHS) <216 result= "adolescent"
CASE (PATIENT._AGEINMONTHS)>=216 and (PATIENT._AGEINMONTHS) <300 result= "young adult "
CASE (PATIENT._AGEINMONTHS) >=300 and (PATIENT._AGEINMONTHS) <480 result= "adult "
CASE (PATIENT._AGEINMONTHS) >=480 and (PATIENT._AGEINMONTHS) <720 result= "middle-aged adult "
CASE (PATIENT._AGEINMONTHS) >=720 and (PATIENT._AGEINMONTHS) <780 result= "late middle-aged adult "
CASE (PATIENT._AGEINMONTHS) >=780 and (PATIENT._AGEINMONTHS) <840 result= "early elderly adult "
CASE (PATIENT._AGEINMONTHS) >=840 result= "elderly adult "
endcond
endif
return result}}
Inside of your Set Value button. you will need to enter the data like this:
{"Well appearing middle-aged obese " + fnAGE() + ", alert, no distress. Vitals reviewed."}
this will allow you to put text, and your function together, and it should give you the normal value you are looking for.
Please let me know if you run into any other issues.
Thank you,
Dan