feat(pacientes): sync de pacientes Firebird → WhatsApp Lab
- Nuevo servicio whatsapp_sync.py: mapeo de campos RIPS→lab_pacientes y cliente HTTP para /api/lab/ingest_paciente.php - Nueva ruta /pacientes con sync masiva por rango de fechas o todos - Hook en /terceros/send y /automation/run: sync silencioso a WhatsApp después de cada envío a TNS - Config: campos whatsapp_url y whatsapp_api_key + botón probar conexión Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b4288ac899
commit
e7c6bc794a
@@ -154,6 +154,39 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="border-gray-200">
|
||||
|
||||
<h4 class="font-medium text-gray-800">
|
||||
<i class="fab fa-whatsapp mr-2 text-green-500"></i>WhatsApp Lab — Ingesta de Pacientes
|
||||
</h4>
|
||||
<p class="text-xs text-gray-500 -mt-2">
|
||||
URL base del sistema WhatsApp Lab. Los pacientes de RIPS se sincronizarán a
|
||||
<code class="bg-gray-100 px-1 rounded">/api/lab/ingest_paciente.php</code>.
|
||||
</p>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">URL WhatsApp Lab</label>
|
||||
<input type="text" name="config_whatsapp_url"
|
||||
value="{{ configs|selectattr('key', 'equalto', 'whatsapp_url')|map(attribute='value')|first|default('') }}"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm"
|
||||
placeholder="Ej: https://lab.ximena.com.co">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">API Key (X-Lab-Key)</label>
|
||||
<input type="text" name="config_whatsapp_api_key"
|
||||
value="{{ configs|selectattr('key', 'equalto', 'whatsapp_api_key')|map(attribute='value')|first|default('rips-lab-sync-2026') }}"
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm"
|
||||
placeholder="rips-lab-sync-2026">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" onclick="testWhatsapp()"
|
||||
class="px-4 py-2 bg-green-50 text-green-700 border border-green-200 rounded-lg hover:bg-green-100 text-sm font-medium">
|
||||
<i class="fab fa-whatsapp mr-1"></i> Probar conexión
|
||||
</button>
|
||||
<span id="wa-status" class="text-sm ml-3"></span>
|
||||
</div>
|
||||
|
||||
<button type="submit"
|
||||
class="px-6 py-2.5 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors">
|
||||
<i class="fas fa-save mr-2"></i> Guardar Configuración
|
||||
@@ -202,5 +235,33 @@ async function testFirebird() {
|
||||
? '<span class="text-green-600"><i class="fas fa-check-circle"></i> Conexión exitosa</span>'
|
||||
: '<span class="text-red-600"><i class="fas fa-times-circle"></i> ' + result.message + '</span>';
|
||||
}
|
||||
|
||||
async function testWhatsapp() {
|
||||
const form = document.querySelector('form');
|
||||
const status = document.getElementById('wa-status');
|
||||
status.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Probando…';
|
||||
|
||||
const url = form.querySelector('[name="config_whatsapp_url"]').value.trim().replace(/\/$/, '');
|
||||
const apiKey = form.querySelector('[name="config_whatsapp_api_key"]').value.trim();
|
||||
|
||||
if (!url) {
|
||||
status.innerHTML = '<span class="text-red-600">Ingresa la URL primero</span>';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await fetch(`${url}/api/lab/ingest_paciente.php`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Lab-Key': apiKey },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
// 422 = llegó al endpoint pero sin datos = conexión OK
|
||||
status.innerHTML = (resp.status === 200 || resp.status === 422 || resp.status === 400)
|
||||
? '<span class="text-green-600"><i class="fas fa-check-circle"></i> Endpoint alcanzable</span>'
|
||||
: `<span class="text-red-600"><i class="fas fa-times-circle"></i> HTTP ${resp.status}</span>`;
|
||||
} catch (e) {
|
||||
status.innerHTML = `<span class="text-red-600"><i class="fas fa-times-circle"></i> ${e.message}</span>`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user