unit uDataModulePacientes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uDataModuleContactos, DB, uDADataTable, uDAScriptingProvider,
  uDACDSDataTable, uDABINAdapter, uRORemoteService,
  uROClient, uROBinMessage, uROWinInetHttpChannel, uROTypes,
  uIDataModulePacientes, uBizContactos, uDADesigntimeCall, uIDataModuleFichasPacienteReport,
  uDAInterfaces, uDAMemDataTable, uDADataStreamer, uDABin2DataStreamer,
  uDARemoteDataAdapter, uIntegerListUtils;

type
  TDataModulePacientes = class(TDataModuleContactos, IDataModulePacientes, IDataModuleFichasPacienteReport)
    tbl_Pacientes: TDAMemDataTable;
    ds_Pacientes: TDADataSource;
  protected
  public
    function GetItem(const ID : Integer) : IBizPaciente;
    function NewItem : IBizPaciente;
    function GetItems : IBizPaciente;

    // Report
    function GetReport(const ListaID: TIntegerList): Binary;
  end;


implementation

{$R *.dfm}

uses
  Etiquetas_Intf, cxControls, schContactosClient_Intf, uDataTableUtils,
  uStringsUtils;

{ TDataModuleVendedores }

function TDataModulePacientes.GetItem(const ID: Integer): IBizPaciente;
var
  Condicion: TDAWhereExpression;
begin
  ShowHourglassCursor;
  try
    Result := Self.GetItems;

    with Result.DataTable.DynamicWhere do
    begin
      // (ID = :ID)
      Condicion := NewBinaryExpression(NewField('', fld_ContactosID), NewConstant(ID, datInteger), dboEqual);

      if IsEmpty then
         Expression := Condicion
      else
         Expression := NewBinaryExpression(Expression, Condicion, dboAnd);
    end;

  finally
    HideHourglassCursor;
  end;
end;

function TDataModulePacientes.GetItems: IBizPaciente;
var
  AContacto : TDAMemDataTable;
begin
  ShowHourglassCursor;
  try
    AContacto := CloneDataTable(tbl_Pacientes);
    AContacto.BusinessRulesID := BIZ_CLIENT_PACIENTE;

    with TBizPaciente(AContacto.BusinessEventsObj) do
    begin
      DatosBancarios := _GetDatosBancarios;
    end;

    Result := (AContacto as IBizPaciente);
  finally
    HideHourglassCursor;
  end;
end;

function TDataModulePacientes.GetReport(const ListaID: TIntegerList): Binary;
var
  AParam : TIntegerArray;
begin
  AParam := ListaID.ToIntegerArray;
  try
    Result := (RORemoteService as IsrvContactos).GenerarInformeFichaPaciente(AParam)
  finally
    FreeANDNil(AParam);
  end;
end;

function TDataModulePacientes.NewItem: IBizPaciente;
begin
  Result := GetItem(ID_NULO)
end;

end.
