alter table TEDEF.T_WEB_LOTES_X_USUARIO modify nidusuario number(11);

alter table TEDEF.T_WEB_LOTES_X_USUARIO_ERRORES modify nidusuario number(11);

alter table clinica add clave varchar2(64);

update clinica set clave = ruc;

CREATE OR REPLACE procedure TEDEF.InsertaClinica(
       pID                  IN NUMBER,
       pNOMBRECLINICA       IN VARCHAR2,
       pRUC                 IN VARCHAR2,
       pEMAIL               IN VARCHAR2,
       pTUBIGEO_DPTO        IN NUMBER,
       pTUBIGEO_PROV        IN NUMBER,
       pTUBIGEO_DIST        IN NUMBER,
       pCOD_PROVEEDOR_LP    IN NUMBER,
       p_n_trama_9          IN NUMBER,
       p_vSucursal          IN VARCHAR2,
       p_Clave              IN VARCHAR2)
as
begin
  Insert into Clinica (IDCLINICA, NOMBRECLINICA, RUC, EMAIL,
  TUBIGEO_DPTO, TUBIGEO_PROV, TUBIGEO_DIST, COD_PROVEEDOR_LP, n_trama_9, vSucursal, clave)
  values(pID, pNOMBRECLINICA, pRUC,
  pEMAIL, pTUBIGEO_DPTO, pTUBIGEO_PROV, pTUBIGEO_DIST, pCOD_PROVEEDOR_LP, p_n_trama_9, p_vSucursal, p_Clave);
end InsertaClinica;
/

CREATE OR REPLACE procedure TEDEF.ActualizaClinica(
       pID                  IN NUMBER,
       pNOMBRECLINICA       IN VARCHAR2,
       pRUC                 IN VARCHAR2,
       pEMAIL               IN VARCHAR2,
       pTUBIGEO_DPTO        IN NUMBER,
       pTUBIGEO_PROV        IN NUMBER,
       pTUBIGEO_DIST        IN NUMBER,
       pCOD_PROVEEDOR_LP    IN NUMBER,
       p_n_trama_9          IN NUMBER,
       p_vSucursal          IN VARCHAR2,
       p_Clave              IN VARCHAR2)
as
begin
  Update Clinica
  set NOMBRECLINICA = pNOMBRECLINICA,
  EMAIL = pEMAIL,
  TUBIGEO_DPTO = pTUBIGEO_DPTO,
  TUBIGEO_PROV = pTUBIGEO_PROV,
  TUBIGEO_DIST = pTUBIGEO_DIST,
  COD_PROVEEDOR_LP = pCOD_PROVEEDOR_LP,
  n_trama_9 = p_n_trama_9,
  vSucursal = p_vSucursal,
  clave = p_Clave
  where IDCLINICA = pID
  and RUC = pRUC;
end ActualizaClinica;
/

CREATE OR REPLACE procedure TEDEF.VALIDAR_LOGIN(
    p_vusuario varchar2,
    p_vpassword varchar2,
    p_nresultado OUT number
)
As
Begin
 /*SELECT COUNT(1) INTO p_nresultado
 FROM TEDEF.MT_WEB_USUARIOS
 WHERE VUSUARIO = p_vusuario
     AND VPASSWORD = p_vpassword;*/
     
     SELECT COUNT(1) INTO p_nresultado
 FROM TEDEF.clinica
 WHERE RUC = p_vusuario
     AND CLAVE = p_vpassword;    
End VALIDAR_LOGIN;
/