Generate xlt using javascript

Homepage Clovertech Forums Cloverleaf Generate xlt using javascript

  • Creator
    Topic
  • #120877
    Doug Haskins
    Participant

    I am new to cloverleaf. Muddling through translations. I find when it gets complicated, I do not know tcl at all and want to move everything over to javascript. If I create a simple entry using tcl and save it, I end up with this

    prologue
    xlt_infile: hl7 2.3 ORM
    who: Doug
    date: October 3, 2023 5:41:58 PM PDT
    xlt_outfile: hl7 2.3 ORM
    type: xlt
    version: 7.0
    end_prologue

    { { OP BULKCOPY }
    { ERR 0 }
    }
    { { OP COPY }
    { ERR 0 }
    { IN {{2(0).1(0).0(0).OBR(0).#2(0).[0]}} }
    { OUT {{2(0).1(0).0(0).OBR(0).#3(0).[0]}} }
    }

    How would this look as a .js file? Is it still a .xlt and maybe it has js for type? or is it saved as .js?

    I can’t seem to find any documentation on using javascript, or any examples, if someone can point me in the right direction.

    If I can sort out the format for an .xlt as javascript, then next item is how to get the incoming message to manipulate.. is it $msg or something? I have my own parser I can use for field ID’s, just need to know the layout.

    Anyone doing this?

    Thanks.

    Doug.

Viewing 9 reply threads
  • Author
    Replies
    • #120878
      Jim Kosloskey
      Participant

      I am really struggling to understand why you would want to do this.

      The Xlate is not that difficult to understand (ITERATE can be a struggle, but I have a class for that).

      Many of us on this forum are willing to help you with Xlate. Have you been to Level 1 training?

       

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

    • #120879
      Doug Haskins
      Participant

      I have had about 4 hours training so far. Next course begins in November, but my company is moving ahead with Cloverleaf now so I am getting my boots dirty. I have a lot of js code ready to go, just need to know how to implement it.

    • #120880
      Jim Kosloskey
      Participant

      The Xlate Configurator tool is designed to build the .xlt files.

      The Xlate tool also has a debugger.

      If you email me I am willing to chat with you (maybe even do a desktop share) to help you get comfortable with the Xlate tool.

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

    • #120881
      Doug Haskins
      Participant

      The problem I have is that tcl in the GUI is somewhat handicapped without a switch statement. Is there something similar?

      I tried using IF Else, but it ends up with this massive amount of code that is much easier orchestrated using javascript.

      tcl

      { { OP IF }
      { ERR 0 }
      { COND { 0(0).MSH(0).#4(0).[0] eq =”A”} }
      { THENBODY {
      { { OP COPY }
      { ERR 0 }
      { IN =”XR” }
      { OUT {{2(0).1(0).0(0).OBR(0).#24(0).[0]}} }
      }
      }}
      { ELSEBODY {
      { { OP IF }
      { ERR 0 }
      { COND { 0(0).MSH(0).#4(0).[0] eq =”B”} }
      { THENBODY {
      { { OP COPY }
      { ERR 0 }
      { IN =”CR” }
      { OUT {{2(0).1(0).0(0).OBR(0).#24(0).[0]}} }
      }
      }}
      { ELSEBODY {
      { { OP COPY }
      { ERR 0 }
      { IN =”OT” }
      { OUT {{2(0).1(0).0(0).OBR(0).#24(0).[0]}} }
      }
      }}
      }
      }}

      javascript

      switch (msh4) {
      case “A”:
      obr24 = “XR”;
      break;
      case “B”:
      obr24 = “CR”
      break;
      default:
      obr24 = “OT”;
      }

      Is there a way to handle a pick list with tcl in the GUI?

    • #120882
      Jim Vilbrandt
      Participant

      Hi Doug,

      XLate scripts are not TCL. But you can include TCL scripts and snippets in an XLate. Either within a Call or Pre/Post Proc steps. XLates do not support a CASE/SWITCH statement, but TCL does have a SWITCH. When I need a SWITCH, I often put this logic in Call.

      I have not implemented Java Script yet, as we need to upgrade our Cloverleaf machine first. Rob Abbot presented last week in Fulda, Germany that the latest version of Cloverleaf also supports Python.

      Best Regards from Berlin, Jim

    • #120883
      Jim Kosloskey
      Participant

      Oh, I did not understand you wanted to extend Xlate with Java(normally Tcl).

      A TABLE Xlate Action may provide a solution here. Without the need for any other language (Tcl, Java, or ???).

      Based on what you have described, the Table would have one side (say the left side) have the values ‘A’ and ‘B’, the corresponding right side have the values ‘XR’ and ‘CR’ respectively with the default being ‘OT’. Kind of like this:

      A XR

      B CR

      Default=’OT’

      Then in the Xlate TABLE Action, you would select your Table and, in the Source, put the MSH address path, in the Destination put the OBR Address Path.

      When the MSH value is A you would get XR in the OBR, when the MSH value is B you would get CR in the OBR, when there is no match, you would get ‘OT’ in the OBR.

      No need, in this case for any extension in any language. It can be handled natively within the Xlate and the Table Configuration Tool.

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

    • #120887
      Doug Haskins
      Participant

      That is interesting. I gave it a go, but of course did something wrong. I opened excel and added A to one column and XR to the second, along with a few more, then saved it as .xlsx, which was the only option for their web version.

      I ran it through a converter to change it to a .csv file, and then renamed it to .tbl and moved it into the Xlate folder.

      In Cloverleaf, I selected the FROM and TO pieces, and put the name of that file under Table, but when I saved and ran the testing tool it failed.

      Is there a way to create this table without using excel? Does script editor help with this?

    • #120888
      Jim Kosloskey
      Participant

      Doug,

       

      In the GUI, Under Configuration, there is a ‘Lookup Table’ Tool. In that tool you build your Table.

      If you would like, I am willing to do a shared desktop session with you to walk you through this (and we can discuss any Xlate or Cloverleaf topics you would like).

      Just email me so we can this taken care of.

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

    • #120889
      Doug Haskins
      Participant

      When I hovered over the table open icon in the table tool I noticed it said lookup table, and then discovered the Lookup Table Configurator. lol.

      It is working now.

      It is a bit clunky, but works. It would be way quicker with javascript. Maybe there are tricks to populate that? Looks like I could open it in notepad and copy and paste if I had a lot of entries.

      Is that lookup table icon supposed to do something? it seems to be grayed out.

      • #120891
        Jim Kosloskey
        Participant

        I have a Tcl proc that will build a lookup table from a csv file. You can have that if you want. Just email me. It was written a while ago but seems to build a Table which can be used in the latest release I have access to (2022.09).

        Also, in later releases of Cloverleaf the Lookup Table can reference a DB. What release of Cloverleaf are you on?

        The grayed out icon you are referencing, are you seeing that in the Xlate Tool?

        The value of using the toolset where it can do the work is so that things are exposed to the IE rather than hidden in some level of code. There are times when the toolset really needs to be extended and that is why the UPoCs at various places exist.

        Cloverleaf is a very powerful toolset and part of what makes it powerful is its extensibility. With that potential comes some level of complexity. A 4-hour training, in my opinion, is insufficient to even begin to use the tool properly.

        I think the Level 1 course is still a full 3.5 day course (and there are 2 more levels). Heck, my ITERATE focused class is 3 full days!

        I am glad you have this working.

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

    • #120890
      Doug Haskins
      Participant

      Hi Doug, XLate scripts are not TCL. But you can include TCL scripts and snippets in an XLate. Either within a Call or Pre/Post Proc steps. XLates do not support a CASE/SWITCH statement, but TCL does have a SWITCH. When I need a SWITCH, I often put this logic in Call. I have not implemented Java Script yet, as we need to upgrade our Cloverleaf machine first. Rob Abbot presented last week in Fulda, Germany that the latest version of Cloverleaf also supports Python. Best Regards from Berlin, Jim

      Can you explain how you would use Call to handle a SWITCH? Lots of interesting concepts in this product.

Viewing 9 reply threads
  • You must be logged in to reply to this topic.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10