feat: campo RETHUS con validación manual desde el admin
- Prisma schema: rethus_code y rethus_validated en tabla professionals - Migración 0001: ALTER TABLE agrega ambas columnas - DTO: rethus_code y rethus_validated en CreateProfessionalDto y UpdateProfessionalDto - Service: nuevo método validateRethus, rethus_code incluido en requestProfessional - Controller: endpoint POST /professionals/:id/validate-rethus (JWT protegido) - Admin listado pendientes: columna RETHUS con ícono verde/amarillo y enlace al detalle - Admin detalle profesional: card de validación RETHUS con botón consultar Minsalud y marcar como validado Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
46fcb57edf
commit
c1e9dba2d1
@@ -10,7 +10,7 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { toast } from 'sonner';
|
||||
import { ArrowLeft, Pencil, X, Check } from 'lucide-react';
|
||||
import { ArrowLeft, Pencil, X, Check, ShieldCheck, ShieldAlert, ExternalLink } from 'lucide-react';
|
||||
|
||||
interface User { id: string; name: string; email?: string; phone?: string; city?: string; picture?: string; }
|
||||
interface Schedule { id: string; day_of_week: number; enabled: boolean; range1_hour1?: string; range1_hour2?: string; }
|
||||
@@ -19,6 +19,7 @@ interface PaymentMethod { id: string; nequi: boolean; datafono: boolean; transfe
|
||||
interface Professional {
|
||||
id: string; user_id: string; is_active: boolean;
|
||||
profession?: string; identification?: string; address?: string;
|
||||
rethus_code?: string; rethus_validated?: boolean;
|
||||
rate?: number; average_score?: number;
|
||||
users?: User; schedules?: Schedule[];
|
||||
specializations?: Specialization[]; payment_methods?: PaymentMethod[];
|
||||
@@ -28,7 +29,7 @@ interface Service { id: string; description?: string; rate?: number; status: str
|
||||
const DAY_NAMES = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
|
||||
const PAYMENT_LABELS: Record<string, string> = { nequi: 'Nequi', datafono: 'Datáfono', transferencia: 'Transferencia' };
|
||||
|
||||
interface ProForm { profession: string; identification: string; address: string; rate: string; }
|
||||
interface ProForm { profession: string; identification: string; address: string; rate: string; rethus_code: string; }
|
||||
interface UserForm { name: string; email: string; phone: string; city: string; }
|
||||
|
||||
export default function ProfessionalDetailPage() {
|
||||
@@ -43,7 +44,8 @@ export default function ProfessionalDetailPage() {
|
||||
const [editingUser, setEditingUser] = useState(false);
|
||||
const [savingPro, setSavingPro] = useState(false);
|
||||
const [savingUser, setSavingUser] = useState(false);
|
||||
const [proForm, setProForm] = useState<ProForm>({ profession: '', identification: '', address: '', rate: '' });
|
||||
const [validatingRethus, setValidatingRethus] = useState(false);
|
||||
const [proForm, setProForm] = useState<ProForm>({ profession: '', identification: '', address: '', rate: '', rethus_code: '' });
|
||||
const [userForm, setUserForm] = useState<UserForm>({ name: '', email: '', phone: '', city: '' });
|
||||
|
||||
const load = useCallback(() => {
|
||||
@@ -61,6 +63,7 @@ export default function ProfessionalDetailPage() {
|
||||
identification: prof.identification || '',
|
||||
address: prof.address || '',
|
||||
rate: prof.rate != null ? String(prof.rate) : '',
|
||||
rethus_code: prof.rethus_code || '',
|
||||
});
|
||||
setUserForm({
|
||||
name: prof.users?.name || '',
|
||||
@@ -84,6 +87,7 @@ export default function ProfessionalDetailPage() {
|
||||
identification: proForm.identification || undefined,
|
||||
address: proForm.address || undefined,
|
||||
rate: proForm.rate ? Number(proForm.rate) : undefined,
|
||||
rethus_code: proForm.rethus_code || undefined,
|
||||
});
|
||||
toast.success('Perfil profesional actualizado');
|
||||
setEditingPro(false);
|
||||
@@ -95,6 +99,19 @@ export default function ProfessionalDetailPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const validateRethus = async () => {
|
||||
setValidatingRethus(true);
|
||||
try {
|
||||
await api.post(`/professionals/${id}/validate-rethus`);
|
||||
toast.success('RETHUS marcado como validado');
|
||||
load();
|
||||
} catch (e: any) {
|
||||
toast.error(e?.message || 'Error al validar RETHUS');
|
||||
} finally {
|
||||
setValidatingRethus(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveUser = async () => {
|
||||
if (!professional?.user_id) return;
|
||||
setSavingUser(true);
|
||||
@@ -247,6 +264,71 @@ export default function ProfessionalDetailPage() {
|
||||
<span className="text-muted-foreground">Puntuación promedio</span>
|
||||
<p className="font-medium">{professional.average_score != null ? `${professional.average_score.toFixed(1)} / 5` : '—'}</p>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<span className="text-muted-foreground">Código RETHUS</span>
|
||||
{editingPro
|
||||
? <Input value={proForm.rethus_code} onChange={(e) => setProForm({ ...proForm, rethus_code: e.target.value })} placeholder="Ej: 123456789-1" />
|
||||
: <p className="font-medium">{professional.rethus_code || '—'}</p>}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* RETHUS */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
{professional.rethus_validated
|
||||
? <ShieldCheck className="h-5 w-5 text-green-500" />
|
||||
: <ShieldAlert className="h-5 w-5 text-yellow-500" />}
|
||||
Validación RETHUS
|
||||
<Badge
|
||||
variant={professional.rethus_validated ? 'default' : 'secondary'}
|
||||
className={professional.rethus_validated ? 'bg-green-500 text-white ml-2' : 'ml-2'}
|
||||
>
|
||||
{professional.rethus_validated ? 'Validado' : 'Pendiente'}
|
||||
</Badge>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{professional.rethus_code ? (
|
||||
<>
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<span className="text-muted-foreground">Código registrado:</span>
|
||||
<span className="font-mono font-semibold">{professional.rethus_code}</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<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" />
|
||||
Consultar en RETHUS (Minsalud)
|
||||
</Button>
|
||||
{!professional.rethus_validated && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={validateRethus}
|
||||
disabled={validatingRethus}
|
||||
className="bg-green-600 hover:bg-green-700 text-white"
|
||||
>
|
||||
<ShieldCheck className="mr-2 h-4 w-4" />
|
||||
{validatingRethus ? 'Guardando...' : 'Marcar como validado'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{!professional.rethus_validated && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Consulta el código en el portal de Minsalud, verifica que coincida con el profesional y luego marca como validado.
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">Este profesional no proporcionó código RETHUS (campo opcional).</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { toast } from 'sonner';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import Link from 'next/link';
|
||||
import { ShieldCheck, ShieldAlert } from 'lucide-react';
|
||||
|
||||
interface Professional {
|
||||
id: string;
|
||||
@@ -15,6 +17,8 @@ interface Professional {
|
||||
is_active: boolean;
|
||||
profession?: string;
|
||||
identification?: string;
|
||||
rethus_code?: string;
|
||||
rethus_validated?: boolean;
|
||||
rate?: number;
|
||||
users?: { id: string; name: string; email?: string; phone?: string };
|
||||
}
|
||||
@@ -112,7 +116,7 @@ export default function ProfessionalsPage() {
|
||||
<TableHead>Nombre</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Teléfono</TableHead>
|
||||
<TableHead>Solicitud</TableHead>
|
||||
<TableHead>RETHUS</TableHead>
|
||||
<TableHead className="text-right">Acción</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
@@ -124,11 +128,29 @@ export default function ProfessionalsPage() {
|
||||
) : (
|
||||
pending.map((p) => (
|
||||
<TableRow key={p.id}>
|
||||
<TableCell className="font-medium">{p.users?.name}</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
<Link href={`/professionals/${p.id}`} className="hover:underline text-primary">
|
||||
{p.users?.name}
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell>{p.users?.email || '—'}</TableCell>
|
||||
<TableCell>{p.users?.phone || '—'}</TableCell>
|
||||
<TableCell>{new Date().toLocaleDateString()}</TableCell>
|
||||
<TableCell>
|
||||
{p.rethus_code ? (
|
||||
<div className="flex items-center gap-1">
|
||||
{p.rethus_validated
|
||||
? <ShieldCheck className="h-4 w-4 text-green-500" />
|
||||
: <ShieldAlert className="h-4 w-4 text-yellow-500" />}
|
||||
<span className="font-mono text-xs">{p.rethus_code}</span>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted-foreground text-xs">No aplica</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right space-x-2">
|
||||
<Link href={`/professionals/${p.id}`}>
|
||||
<Button size="sm" variant="outline">Ver detalle</Button>
|
||||
</Link>
|
||||
<Button size="sm" onClick={() => approve(p.id)}>Aprobar</Button>
|
||||
<Button size="sm" variant="destructive" onClick={() => deny(p.id)}>Rechazar</Button>
|
||||
</TableCell>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- Add RETHUS fields to professionals
|
||||
ALTER TABLE "professionals" ADD COLUMN IF NOT EXISTS "rethus_code" VARCHAR(50);
|
||||
ALTER TABLE "professionals" ADD COLUMN IF NOT EXISTS "rethus_validated" BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -82,6 +82,8 @@ model professionals {
|
||||
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
|
||||
user_id String @unique @db.Uuid
|
||||
identification String? @db.VarChar(50)
|
||||
rethus_code String? @db.VarChar(50)
|
||||
rethus_validated Boolean? @default(false)
|
||||
address String?
|
||||
additional_address String?
|
||||
profession String? @db.VarChar(255)
|
||||
|
||||
@@ -15,6 +15,10 @@ export class CreateProfessionalDto {
|
||||
@IsString()
|
||||
additional_address?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
rethus_code?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
identification_picture?: string;
|
||||
@@ -41,6 +45,14 @@ export class UpdateProfessionalDto {
|
||||
@IsString()
|
||||
profession?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
rethus_code?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
rethus_validated?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
rate?: number;
|
||||
|
||||
@@ -43,6 +43,13 @@ export class ProfessionalsController {
|
||||
return this.pros.deny(id);
|
||||
}
|
||||
|
||||
@Post(':id/validate-rethus')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
validateRethus(@Param('id') id: string) {
|
||||
return this.pros.validateRethus(id);
|
||||
}
|
||||
|
||||
@Get('me')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
|
||||
@@ -149,6 +149,13 @@ export class ProfessionalsService {
|
||||
return { message: 'Solicitud rechazada' };
|
||||
}
|
||||
|
||||
async validateRethus(id: string) {
|
||||
const prof = await this.prisma.professionals.findUnique({ where: { id } });
|
||||
if (!prof) throw new NotFoundException('Profesional no encontrado');
|
||||
await this.prisma.professionals.update({ where: { id }, data: { rethus_validated: true } });
|
||||
return { message: 'RETHUS validado correctamente' };
|
||||
}
|
||||
|
||||
async requestProfessional(userId: string, data: any) {
|
||||
const existing = await this.prisma.professionals.findUnique({ where: { user_id: userId } });
|
||||
if (existing) throw new BadRequestException('Ya tienes una solicitud de profesional');
|
||||
@@ -161,6 +168,7 @@ export class ProfessionalsService {
|
||||
profession: data.profession,
|
||||
address: data.address,
|
||||
additional_address: data.additional_address,
|
||||
rethus_code: data.rethus_code ?? null,
|
||||
identification_picture: data.identification_picture,
|
||||
certificate_picture: data.certificate_picture,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user