Add Verifik RETHUS integration: backend module, settings auth flow, admin query button
- verifik.service.ts: email OTP auth, token storage/refresh, RETHUS query by professional - verifik.controller.ts: send-otp, confirm, refresh, rethus/professional/:id endpoints - settings/page.tsx: Verifik connection section (email→OTP→token) - professionals/[id]/page.tsx: Consultar RETHUS button with inline result display Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
66bc47b6e1
commit
0a67f5d80a
@@ -47,6 +47,8 @@ export default function ProfessionalDetailPage() {
|
||||
const [savingPro, setSavingPro] = useState(false);
|
||||
const [savingUser, setSavingUser] = useState(false);
|
||||
const [validatingRethus, setValidatingRethus] = useState(false);
|
||||
const [rethusResult, setRethusResult] = useState<any>(null);
|
||||
const [loadingRethus, setLoadingRethus] = useState(false);
|
||||
const [proForm, setProForm] = useState<ProForm>({ profession: '', identification: '', address: '', rate: '', rethus_code: '' });
|
||||
const [userForm, setUserForm] = useState<UserForm>({ name: '', email: '', phone: '', city: '' });
|
||||
|
||||
@@ -101,6 +103,19 @@ export default function ProfessionalDetailPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const consultRethus = async () => {
|
||||
setLoadingRethus(true);
|
||||
setRethusResult(null);
|
||||
try {
|
||||
const data = await api.get<any>(`/verifik/rethus/professional/${id}`);
|
||||
setRethusResult(data);
|
||||
} catch (e: any) {
|
||||
toast.error(e?.message || 'Error al consultar RETHUS');
|
||||
} finally {
|
||||
setLoadingRethus(false);
|
||||
}
|
||||
};
|
||||
|
||||
const validateRethus = async () => {
|
||||
setValidatingRethus(true);
|
||||
try {
|
||||
@@ -349,13 +364,22 @@ export default function ProfessionalDetailPage() {
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={consultRethus}
|
||||
disabled={loadingRethus}
|
||||
>
|
||||
<ShieldCheck className="mr-2 h-4 w-4" />
|
||||
{loadingRethus ? 'Consultando...' : 'Consultar en RETHUS'}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => window.open('https://www.minsalud.gov.co/salud/Paginas/rethus.aspx', '_blank')}
|
||||
>
|
||||
<ExternalLink className="mr-2 h-4 w-4" />
|
||||
Abrir portal RETHUS (Minsalud)
|
||||
Portal Minsalud
|
||||
</Button>
|
||||
{!professional.rethus_validated && (
|
||||
<Button
|
||||
@@ -369,9 +393,33 @@ export default function ProfessionalDetailPage() {
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{rethusResult && (
|
||||
<div className="mt-3 rounded-lg border bg-muted/40 p-4 space-y-2 text-sm">
|
||||
<p className="font-semibold">{rethusResult.fullName || `${rethusResult.firstName} ${rethusResult.lastName}`}</p>
|
||||
<p><span className="text-muted-foreground">Estado: </span>
|
||||
<span className={rethusResult.rethus?.status?.includes('ACTIVO') ? 'text-green-600 font-medium' : 'text-destructive font-medium'}>
|
||||
{rethusResult.rethus?.status || '—'}
|
||||
</span>
|
||||
</p>
|
||||
{rethusResult.rethus?.academic?.length > 0 && (
|
||||
<div className="space-y-1">
|
||||
<p className="text-muted-foreground font-medium">Títulos registrados:</p>
|
||||
{rethusResult.rethus.academic.map((a: any, i: number) => (
|
||||
<div key={i} className="pl-3 border-l-2 border-muted-foreground/30">
|
||||
<p className="font-medium">{a.profession}</p>
|
||||
<p className="text-xs text-muted-foreground">{a.type} · {a.originDegree} · {a.startDate}</p>
|
||||
{a.entity && <p className="text-xs text-muted-foreground">{a.entity}</p>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!professional.rethus_validated && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Copia el código o cédula, búscalo en el portal de Minsalud y una vez verificado haz clic en "Marcar como validado".
|
||||
Consulta automáticamente con Verifik o búscalo en el portal de Minsalud. Una vez verificado, haz clic en "Marcar como validado".
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { toast } from 'sonner';
|
||||
import {
|
||||
Save, ExternalLink, Copy, FileText, Shield, Map,
|
||||
Eye, EyeOff, CheckCircle2, XCircle, Clock, Smartphone, Phone, Mail, Server,
|
||||
Eye, EyeOff, CheckCircle2, XCircle, Clock, Smartphone, Phone, Mail, Server, Link,
|
||||
} from 'lucide-react';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000/api/v1';
|
||||
@@ -57,6 +57,13 @@ export default function SettingsPage() {
|
||||
const [policies, setPolicies] = useState<Record<string, string>>({ privacy: '', terms: '' });
|
||||
const [savingPolicy, setSavingPolicy] = useState<string | null>(null);
|
||||
|
||||
// Verifik
|
||||
const [verifikConnected, setVerifikConnected] = useState(false);
|
||||
const [verifikEmail, setVerifikEmail] = useState('');
|
||||
const [verifikOtp, setVerifikOtp] = useState('');
|
||||
const [verifikOtpSent, setVerifikOtpSent] = useState(false);
|
||||
const [verifikLoading, setVerifikLoading] = useState(false);
|
||||
|
||||
// SMTP
|
||||
const [smtp, setSmtp] = useState<SmtpConfig>({ host: '', port: '587', user: '', pass: '', from: '' });
|
||||
const [showSmtpPass, setShowSmtpPass] = useState(false);
|
||||
@@ -69,12 +76,14 @@ export default function SettingsPage() {
|
||||
api.get<{ configured: boolean }>('/settings/maps-key'),
|
||||
api.get<{ privacy: string | null; terms: string | null }>('/settings/policies'),
|
||||
api.get<SmtpConfig | null>('/settings/smtp').catch(() => null),
|
||||
api.get<{ connected: boolean }>('/verifik/status').catch(() => ({ connected: false })),
|
||||
])
|
||||
.then(([globalData, mapsData, policiesData, smtpData]) => {
|
||||
.then(([globalData, mapsData, policiesData, smtpData, verifikStatus]) => {
|
||||
setGlobal(globalData || {});
|
||||
setMapsConfigured(mapsData.configured);
|
||||
setPolicies({ privacy: policiesData.privacy || '', terms: policiesData.terms || '' });
|
||||
if (smtpData) setSmtp({ host: smtpData.host || '', port: smtpData.port || '587', user: smtpData.user || '', pass: smtpData.pass || '', from: smtpData.from || '' });
|
||||
setVerifikConnected(verifikStatus.connected);
|
||||
})
|
||||
.catch(() => toast.error('Error al cargar configuración'))
|
||||
.finally(() => setLoading(false));
|
||||
@@ -134,6 +143,48 @@ export default function SettingsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const sendVerifikOtp = async () => {
|
||||
if (!verifikEmail.trim()) return toast.error('Ingresa tu email de Verifik');
|
||||
setVerifikLoading(true);
|
||||
try {
|
||||
await api.post('/verifik/send-otp', { email: verifikEmail.trim() });
|
||||
setVerifikOtpSent(true);
|
||||
toast.success('OTP enviado a tu correo');
|
||||
} catch (e: any) {
|
||||
toast.error(e?.message || 'Error al enviar OTP');
|
||||
} finally {
|
||||
setVerifikLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const confirmVerifikOtp = async () => {
|
||||
if (!verifikOtp.trim()) return toast.error('Ingresa el código OTP');
|
||||
setVerifikLoading(true);
|
||||
try {
|
||||
await api.post('/verifik/confirm', { email: verifikEmail.trim(), otp: verifikOtp.trim() });
|
||||
setVerifikConnected(true);
|
||||
setVerifikOtpSent(false);
|
||||
setVerifikOtp('');
|
||||
toast.success('Verifik conectado correctamente');
|
||||
} catch (e: any) {
|
||||
toast.error(e?.message || 'Error al confirmar OTP');
|
||||
} finally {
|
||||
setVerifikLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const refreshVerifikToken = async () => {
|
||||
setVerifikLoading(true);
|
||||
try {
|
||||
await api.post('/verifik/refresh', {});
|
||||
toast.success('Token renovado');
|
||||
} catch (e: any) {
|
||||
toast.error(e?.message || 'Error al renovar token');
|
||||
} finally {
|
||||
setVerifikLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const copyLink = (key: string) => {
|
||||
navigator.clipboard.writeText(`${API_BASE}/settings/policy/${key}`);
|
||||
toast.success('Enlace copiado');
|
||||
@@ -418,6 +469,66 @@ export default function SettingsPage() {
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
{/* ── Verifik ── */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-lg font-semibold">Verifik — Validación de profesionales</h2>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2 text-base">
|
||||
<Link size={18} className="text-muted-foreground" />
|
||||
Cuenta Verifik
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Permite consultar RETHUS (registro de profesionales de salud) directamente desde el perfil de cada profesional.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="flex items-center gap-3">
|
||||
{verifikConnected
|
||||
? <><CheckCircle2 className="text-green-500 h-5 w-5" /><span className="text-sm font-medium text-green-600">Conectado</span></>
|
||||
: <><XCircle className="text-destructive h-5 w-5" /><span className="text-sm font-medium text-destructive">No conectado</span></>}
|
||||
</div>
|
||||
|
||||
{!verifikOtpSent ? (
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
type="email"
|
||||
placeholder="tu@email.com (cuenta Verifik)"
|
||||
value={verifikEmail}
|
||||
onChange={(e) => setVerifikEmail(e.target.value)}
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button onClick={sendVerifikOtp} disabled={verifikLoading || !verifikEmail.trim()}>
|
||||
{verifikLoading ? 'Enviando...' : 'Enviar OTP'}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">Ingresa el código que llegó a <strong>{verifikEmail}</strong></p>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
placeholder="Código OTP"
|
||||
value={verifikOtp}
|
||||
onChange={(e) => setVerifikOtp(e.target.value)}
|
||||
className="w-40 font-mono"
|
||||
/>
|
||||
<Button onClick={confirmVerifikOtp} disabled={verifikLoading}>
|
||||
{verifikLoading ? 'Confirmando...' : 'Confirmar'}
|
||||
</Button>
|
||||
<Button variant="ghost" onClick={() => setVerifikOtpSent(false)}>Cancelar</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{verifikConnected && (
|
||||
<Button variant="outline" size="sm" onClick={refreshVerifikToken} disabled={verifikLoading}>
|
||||
{verifikLoading ? 'Renovando...' : 'Renovar token (30 días)'}
|
||||
</Button>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
{/* ── Documentos legales ── */}
|
||||
<section className="space-y-4">
|
||||
<h2 className="text-lg font-semibold">Documentos legales</h2>
|
||||
|
||||
Reference in New Issue
Block a user