How to compare dates in a IF statement in an Xlate

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How to compare dates in a IF statement in an Xlate

  • Creator
    Topic
  • #48133
    Pratibha Kavishwar
    Participant

      Is it possible to compare dates in an IF statement in an Xlate?

      e.g. I need to do the following

      If 0(0).MSH.00009.[0]   eq  =A08 &&  0(0).PV1.00175.[0]  <  200510020830         Then suppress ThankYou Pratibha

    Viewing 9 reply threads
    • Author
      Replies
      • #57777
        Dennis Pfeifer
        Participant

          may depend on the system, I don’t know about 64 bit systems ..

          but.. the value for ‘integer’ comparison should stay below

          2147483647

          so .. you probably could compare

          ccyymmddhh

          to compare dates, I take the left 8 characters, and then compare.

          Dennis

        • #57778
          Pratibha Kavishwar
          Participant

            I tried the 8 character as well, it does not work.

            Also i tried doing a string compare.

            0(0).MSH.00009.[0]   eq  =A08 && 0(0).PV1.00175.[0]   lt  20051002

            Did you mean i have to convert it into an integer value before i compare?

          • #57779
            Vince Angulo
            Participant

              I’d be interested in hearing about a simple solution for this.  Here at Children’s we’ve got (what I think) is a pretty complex workaround.  We have two tcl procs (IsDateOverLimit and IsDateUnderLimit) that we use to filter messages when Admit or Disch date is over or under some value (usually 60d or 90d).

              The procs accept the PV1-44/45 date values and the number of days we want to test for and return a true/false via XlateOutVals to a variable that we test in the IF statement.

              It’s functional if not elegant.

            • #57780
              Dennis Pfeifer
              Participant

                using copy

                and a pre TCL of

                set xlateOutVals

                  0 7]]

                  source

                  0(0).PV1.#45.[0]

                  destination

                  @dischargeDate

                  in your If statement

                  (0(0).MSH.#9.[1]  eq =A08) && (@dischargeDate < =20051002) — I don’t know the origin of 20051002 as a date .. but .. you may wish to assign it to a variable .. and use that in your if statement .. Dennis P.S. .. I prefer the ‘#’ notation instead of the item number .. It’s just me .. I know what PID-45 is .. I don’t know item 00175

                1. #57781
                  Dennis Pfeifer
                  Participant

                    You may wish to also include

                    && (@dischargeDate ne @null)

                    also .. thought of this ..

                    as long as the date/time strings are of the same length, you should be able to perform lt and gt on them .. but they must be of the same length ..

                    200510020830

                    will be less than (in strings)

                    200511090005

                    will be less than (in strings)

                    200511090010

                    as long as your dates/times are HL7 format .. then .. you should be ok for gt and lt comparison (and they are of the same length) ..

                    guess someone should fully test .. but I don’t see a hole at this time..

                    Dennis

                  • #57782
                    Pratibha Kavishwar
                    Participant

                      I tried putting the brackets in the IF condition seperating the 2, I tried copying into a viarable then comparing, it did’t work either.

                      The date lenght is the same on the comparison.

                      I need to have a fixed date there in the condition as we want to supress certain transaction updated before that date as they fail in the receiving system.

                      Thank You

                      Pratibha

                    • #57783
                      Dennis Pfeifer
                      Participant

                        Please post specific code..

                        I am not able to interpret your description.

                        Dennis

                      • #57784
                        Brian Goad
                        Participant

                          Dennis,

                          How would you compare the PV1:45 (Discahrge Date) to the current system date? Could this be done in an if statement?

                          I would think you would have to get the current clock time and convert that to format you want before doing your comparison.

                          Maybe something like this???

                          #get the system time in seconds

                          set curTime [clock seconds ]

                          # change the format of the time to YYYYMMDD

                          set newTime [clock format $curTime  -format {%Y%m%d}]

                          # this function gets the difference

                          set difference [expr {$newTime – $PV1_45}]

                          # setting the format to days only

                          set fmt “%d”

                          #reducing the difference to days

                          set curDif [clock format $difference -format $fmt]

                          #If the message was discharged more than 10 days ago

                          if {$curDiff < 10} Do what ever I have not tested this and am not sure it would work.  Also there may be a short way to make this happen. Brian

                        • #57785
                          Dennis Pfeifer
                          Participant

                            Yes, this would require TCL.

                            The original request was to test against a static date.

                            I haven’t tried to use @date and compare in an IF statement..

                            Dennis

                          • #57786
                            Rentian Huang
                            Participant

                              set difference [expr {$newTime – $PV1_45}]  will not work, ie 20060101 – 20051231 = 8870, which is not you really want.

                              you can do something like this:

                              1. strip only the first 8 charactors from PV1-45 into a variable, ie. 20051011 -> @dischDate

                              2. set diff [expr {([getclock] – [clock scan $dischDate])/86400}]  # 86400 sec per day

                              Now $diff will give you the actual number of day difference.

                              Sam   8)

                          Viewing 9 reply threads
                          • The forum ‘Cloverleaf’ is closed to new topics and replies.