Global Variable in XLATE

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Global Variable in XLATE

  • Creator
    Topic
  • #54653
    Jon Melin
    Participant

    Hello,

    I am attempting to consume a csv through a VRL, and output a VRL message. I am using an XLATE to make a couple really quick modifications to that data and add some static values to some of the outbound VRL fields. This works just fine.

    My problem is the header of the file, which I remove (ignore) at the beginning of the XLATE (just suppress that new line), contains a file date and I need to insert into the outbound date field in the outbound VRL. It’s the same date into the same spot in every new line coming from the source file, but the date only appears in the header. Any idea how I can get this variable to be usable for each new line so that I can insert it into all the new lines out?

    Attached is a very basic image of the inbound data structure, and where the date is. The top 3 lines are header info that I remove, I did store the date into a variable, but it’s only usable when I’m on that new line and not for the rest. The last 2 lines in this example are [example] new lines I need to forward, with the date in each one (plus many other static values via the xlate). Could be any number of new lines in the inbound file. Everything but the date variable is working great. Please let me know if you have any suggestions. I’m assuming I am missing something simple here.

    Thank you,

    Jon

Viewing 8 reply threads
  • Author
    Replies
    • #82428
      Jim Kosloskey
      Participant

      You could define the file as a HRL  where there are 3 VRLs to define the three leading (header) records and one VRL defined for the CLINIC.

      In the HRL then specify the CLINIC VRL as repeating while the first field contains the value CLINIC.

      Then all of the data will be available to your Xlate and you can use the header data any way you want. You might need to do a CONTINUE to cut out multiple messages or define another VRL for your outbound – we don’t have much information about your outbound.

      Another potential solution is to use a Pre-Xlate proc to store the data you want in a global Tcl variiable, then in another Xlate proc inside the Xlate get that global and use it. It hass been a long time since I have done this and in the newer versions of Cloverleaf I think you need to be careful to always assure the pre-xlate and Xlate use the same interpreter.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #82429
      Charlie Bursell
      Participant

      I have not looked at the entire problem ut one thing to remember is all variables, by definition are global in the Xlate engine.

      You could do this at the top of the translate:

      set date

      Then date will be available to all subsequent  statements

      If you wanted the same variable across many Xlates you would do something like:

      if {![info exists date]} {set date }

      I normally set aside a Xlate statement just for this.  Simply copy @ null to @null

    • #82430
      Jon Melin
      Participant

      Thank you both for the responses.

      Jim,

      To answer your question, the outbound is just tab separated VRL that takes data from the inbound and places it in the correct locations to be consumed by the destination system. Nothing fancy at all, just a line at a time writing to a tab separated file, 1 to 1, so one output for each input (after the headers) I can try the HRL, but I’ve never worked with them before.

      Charlie,

      To answer your question, it is global to the XLATE yes, but each time a line comes in from the source file, it starts the XLATE process over, since I’ve obtained the date in a previous new line from the source, it doesn’t seem to carry over to the next lines, as in the variable is empty after I’ve grabbed it from the header and moved on to the next file line. It is available for all subsequent statements during the time i’m working with the header line item, and not after the next line comes in from the file.

      In your example, how would I be able to {set date } when that variable appears to be blank when the next line comes in? Maybe I’m not understanding.

      Thank you,

      Jon

    • #82431
      Charlie Bursell
      Participant

      I think it is me that is not understanding.

      Are you doing this all in one Xlate instance or does each line require a different Xlate instance?

      Any variable you set in Xlate should still be available anywhere in the Xlate.

    • #82432
      Jon Melin
      Participant

      Charlie,

      I read in a line at a time from the inbound file, so I thought it was a separate instance each time. When I echo the variable it only shows up for the new line coming in that the date is present, otherwise it is blank for the remaining lines in the inbound file, when I try to send it to the outbound VRL.

      So when I encounter that piece in the header, it’s visible, any line after that it’s blank. I am not assigning @null to the variable afterward so I assumed it was a separate instance.  

      Thank you,

      jon

    • #82433
      Charlie Bursell
      Participant

      Still confused Jon  ðŸ™‚

      Where are you trying to do this?  I thought it was in Xlate.  Are you just sending one line at a time through Xlate?

      Can you give us an idea of the flow from IB to OB?

    • #82434
      Jim Kosloskey
      Participant

      Jon,

      Re HRL – maybe a good time to refine a new skill  ðŸ™‚

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #82435
      Jon Melin
      Participant

      Jim,

      I plan on spending some time this afternoon and taking a look. Good idea 🙂

      Charlie,

      I am doing it inside of an XLATE yes. Maybe I was trying to over simplify it. Using the screenshot I provided before I essentially need to strip off the top 3 lines of the file, and process any line after that, but in the middle header line that I strip, I need to grab that date and reuse it for every tab separated VRL message I send outbound.

      I’ve included a screenshot of the simple XLATE I was trying to use. It does obtain the date when it strips the 2nd header line, but it’s gone when it processes any other line.

      I’ve also included a screenshot of the echo statements. I set it to echo at the first copy statement (which is below the suppress in the other screenshot) and you can see it echos out when I capture it in the 2nd header, and never again, like it was reset or blanked. I don’t think I can do what I am trying to do without another step, such as the recommended HRL, I was just thinking maybe someone knew a quick and easy solution.

      Thank you,

      Jon

    • #82436
      Charlie Bursell
      Participant

      @filedate is not a global variable.  However it should stay set throughout the Xlate unless changed.  When I spoke of global variables, I was speaking of Tcl variables.

      I don’t think Jim or I either one could do much more without the Xlate and test data.

      If you are considering HRL for input let me suggest setting up an HL7 variant instead and normalize the input data to HL7.

      HRL is OK for output but can be a real pain on input if you have repeating and/or optional segments

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

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,293
Replies
34,435
Topic Tags
286
Empty Topic Tags
10