unit uBizPacientesServer;

interface

uses
  schContactosServer_Intf, uDAInterfaces, uDADelta,
  uDADataTable, uDABusinessProcessor, uBizContactosServer;

const
  BIZ_SERVER_PACIENTE = 'Server.Paciente';

type
  TBizPacienteServer = class(TBizContactosServer)
  protected
    function DarReferenciaContacto : String; override;
    function IncrementarReferenciaContacto : Boolean; override;
  
    procedure Insert_Datos_Contacto(aChange: TDADeltaChange); override;
    procedure Update_Datos_Contacto(aChange: TDADeltaChange); override;
    procedure Delete_Datos_Contacto(aChange: TDADeltaChange); override;
  end;

implementation

uses
  uDataModuleServer, uDAClasses, 
  schContactosClient_Intf, uBusinessUtils;

const
  REF_PACIENTES = 'REF_PACIENTES';

{ TBizPacienteServer }

function TBizPacienteServer.DarReferenciaContacto: String;
begin
  Result := _DarReferenciaInterna(REF_PACIENTES)
end;

procedure TBizPacienteServer.Delete_Datos_Contacto(aChange: TDADeltaChange);
var
  ASchema : TDASchema;
  ACurrentConn : IDAConnection;
  ACommand : IDASQLCommand;
begin
  inherited;

  ASchema := BusinessProcessor.Schema;
  ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);

  ACommand := ASchema.NewCommand(ACurrentConn, 'Delete_PacientesDatos');
  try
    with ACommand do
    begin
      ParamByName('OLD_ID_PACIENTE').Value := aChange.OldValueByName[fld_PacientesID];
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

function TBizPacienteServer.IncrementarReferenciaContacto: Boolean;
begin
  Result := _IncrementarReferenciaInterna(REF_PACIENTES)
end;

procedure TBizPacienteServer.Insert_Datos_Contacto(aChange: TDADeltaChange);
var
  ASchema : TDASchema;
  ACurrentConn : IDAConnection;
  ACommand : IDASQLCommand;
begin
  inherited;

  ASchema := BusinessProcessor.Schema;
  ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);

  ACommand := ASchema.NewCommand(ACurrentConn, 'Insert_PacientesDatos');
  try
    with ACommand do
    begin
      ParamByName('ID_PACIENTE').Value := aChange.NewValueByName[fld_PacientesID];
      ParamByName('FECHA_NACIMIENTO').Value := aChange.NewValueByName[fld_PacientesFECHA_NACIMIENTO];
      ParamByName('NUMERO_SS').Value := aChange.NewValueByName[fld_PacientesNUMERO_SS];
      ParamByName('FECHA_BAJA').Value := aChange.NewValueByName[fld_PacientesFECHA_BAJA];
      ParamByName('CAUSA_BAJA').Value := aChange.NewValueByName[fld_PacientesCAUSA_BAJA];
      ParamByName('PABELLON').Value := aChange.NewValueByName[fld_PacientesPABELLON];
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

procedure TBizPacienteServer.Update_Datos_Contacto(aChange: TDADeltaChange);
var
  ASchema : TDASchema;
  ACurrentConn : IDAConnection;
  ACommand : IDASQLCommand;
begin
  inherited;

  ASchema := BusinessProcessor.Schema;
  ACurrentConn := GetBusinessProcessorConnection(BusinessProcessor);

  ACommand := ASchema.NewCommand(ACurrentConn, 'Update_PacientesDatos');
  try
    with ACommand do
    begin
      ParamByName('OLD_ID_PACIENTE').Value := aChange.OldValueByName[fld_PacientesID];
      ParamByName('FECHA_NACIMIENTO').Value := aChange.NewValueByName[fld_PacientesFECHA_NACIMIENTO];
      ParamByName('NUMERO_SS').Value := aChange.NewValueByName[fld_PacientesNUMERO_SS];
      ParamByName('FECHA_BAJA').Value := aChange.NewValueByName[fld_PacientesFECHA_BAJA];
      ParamByName('CAUSA_BAJA').Value := aChange.NewValueByName[fld_PacientesCAUSA_BAJA];
      ParamByName('PABELLON').Value := aChange.NewValueByName[fld_PacientesPABELLON];      
      Execute;
    end;
  finally
    ACommand := NIL;
  end;
end;

initialization
  RegisterBusinessProcessorRules(BIZ_SERVER_PACIENTE, TBizPacienteServer);

end.
