AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.216.192
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_apps/leve/application/plugins/module_med_scheduling/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/leve/application/plugins/module_med_scheduling/assets/js/usb_printer.js
var device;
    
function setup(device) {
        return device.open()
        .then(() => device.selectConfiguration(1))
        .then(() => device.claimInterface(0))
}

function printUsb(copies,id) {
    
        // Pego os dados do paciente
        $.ajax({
            type: 'POST',
            url: $("#_url").val() + "module_med_scheduling/scheduling/schedulingInfo/",
            data: {'id' : id},
            dataType: 'html'
        }).done(function (data) 
        {
//            console.log(data);
            var obj = JSON.parse(data);    
            console.log(obj);
            
            /// ###### Verifico a AGENDA e envio para o sistema de Laudos #####
            // TODO: isto vale apenas para a CEDDI que tem servidor PACS
//            if(obj.diary_id == 2 || obj.diary_id == 5)
//            {
//                var tipo_exame = '';
//                if(obj.diary_id == 2)
//                {
//                    tipo_exame = 'ENDOSCOPIA';
//                }
//                else
//                {
//                    tipo_exame = 'DENSITOMETRIA';
//                }
//                var arr_data = {
//                    'firstname' : '',
//                    'lastname' : obj.patients.account.toUpperCase(),
//                    'id' : obj.id,
//                    'appt_date' : obj.date+' '+obj.hour_start,
//                    'dob' : obj.patients.date_of_birth,
//                    'study_uid' : obj.date+'_'+obj.patients.id+'_'+obj.id,
//                    'study_desc' : obj.study_desc,
//                    'tipo_exame' : tipo_exame,
//                    'sent_from_ae' : 'HEALTH ERP'
//                };
//                $.post("https://177.11.165.11/index.php?option=com_sync&view=api&layout=estudos&token=KUDJNGM83YHF83745JGFMKMKLNKJDFAS7433KJ2", arr_data)
//                .done(function (data) 
//                {
//                    console.log(data);
//                });
//            }
            
            /// ######TRATAMENTO DOS DADOS PARA IMPRESSÃO #####
            
            // Dados do Paciente
            var name_aux = removerAcentos(obj.patients.account);
            var name = name_aux.toUpperCase().substring(0, 25);
            var prontuario = obj.patients.id;
            var idade = obj.patients.age;
            
            // data da consulta
            var data_aux = obj.date.split('-');
            var data = data_aux[2]+'/'+data_aux[1]+'/'+data_aux[0];
            
            // convenio
            var convenio = obj.agreements.agreement_company_name.toUpperCase().substring(0, 20);
            convenio = removerAcentos(convenio);

            // Pego o solicitante
            var solicitante = 'POR DR: PROCURA DIRETA';
            if(obj.requester != null)
            {
                var sex = '';
                if(obj.requester.sex == 'f')
                {
                    sex = 'A';
                }
                solicitante = 'POR DR'+sex+': '+obj.requester.account.toUpperCase().substring(0, 30);
            }
            solicitante = removerAcentos(solicitante);
            
            // Pego o solicitante
            var professional = '';
            if(obj.professional != null)
            {
                var sex = '';
                if(obj.professional.sex == 'f')
                {
                    sex = 'A';
                }
                professional = 'DR'+sex+': '+obj.professional.account.toUpperCase().substring(0, 30)+'    ';
            }
            professional = removerAcentos(professional);
            
            // Dados do Exame
            var valor_aux = 0;
            var exame_aux = '';
            obj.items.forEach(function(item)
            {
                valor_aux += (parseFloat(item.value_patient) - parseFloat(item.discount)) * item.qty;
                exame_aux += item.name.toUpperCase() + ' - ';
            });
            
            exame_aux = exame_aux.substring(0, exame_aux.length - 3);
            var exame = exame_aux.substring(0, 30);
            exame = removerAcentos(exame);
            
            var valor = '';
            if(valor_aux.toFixed(2) > 0)
            {
                valor = '    VALOR: R$ '+valor_aux.toFixed(2);
            }
            
            // Verifico qual é a agenda
            var diary = '';
            switch (obj.diary_id) {
              case '1':
                diary = 'U';
                break;
              case '2':
                diary = 'G'
                break;
              case '3':
                diary = 'R'
                break;
              case '5':
                diary = 'D'
                break;
            }
            
            if(obj.urgency == 'Y')
            {
                diary = 'E';
            }
            
            
            // PARAMETROS DE CONTROLE PARA IMPRESSÃO
            var STX = '\x02';
            var CR = '\x0D';
            var ESC = '\X1B';
                
            // IMPRIMO AS ETIQUETAS COM VALOR
            if(copies > 2)
            {
                copies_aux = parseFloat(copies) - 2;
                console.log(copies_aux);


    //                    var string = STX+'Q'+CR;
                var string = STX+'KI<7';
//                string += STX+'KI70x01'+CR;
//                string += STX+'e'+CR;
//                string += STX+'j'+CR;
                string += STX+'m'+CR;
                string += STX+'M0300'+CR;
        //                string += STX+'V1'+CR;
                string += STX+'L'+CR;
                string += 'D11'+CR;
                string += 'H12'+CR;
                string += '190000202000060NOME: '+name+CR;
                if(obj.queue_number != null)
                {
                    string += '190000401500720SENHA: '+diary+obj.queue_number+CR;
                }
                string += '190000202000840N: '+prontuario+CR;
                string += '190000201500060EXAME:'+exame+CR;
                string += '190000201000060'+professional+solicitante+CR;
                string += '190000200500060DATA: '+data+'    CONV: '+convenio+CR;
                string += '190000200500700'+valor+CR;
                string += 'Q000'+copies_aux+CR;
                string += 'E'+CR;
//                string += STX+'f320'+CR;
    //            string += STX+'E000'+copies+CR;
    //            string += STX+'G'+CR;
                string += STX+'Q'+CR;


        //                string = STX+'T';
        
                var encoder = new TextEncoder();
                var data_send = encoder.encode(string);
                device.open()
                .then(() => device.selectConfiguration(1))
                .then(() => device.claimInterface(1))
                device.transferOut(1, data_send)
                .then(teste => console.log(teste))
                .catch(error => { console.log(error); })
            }
            
            
            // IMPRIMO A PRIMEIRA ETIQUETA SEM VALOR
            var copies_aux = 1;
            if(copies >=2)
            {
                copies_aux = 2;
            }
            var string = STX+'KI<7';
//            string += STX+'KI70x01'+CR;
//            string += STX+'e'+CR;
//            string += STX+'j'+CR;
            string += STX+'m'+CR;
            string += STX+'M0300'+CR;
            string += STX+'L'+CR;
            string += 'D11'+CR;
            string += '190000202000060NOME: '+name+CR;
            console.log(obj.queue_number);
            if(obj.queue_number != null)
            {
                string += '190000401500720SENHA: '+diary+obj.queue_number+CR;
            }
            string += '190000202000840N: '+prontuario+CR;
            string += '190000201500060EXAME: '+exame+CR;
            string += '190000201000060'+professional+solicitante+CR;
            string += '190000200500060DATA: '+data+'    CONV: '+convenio+CR;
            string += 'Q000'+copies_aux+CR;
            string += 'E'+CR;
            string += STX+'f810'+CR;
            string += STX+'Q'+CR;
//            string += STX+'G'+CR;


    //                string = STX+'T';


            var encoder = new TextEncoder();
            var data = encoder.encode(string);
            device.open()
            .then(() => device.selectConfiguration(1))
            .then(() => device.claimInterface(1))
            device.transferOut(1, data)
            .then(teste => console.log(teste))
            .catch(error => { console.log(error); })
            console.log(string);
            
        });
}

