Announcement

Collapse
No announcement yet.

channel to read data from sql in xml format and write file on file system

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • channel to read data from sql in xml format and write file on file system

    Good morning,
    i'm quite new to mirth, i have to create a channel to read data from database in XML format and write those data in a file under a specified file path and name.

    the channel source is reading the data correclty from the database but i'm always getting those error in the Server log dashboard:

    com.mirth.connect.connectors.jdbc.DatabaseReceiver : Failed to poll for messages from the database in channel "DeliveryDBReadChannel".

    most probably i'm missing something really stupid, but here in the forum and also online i cannot get the solution.

    hope that someone could help.


    the current javascript for the channel source is this:

    var dbConn;
    var xmlResult = java.util.ArrayList();
    importPackage(net.sf.json.xml);

    try {
    var pathOut = 'C:\\TEMP\\OUT\\';
    var fileNameOut = 'Out.xml';
    //GET DATABASE CONNECTION
    dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sql server://127.0.0.1;databaseName=XXXXX;','XXXXX','XXXXX');
    //CHECK IF THERE ARE NO FILES IN DESTINATION FOLDER
    try {
    LogMeSimple('20170807.1135', 'DEBUG', 'FILE PATH: ' + 'C:\\TEMP\\OUT\\Out.xml');
    var stringOut = FileUtil.read('C:\\TEMP\\OUT\\Out.xml');
    LogMeSimple('20170807.1135', 'DEBUG', 'FILE PATH: ' + 'C:\\TEMP\\OUT\\Out.xml' + ' file lenght: ' + stringOut.length().toString());
    if (stringOut.length() > 0)
    {
    LogMeSimple('20170807.1135', 'DEBUG', 'FILES FOUND! return ');
    return;
    }
    }
    catch ( ex )
    {
    LogMeSimple('20170807.1128', 'DEBUG', 'NO FILES FOUND! continue ');
    }
    //GET FIRST RING TO PROCESS
    try
    {
    var ring = dbConn.executeCachedQuery("SELECT TOP 1 [jbt_codering] FROM [ppmgr].[V_Jobs_Out_To_Cosmic_Related_Jobs_Out_To_First_To_ Process]");
    ring.next();
    var ringone = ring.getInt(1);
    LogMeSimple('20170804.1300', 'DEBUG', 'SELECT RING ' + java.util.Arrays.asList(ringone).toString());
    }
    catch (ex)
    {
    //if (!ring || !ringone || ringone <=0)

    LogMeSimple('20170807.1135', 'DEBUG', 'NO RING FOUND! return ');
    return ;
    }


    var params = parseInt(ringone);
    LogMeSimple('20170804.1302', 'DEBUG', 'CallSP ' + java.util.Arrays.asList(params).toString());
    var rowSet = executeCachedQuery2("EXEC ppdb_mgr.ppmgr.[ppsp_Jobs_Out_GetRingToSendXML_FHIR] ?", params);
    rowSet.next();

    var result = rowSet.getClob(1);
    var cloblenght = result.length();
    var xml = result.getSubString(1, cloblenght);
    LogMeSimple('20170804.1300', 'DEBUG', 'Clob Result: ' + XmlUtil.prettyPrint(xml));

    var InBoundXML = "";
    InBoundXML = new XML(xml);
    globalChannelMap.put('RingXML', InBoundXML);
    LogMeSimple('20170804.1320', 'DEBUG', 'InboundXML: ' + InBoundXML);

    FileUtil.write(pathOut + fileNameOut, true, XmlUtil.prettyPrint(InBoundXML));
    FileUtil.write(pathOut + fileNameOut, true, "\r\n");


    xmlResult.add(XmlUtil.prettyPrint(InBoundXML));



    } finally {
    if (dbConn) {
    dbConn.close();
    }

    channelMap.put(xmlResult);
    }



    this the output that is created from the log and in the folder, since the source reader is also writing the XML on the filesystem:

    <ProductionResult>
    <Dispenser>Swisslog</Dispenser>
    <BatchOrders>
    <Order>
    <MedicationRolls>
    <Roll code="SR2402">
    <Patient number="1308292709">
    <Name>Name Surname</Name>
    <Facility>451361000016008, SVS 651 senge afsnit</Facility>
    </Patient>
    <Pouches>
    <Pouch code="SP#1100262A00002D1">
    <PouchType type="5">Medication pouch</PouchType>
    <PassDate>30-06-2017</PassDate>
    <PassTime>20:00:00</PassTime>
    <Contents>
    <Content>
    <RequestedMedicine code="28103489103">Acetylsalicylsyre Hjertemagnyl 75 mg TABFILM</RequestedMedicine>
    <DispensedMedicine code="28103489103">Acetylsalicylsyre Hjertemagnyl 75 mg TABFILM</DispensedMedicine>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    <Content>
    <RequestedMedicine code="28104120007">Losartan Ancozan 50 mg TABFILM</RequestedMedicine>
    <DispensedMedicine code=""/>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    <Content>
    <RequestedMedicine code="28104249407">Amlodipin Amlodipin Teva 5 mg TAB</RequestedMedicine>
    <DispensedMedicine code="28104249407">Amlodipin Amlodipin Teva 5 mg TAB</DispensedMedicine>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    </Contents>
    </Pouch>
    <Pouch code="SP#1100229B00006E7">
    <PouchType type="5">Medication pouch</PouchType>
    <PassDate>30-06-2017</PassDate>
    <PassTime>22:00:00</PassTime>
    <Contents>
    <Content>
    <RequestedMedicine code="28103489103">Acetylsalicylsyre Hjertemagnyl 75 mg TABFILM</RequestedMedicine>
    <DispensedMedicine code="28103489103">Acetylsalicylsyre Hjertemagnyl 75 mg TABFILM</DispensedMedicine>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    <Content>
    <RequestedMedicine code="28104120007">Losartan Ancozan 50 mg TABFILM</RequestedMedicine>
    <DispensedMedicine code=""/>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    <Content>
    <RequestedMedicine code="28104249407">Amlodipin Amlodipin Teva 5 mg TAB</RequestedMedicine>
    <DispensedMedicine code="28104249407">Amlodipin Amlodipin Teva 5 mg TAB</DispensedMedicine>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    </Contents>
    </Pouch>
    <Pouch code="">
    <PouchType type="5">Medication pouch</PouchType>
    <PassDate>30-06-2017</PassDate>
    <PassTime>18:00:00</PassTime>
    <Contents>
    <Content>
    <RequestedMedicine code="28103489103">Acetylsalicylsyre Hjertemagnyl 75 mg TABFILM</RequestedMedicine>
    <DispensedMedicine code="28103489103">Acetylsalicylsyre Hjertemagnyl 75 mg TABFILM</DispensedMedicine>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    <Content>
    <RequestedMedicine code="28104120007">Losartan Ancozan 50 mg TABFILM</RequestedMedicine>
    <DispensedMedicine code=""/>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    <Content>
    <RequestedMedicine code="28104249407">Amlodipin Amlodipin Teva 5 mg TAB</RequestedMedicine>
    <DispensedMedicine code="28104249407">Amlodipin Amlodipin Teva 5 mg TAB</DispensedMedicine>
    <RequiredQuantity>1</RequiredQuantity>
    </Content>
    </Contents>
    </Pouch>
    </Pouches>
    </Roll>
    </MedicationRolls>
    </Order>
    </BatchOrders>
    </ProductionResult>

  • #2
    the mirth connect version is 3.4.2.8129.

    Comment


    • #3
      this is the export of the channel
      Attached Files

      Comment

      Working...
      X