var G_ROBO_WS_SERVICE = "ws://localhost:6026";

var g_robo_cln_socket = new WebSocket(G_ROBO_WS_SERVICE);
var g_robo_cln_printer_ready = false;
var g_robo_cln_socket = new WebSocket(G_ROBO_WS_SERVICE);
g_robo_cln_socket.onmessage = function(msg) {
};
g_robo_cln_socket.onopen = function() {

};
g_robo_cln_socket.onerror = function(msg) {

};

function one_print_robo(inp) {
   g_robo_cln_socket = new WebSocket(G_ROBO_WS_SERVICE);
   axios.get('/one-api/v1/su/barcode/pk',{
      params: {barcodeId: inp}
   })
   .then( function(resp) {
      if (resp.data.status == "OK") {
         var data_print = {};
         for(var i=0; i < resp.data.rows.length ; i++) {
            var r = resp.data.rows[i];
            if (i==0) {
               data_print = {
                  type : "robo",
                  name : r.M_PatientName,
                  age  : r.T_OrderHeaderM_PatientAge,
                  date : r.T_OrderHeaderDate,
                  regno : r.T_OrderHeaderLabNumber,
                  sex : r.Sex,
                  pid: r.M_PatientNoReg,
                  data : []
               };
            }
            data_print.data.push( {
               sample: r.T_SampleTypeName,
               no : r.T_BarcodeLabBarcode,
               code : r.T_SampleTypeSuffix
            });
         }
         g_robo_cln_socket.send(JSON.stringify(data_print));
      } else {
         console.log("ERR", resp.data);
      }
   })
   .catch( function(e) {
      console.log('Err Get Barcode', e);
   })
}



window.one_print_robo = one_print_robo;
