Good morning CHUG land, it was just reported to me that the form we are using for our OB flowsheet is pulling in values from the previous pregnancy. I thought this had been fixed previously but our programmer who worked on that is no longer with us. Can someone look at this MEL code and let me know what I need to change? This particular patient delivered last around March 25,2013 and came in for her first prenatal visit on Sept 10, 2013. Here is the code:
{! /* OB Flowsheet Functions -- Comments restored Revision to allow for limited range of dates DAFN 22apr01 */}{ fn ExDate(value) { /* Extract the date of a returned VALUEDATE item. */ local v = value if v == "" then return "" endif while match(v,"(") > 0 do v=remove(v,1,match(v,"(")) endwhile /* found first character of date. Space is end of date, start of time. */ if (match(v," ") > 0) then v=remove(v,match(v," ")) endif /* Test the resulting string to see if it is a valid date. */ if durationdays("01/01/1900", v)==0 then return "" else return v endif }}{ fn ExValu(value) { /* Extract the value of a returned VALUEDATE item. */ local v = value if v == "" then return "" endif /* Last "(" in string is start of the date, end of value. Find position of last "(" */ local i = 0 while match(v,i+1,"(") > 0 do i=match(v,i+1,"(") endwhile v=remove(v,i) while v[size(v)] == " " do v=remove(v,size(v)) /* remove trailing blanks */ endwhile while v[1] == " " do v=remove(v,1,1) /* remove leading blanks */ endwhile return v }}{ /* Return an array list of dates on which a given observation was made. Modified to exclude dates before 'startdate' DAFN 15apr01 */ }{fn AllDates(obsterm) { local r = array() local l = getfield(LIST_OBS(obsterm,'SIGNED','LIST','VALUEDATE'),"\n","\r") if size(l) > 0 then if l[size(l)]=="" then remove(l,size(l)) endif endif /* remove trailing null entry if present */ if size(l) > 0 then local n for n=1, n<=size(l), n=n+1 do if durationdays(startdate, ExDate(l[n]))< 0 then break endif set(r, n, ExDate(l[n])) endfor endif return r }}{ fn InsDates(obsterm) { /* Insert into the dates array any dates when (obsterm) was recorded */ local d=copy(AllDates(obsterm)) local j=1 /* index pointer to array dates[] */ while size(d)>0 do /* Look for a matching date. If not found, insert it. */ cond case j>size(dates) /* reached end of array without a match; insert new item */ insert(dates, j, d[1]) remove(d,1) case durationdays(dates[j], d[1])>0 /* new item greater; insert before current */ insert(dates, j, d[1]) remove(d,1) j=j+1 case durationdays(dates[j], d[1])<0 /* old item greater; look farther */ j=j+1 else remove(d,1) /* dates are equal, no insert needed */ endcond endwhile return "" }}{ fn Valu(obsterm, dat) { /* Return value of an obsterm for a given date, if value exists. */ local a = getfield(LIST_OBS(obsterm,'SIGNED','LIST','VALUEDATE'),"\n","\r") while size(a) > 0 do if durationdays(ExDate(a[1]),dat)==0 then return ExValu(a[1]) else remove(a,1) endif endwhile return "" }}{ fn ad(index) { /* Return the date at position <index> in array, if item exists. */ if index > 0 and index <= size(dates) then return dates[index] else return "" endif }}{ fn av(obsterm, index, width) { /* Return the obsterm value corresponding to date array entry, if date exists. If width is present, limit to width characters. */ local value if index > 0 and index <= size(dates) then value=Valu(obsterm, dates[index]) else value="" endif if width == "" then return value else if width > 0 and size(value) > width then return remove(value,width+1) else return value endif endif }} {! fn calcweeks(EDC) { /* Calculate weeks gestation as of today given a date string for EDC Valid results are 0-44 wks If results are outside those limits, or no value for EDC, return "" DAFN 24apr01 Changed the display for duration to 6W2D etc. Updated ._todaysdate in the formula to DOCUMENT.CLINICALDATE D.Z. 7/5/2012 */ if durationdays("01/01/1900",EDC)==0 then return "" endif /* EDC is not a valid date */ local days=(durationdays(EDC,str(DOCUMENT.CLINICALDATE))+280) if days < 0 or days > 308 then return "" else return str(div(days,7))+"W"+str(mod(days,7))+"D" endif }} {fn fwd(obsterm) { /* If a prior value exists for an obs term, bring the old value forward into the current value for the item. */ if OBSNOW(obsterm)=="" and OBSANY(obsterm)<>"" then OBSNOW(obsterm, OBSANY(obsterm)) else "" endif } } {! if OBSNOW("GEST AGE EST")<>"" or OBSANY("EDC")=="" then "" else OBSNOW("GEST AGE EST", calcweeks(OBSANY("EDC"))) endif /* Compute Gestational Age at this visit using usrlib.txt functions. Only do if best estimate EDC has been assigned. */ global startdate = subtractdates(str(._TODAYSDATE),"1","0","0") if obsany("Last MP") <> "" and durationdays(startdate, obsany("Last MP")) > 0 then startdate=obsany("Last MP") else "" endif global dates = array() InsDates("GEST AGE EST") InsDates("FUNDAL HT CM") InsDates("FETAL HEART") InsDates("AMNIOTC LEAK") InsDates("BLD PREG YN") InsDates("FETAL MOVE") InsDates("N/V PREG")} { // !IF (OBSANY("Height")<>"")THEN !DOCUMENT.BODY_MASS_IN = str(CalcBMIConv(gHEIGHT,gHEIGHTPREV,gWEIGHT)) // OBSNOW("BMI",DOCUMENT.BODY_MASS_IN) // ENDIF } {fn CalcBMIConv(heightnow,heightprev,weightnow) { local heightval = "" cond case heightnow <> "" heightval = heightnow case heightprev <> "" heightval = heightprev else heightval = "" endcond if weightnow == "" or heightval == "" then return "" endif if heightval == 0 then return str(0) endif return str((weightnow / 2.2) / ((heightval / 39.4)^2)) }} /*Calculations for BMI & BSA Added by D.A.Z 01/17/2012.*/ { // !IF (OBSANY("Height")<>"")THEN !DOCUMENT.BODY_SURFACE = str(CalcBSAConv(gHEIGHT,gHEIGHTPREV,gWEIGHT)) // OBSNOW("BSA",DOCUMENT.BODY_SURFACE) // ENDIF } {global gHEIGHT = OBSNOW("Height") global gWEIGHT = OBSNOW("Weight") global gHEIGHTPREV = OBSPREV("Height")} { fn CalcBSAConv(heightnow,heightprev,weightnow) { local heightval = "" cond case heightnow <> "" heightval = heightnow case heightprev <> "" heightval = heightprev else heightval = "" endcond if weightnow == "" or heightval == "" then return "" endif return str(((weightnow /2.2) ^.425) * ((val(heightval)*2.54) ^.725) * (71.84/10000)) }} { fn checknullpreweight(){ local datessize = 0 datessize = size(dates) local preweight = 0 local preweight2 = 0 preweight = av("Weight",datessize) preweight2 = av("Weight",(datessize-1)) if (preweight > 0) then preweight else if (preweight2 > 0) then preweight = preweight2 else preweight = OBSNOW("Weight") endif endif return preweight } }
Thanks for any assistance you can give.
You have a lot going on here...
It looks it should filter out dates that are before a start date, determined by the either one year ago, or the obsterm "Last MP", whichever is later, can you check that and see if "Last MP" was updated for this patient?
Thank you so much. It was the Last MP that was the issue, since it hasn't been at least a year, it would be relying on the Last MP and the patient indicated she was sure of it so they just put 2013.
Thanks again.