UNPKG

n8n-nodes-feegow

Version:
541 lines 32.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Feegow = void 0; const n8n_workflow_1 = require("n8n-workflow"); const GenericFunctions_1 = require("./GenericFunctions"); class Feegow { constructor() { this.description = { displayName: 'Feegow Clinic', name: 'feegow', icon: 'file:feegow.svg', group: ['transform'], version: 1, description: 'Integração com a API Feegow', defaults: { name: 'Feegow' }, inputs: ["main"], outputs: ["main"], credentials: [{ name: 'feegowApi', required: true }], properties: [ { displayName: 'Recurso', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Agendamento', value: 'appointments' }, { name: 'Convênio', value: 'convenios' }, { name: 'Empresa', value: 'company' }, { name: 'Especialidade', value: 'specialties' }, { name: 'Paciente', value: 'patient' }, { name: 'Procedimento', value: 'procedures' }, { name: 'Profissional', value: 'professionals' }, ], default: 'patient', description: 'Selecione o recurso da API Feegow a ser utilizado', }, { displayName: 'Operação', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Atualizar Status De Agendamento', value: 'updateAppointmentStatus', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Buscar Paciente', value: 'searchPatient', displayOptions: { show: { resource: ['patient'] } } }, { name: 'Cancelar Agendamento', value: 'cancelAppointment', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Criar Novo Agendamento', value: 'createAppointment', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Criar Paciente', value: 'createPatient', displayOptions: { show: { resource: ['patient'] } } }, { name: 'Editar Paciente', value: 'editPatient', displayOptions: { show: { resource: ['patient'] } } }, { name: 'Listar Agendamentos Por Filtros', value: 'listAppointmentsByFilters', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Listar Canais De Agendamento', value: 'listAppointmentChannels', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Listar Convênios', value: 'listConvenios', displayOptions: { show: { resource: ['convenios'] } } }, { name: 'Listar Convênios Aceitos', value: 'listProfessionalInsurances', displayOptions: { show: { resource: ['professionals'] } } }, { name: 'Listar Convênios Do Procedimento', value: 'listProcedureInsurances', displayOptions: { show: { resource: ['procedures'] } } }, { name: 'Listar Especialidades', value: 'listSpecialties', displayOptions: { show: { resource: ['specialties'] } } }, { name: 'Listar Grupos De Procedimentos', value: 'listProcedureGroups', displayOptions: { show: { resource: ['procedures'] } } }, { name: 'Listar Horários Disponíveis', value: 'listAvailableSchedules', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Listar Locais', value: 'listLocals', displayOptions: { show: { resource: ['company'] } } }, { name: 'Listar Motivos De Reagendamento/Cancelamento', value: 'listAppointmentMotives', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Listar Pacientes', value: 'listPatients', displayOptions: { show: { resource: ['patient'] } } }, { name: 'Listar Pacotes', value: 'listBundles', displayOptions: { show: { resource: ['procedures'] } } }, { name: 'Listar Procedimentos', value: 'listProcedures', displayOptions: { show: { resource: ['procedures'] } } }, { name: 'Listar Procedimentos Importados Da Franquia', value: 'listImportedFranchiseProcedures', displayOptions: { show: { resource: ['procedures'] } } }, { name: 'Listar Profissionais', value: 'listProfessionals', displayOptions: { show: { resource: ['professionals'] } } }, { name: 'Listar Status De Agendamentos', value: 'listAppointmentStatuses', displayOptions: { show: { resource: ['appointments'] } } }, { name: 'Listar Tipos De Procedimentos', value: 'listProcedureTypes', displayOptions: { show: { resource: ['procedures'] } } }, { name: 'Listar Unidades', value: 'listUnities', displayOptions: { show: { resource: ['company'] } } }, { name: 'Obter Informações E Especialidades', value: 'searchProfessional', displayOptions: { show: { resource: ['professionals'] } } }, { name: 'Reagendar Agendamento', value: 'rescheduleAppointment', displayOptions: { show: { resource: ['appointments'] } } }, ], default: 'listPatients', description: 'Selecione a operação a ser realizada no recurso escolhido', }, { displayName: 'Dados De Cancelamento', name: 'cancel_data', type: 'collection', placeholder: 'Adicionar Dados', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['cancelAppointment'] } }, options: [ { displayName: 'Agendamento ID', name: 'agendamento_id', type: 'number', default: 0, description: 'ID do agendamento (obrigatório)' }, { displayName: 'Motivo ID', name: 'motivo_id', type: 'number', default: 0, description: 'ID do motivo de cancelamento (obrigatório)' }, { displayName: 'Observação', name: 'obs', type: 'string', default: '', description: 'Observação adicional (opcional)' }, ], }, { displayName: 'Dados Do Agendamento', name: 'appointment_data', type: 'collection', placeholder: 'Adicionar Dados', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['createAppointment'] } }, options: [ { displayName: 'Data', name: 'data', type: 'string', default: '', description: 'Data do agendamento (YYYY-MM-DD) (obrigatório)' }, { displayName: 'Hora', name: 'hora', type: 'string', default: '', description: 'Hora do agendamento (HH:MM) (obrigatório)' }, { displayName: 'Paciente ID', name: 'paciente_id', type: 'number', default: 0, description: 'ID do paciente (obrigatório)' }, { displayName: 'Procedimento ID', name: 'procedimento_id', type: 'number', default: 0, description: 'ID do procedimento (opcional)' }, { displayName: 'Profissional ID', name: 'profissional_id', type: 'number', default: 0, description: 'ID do profissional (obrigatório)' }, { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['listAppointmentChannels'] } }, options: [], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['listAppointmentsByFilters'] } }, options: [ { displayName: 'Data Fim', name: 'data_fim', type: 'string', default: '', description: 'Data final (YYYY-MM-DD) (opcional)' }, { displayName: 'Data Início', name: 'data_inicio', type: 'string', default: '', description: 'Data inicial (YYYY-MM-DD) (opcional)' }, { displayName: 'Profissional ID', name: 'profissional_id', type: 'number', default: 0, description: 'ID do profissional (opcional)' }, { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (opcional)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['listAvailableSchedules'] } }, options: [ { displayName: 'Data', name: 'data', type: 'string', default: '', description: 'Data (YYYY-MM-DD) (obrigatório)' }, { displayName: 'Profissional ID', name: 'profissional_id', type: 'number', default: 0, description: 'ID do profissional (obrigatório)' }, { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['listAppointmentMotives'] } }, options: [], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['listAppointmentStatuses'] } }, options: [ { displayName: 'Limite', name: 'limit', type: 'number', default: 50, typeOptions: { minValue: 1 }, description: 'Max number of results to return' }, { displayName: 'Offset', name: 'offset', type: 'number', default: 0, typeOptions: { minValue: 0 }, description: 'Número de registros a pular (opcional)' }, ], }, { displayName: 'Dados Do Status', name: 'status_data', type: 'collection', placeholder: 'Adicionar Dados', default: {}, displayOptions: { show: { resource: ['appointments'], operation: ['updateAppointmentStatus'] } }, options: [ { displayName: 'Agendamento ID', name: 'agendamento_id', type: 'number', default: 0, description: 'ID do agendamento (obrigatório)' }, { displayName: 'Hora De Chegada', name: 'hora_chegada', type: 'string', default: '', description: 'Hora de chegada (HH:MM) (opcional)' }, { displayName: 'Observação', name: 'obs', type: 'string', default: '', description: 'Observação adicional (opcional)' }, { displayName: 'Status ID', name: 'status_id', type: 'number', default: 0, description: 'Novo status ID (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['convenios'], operation: ['listConvenios'] } }, options: [ { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['company'], operation: ['listLocals'] } }, options: [ { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['company'], operation: ['listUnities'] } }, options: [ { displayName: 'CEP', name: 'cep', type: 'string', default: '', description: 'CEP para busca (opcional)' }, { displayName: 'Endereço', name: 'endereco', type: 'string', default: '', description: 'Endereço para busca (opcional)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['specialties'], operation: ['listSpecialties'] } }, options: [ { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (opcional)' }, ], }, { displayName: 'Dados Do Paciente', name: 'patient_data', type: 'collection', placeholder: 'Adicionar Dados', default: {}, displayOptions: { show: { resource: ['patient'], operation: ['createPatient'] } }, options: [ { displayName: 'CPF', name: 'cpf', type: 'string', default: '', description: 'CPF do paciente (obrigatório)' }, { displayName: 'Data De Nascimento', name: 'data_nascimento', type: 'string', default: '', description: 'Data de nascimento (YYYY-MM-DD) (opcional)' }, { displayName: 'Nome', name: 'nome', type: 'string', default: '', description: 'Nome do paciente (obrigatório)' }, { displayName: 'Telefone', name: 'telefone', type: 'string', default: '', description: 'Telefone do paciente (opcional)' }, ], }, { displayName: 'Dados Do Paciente', name: 'patient_data', type: 'collection', placeholder: 'Adicionar Dados', default: {}, displayOptions: { show: { resource: ['patient'], operation: ['editPatient'] } }, options: [ { displayName: 'Nome', name: 'nome', type: 'string', default: '', description: 'Nome do paciente (opcional)' }, { displayName: 'Paciente ID', name: 'paciente_id', type: 'number', default: 0, description: 'ID do paciente (obrigatório)' }, { displayName: 'Telefone', name: 'telefone', type: 'string', default: '', description: 'Telefone do paciente (opcional)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['patient'], operation: ['listPatients'] } }, options: [ { displayName: 'CPF', name: 'cpf', type: 'string', default: '', description: 'CPF do paciente (opcional)' }, { displayName: 'Limite', name: 'limit', type: 'number', default: 50, typeOptions: { minValue: 1 }, description: 'Max number of results to return' }, { displayName: 'Nome', name: 'nome', type: 'string', default: '', description: 'Nome do paciente (opcional)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['patient'], operation: ['searchPatient'] } }, options: [ { displayName: 'CPF', name: 'cpf', type: 'string', default: '', description: 'CPF do paciente (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['procedures'], operation: ['listBundles'] } }, options: [], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['procedures'], operation: ['listImportedFranchiseProcedures'] } }, options: [], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['procedures'], operation: ['listProcedureGroups'] } }, options: [], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['procedures'], operation: ['listProcedureInsurances'] } }, options: [ { displayName: 'Procedimento ID', name: 'procedimento_id', type: 'number', default: 0, description: 'ID do procedimento (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['procedures'], operation: ['listProcedureTypes'] } }, options: [], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['procedures'], operation: ['listProcedures'] } }, options: [ { displayName: 'Nome', name: 'nome', type: 'string', default: '', description: 'Nome do procedimento (opcional)' }, { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (obrigatório)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['professionals'], operation: ['listProfessionalInsurances'] } }, options: [], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['professionals'], operation: ['listProfessionals'] } }, options: [ { displayName: 'Especialidade ID', name: 'especialidade_id', type: 'number', default: 0, description: 'ID da especialidade (opcional)' }, { displayName: 'Unidade ID', name: 'unidade_id', type: 'number', default: 0, description: 'ID da unidade (opcional)' }, ], }, { displayName: 'Filtros', name: 'filters', type: 'collection', placeholder: 'Adicionar Filtro', default: {}, displayOptions: { show: { resource: ['professionals'], operation: ['searchProfessional'] } }, options: [ { displayName: 'Profissional ID', name: 'profissional_id', type: 'number', default: 0, description: 'ID do profissional (obrigatório)' }, ], }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const resource = this.getNodeParameter('resource', i); const operation = this.getNodeParameter('operation', i); let endpoint = ''; let body = {}; let qs = {}; try { switch (resource) { case 'appointments': switch (operation) { case 'listAppointmentStatuses': endpoint = '/api/appoints/status'; qs = this.getNodeParameter('filters', i); break; case 'updateAppointmentStatus': endpoint = '/api/appoints/statusUpdate'; const statusData = this.getNodeParameter('status_data', i); body = { agendamento_id: statusData.agendamento_id, status_id: statusData.status_id, obs: statusData.obs, hora_chegada: statusData.hora_chegada, }; break; case 'cancelAppointment': endpoint = '/api/appoints/cancel'; const cancelData = this.getNodeParameter('cancel_data', i); body = { agendamento_id: cancelData.agendamento_id, motivo_id: cancelData.motivo_id, obs: cancelData.obs, }; break; case 'createAppointment': endpoint = '/api/appoints/create'; const appointmentData = this.getNodeParameter('appointment_data', i); body = { paciente_id: appointmentData.paciente_id, profissional_id: appointmentData.profissional_id, data: appointmentData.data, hora: appointmentData.hora, unidade_id: appointmentData.unidade_id, procedimento_id: appointmentData.procedimento_id, }; break; case 'listAppointmentsByFilters': endpoint = '/api/appoints/list'; qs = this.getNodeParameter('filters', i); break; case 'listAppointmentChannels': endpoint = '/api/appoints/channels'; break; case 'listAvailableSchedules': endpoint = '/api/appoints/available-schedules'; qs = this.getNodeParameter('filters', i); break; case 'listAppointmentMotives': endpoint = '/api/appoints/motives'; break; case 'rescheduleAppointment': endpoint = '/api/appoints/reschedule'; const rescheduleData = this.getNodeParameter('appointment_data', i); body = { agendamento_id: rescheduleData.agendamento_id, data: rescheduleData.data, hora: rescheduleData.hora, }; break; } break; case 'convenios': if (operation === 'listConvenios') { endpoint = '/api/insurance/list'; qs = this.getNodeParameter('filters', i); } break; case 'company': if (operation === 'listUnities') { endpoint = '/api/company/list-unity'; qs = this.getNodeParameter('filters', i); } else if (operation === 'listLocals') { endpoint = '/api/company/list-local'; qs = this.getNodeParameter('filters', i); } break; case 'specialties': if (operation === 'listSpecialties') { endpoint = '/api/specialties/list'; qs = this.getNodeParameter('filters', i); } break; case 'patient': switch (operation) { case 'searchPatient': endpoint = '/api/patient/search'; qs = this.getNodeParameter('filters', i); break; case 'createPatient': endpoint = '/api/patient/create'; const createPatientData = this.getNodeParameter('patient_data', i); body = { nome: createPatientData.nome, cpf: createPatientData.cpf, data_nascimento: createPatientData.data_nascimento, telefone: createPatientData.telefone, }; break; case 'editPatient': endpoint = '/api/patient/edit'; const editPatientData = this.getNodeParameter('patient_data', i); body = { paciente_id: editPatientData.paciente_id, nome: editPatientData.nome, telefone: editPatientData.telefone, }; break; case 'listPatients': endpoint = '/api/patient/list'; qs = this.getNodeParameter('filters', i); break; } break; case 'procedures': switch (operation) { case 'listBundles': endpoint = '/api/procedures/bundles'; break; case 'listImportedFranchiseProcedures': endpoint = '/api/procedures/imported-franchise'; break; case 'listProcedureGroups': endpoint = '/api/procedures/groups'; break; case 'listProcedureInsurances': endpoint = '/api/procedures/insurances'; qs = this.getNodeParameter('filters', i); break; case 'listProcedureTypes': endpoint = '/api/procedures/types'; break; case 'listProcedures': endpoint = '/api/procedures/list'; qs = this.getNodeParameter('filters', i); break; } break; case 'professionals': switch (operation) { case 'listProfessionalInsurances': endpoint = '/api/professionals/insurances'; qs = this.getNodeParameter('filters', i); break; case 'listProfessionals': endpoint = '/api/professionals/list'; qs = this.getNodeParameter('filters', i); break; case 'searchProfessional': endpoint = '/api/professionals/search'; qs = this.getNodeParameter('filters', i); break; } break; } const response = await GenericFunctions_1.feegowRequest.call(this, Object.keys(body).length > 0 ? 'POST' : 'GET', endpoint, body, qs); returnData.push({ json: response }); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Erro na operação ${operation} para ${resource}: ${error.message}`); } } return [returnData]; } } exports.Feegow = Feegow; //# sourceMappingURL=Feegow.node.js.map