function connectAndPrint(copies,id) 
{
//    printUsb(copies, id);
    if (device == null) 
    {
        navigator.usb.requestDevice({ filters: [{ vendorId: 0x1664 }] })			
        .then(selectedDevice => {
                device = selectedDevice;
                console.log(device);
                return setup(device);
        })
        .then(() => printUsb(copies, id))
        .catch(error => { console.log(error); })
    }
    else
    {
            printUsb(copies, id);
    }
}


//function verifyPrinter() {
//    
//        
//    if (device == null) 
//    {
//        navigator.usb.requestDevice({ filters: [{ vendorId: 0x1664 }] })			
//        .then(selectedDevice => {
//                device = selectedDevice;
//                console.log(device);
//                return setup(device);
//        })
//        .catch(error => { console.log(error); })
//    }
//    else
//    {
//        console.log('SELECIONADO');
//    }
//}


navigator.usb.getDevices()
.then(devices => {
        if (devices.length > 0) {
                device = devices[0];
                return setup(device);
        }
        console.log(devices);
})
.catch(error => { console.log(error); });


function removerAcentos( newStringComAcento ) {
    var string = newStringComAcento;
    var mapaAcentosHex 	= {
        a : /[\xE0-\xE6]/g,
        A : /[\xC0-\xC6]/g,
        e : /[\xE8-\xEB]/g,
        E : /[\xC8-\xCB]/g,
        i : /[\xEC-\xEF]/g,
        I : /[\xCC-\xCF]/g,
        o : /[\xF2-\xF6]/g,
        O : /[\xD2-\xD6]/g,
        u : /[\xF9-\xFC]/g,
        U : /[\xD9-\xDC]/g,
        c : /\xE7/g,
        C : /\xC7/g,
        n : /\xF1/g,
        N : /\xD1/g
    };

    for ( var letra in mapaAcentosHex ) {
        var expressaoRegular = mapaAcentosHex[letra];
        string = string.replace( expressaoRegular, letra );
    }

    return string;
}

Anon7 - 2022
AnonSec Team