unit class_measure;

interface

uses SysUtils, Classes, Dialogs, DataUnit, ConstUnit, DB,
     check_user_data, user_types, class_point, class_counted_values, class_diagnoz,
     class_basics;

type
  TRDMeasure = class (TObject)
    private
      ID:             string;             //порядковый номер
      date:           string;             //дата
      description:    string;             //описание измерения

    //информация о пациенте
      patinent_id:          string;
      patinent_sirname:     string;
      patinent_first_name:  string;
      patinent_middle_name: string;

      function Set_measure_id( in_measure_id: string ): boolean;
      function Set_measure_date( in_measure_date: string ): boolean;
      function Set_measure_opisanie( in_measure_description: string ): boolean;

      function Set_measure_patient_id( in_patient_id:string ): boolean;
      function Set_measure_patient_sirname( in_patient_sirname: string ): boolean;
      function Set_measure_patient_first_name( in_patient_first_name: string ): boolean;
      function Set_measure_patient_middle_name( in_patient_middle_name: string ): boolean;

    public
      point_values:   TRDPointList;
      counted_values: TRDCounted_Values;
      diagnoz:        TRDMeasure_diagnoz;

      //функция установки информации об измерении
      function Set_measure_info(in_measure_id, in_measure_date, in_measure_description: string):boolean;
      //функция установки информации о пациенте
      function Set_measure_patient_info(in_patient_id, in_patient_sirname, in_patient_first_name, in_patient_middle_name: string):boolean;

      constructor Create;  virtual;
      destructor  Destroy; override;

end;


implementation

constructor TRDMeasure.Create;
begin
  inherited Create;
  point_values := TRDPointList.Create();
  counted_values := TRDCounted_Values.Create;
  diagnoz := TRDMeasure_diagnoz.Create;
  with self do
  begin
    ID := '';
    date := '';
    description := '';
    patinent_id := '';
    patinent_sirname := '';
    patinent_first_name := '';
    patinent_middle_name := '';
  end;
end;
destructor TRDMeasure.Destroy;
begin
  point_values.Free;
  counted_values.Free;
  diagnoz.Free;
  with self do
    begin
      ID := '';
      date := '';
      description := '';
      patinent_id := '';
      patinent_sirname := '';
      patinent_first_name := '';
      patinent_middle_name := '';
    end;
   inherited Destroy;;
end;

function TRDMeasure.Set_measure_id( in_measure_id: string ): boolean;
begin
Assert( ( ( in_measure_id <> '' ) and ( strtoint( in_measure_id ) > 0 ) ),
        'Входное поле ID измерения класса RDMeasure недопустимо!'+'{B8FFAE03-5A34-4A02-937F-2AF5003C6717}');
  self.ID := in_measure_id;
  result := true;
end;

function TRDMeasure.Set_measure_info(in_measure_id, in_measure_date,
  in_measure_description: string): boolean;
begin
  result := Self.Set_measure_id(in_measure_id) and
            Self.Set_measure_date(in_measure_date) and
            Self.Set_measure_opisanie(in_measure_description);

end;

function TRDMeasure.Set_measure_date( in_measure_date: string ): boolean;
begin
Assert( ( in_measure_date <> '' ) ,
        'Входное поле Date измерения класса RDMeasure недопустимо!'+'{EFCE36FB-9E58-4437-9492-856026C3105C}');
  try
    strtodate( in_measure_date );
  finally
    self.date := in_measure_date;
    result := true; 
  end;
end;

function TRDMeasure.Set_measure_opisanie( in_measure_description: string ): boolean;
begin
  self.description := in_measure_description;
  result := true;
end;

function TRDMeasure.Set_measure_patient_id( in_patient_id: string ): boolean;
begin
Assert( ( ( in_patient_id <> '' ) and ( strtoint( in_patient_id ) > 0 ) ),
        'Входное поле ID пациента класса RDMeasure недопустимо!'+'{7D3EA97C-93FB-41EC-A8CB-2E7FA500F2E2}');
  self.ID := in_patient_id;
  result := TRUE;
end;

function TRDMeasure.Set_measure_patient_info(in_patient_id, in_patient_sirname,
  in_patient_first_name, in_patient_middle_name: string): boolean;
begin
  result := Self.Set_measure_patient_id(in_patient_id) and
            Self.Set_measure_patient_sirname(in_patient_sirname) and
            Self.Set_measure_patient_first_name(in_patient_first_name) and
            Self.Set_measure_patient_middle_name(in_patient_middle_name);
end;

function TRDMeasure.Set_measure_patient_sirname( in_patient_sirname: string ): boolean;
var temp_string:string;
begin
  temp_string := user_data_check_and_correct_name( in_patient_sirname );
  if ( self.patinent_sirname = temp_string ) then
    begin
      result := false;
      Exit;
    end
  else
    begin
      self.patinent_sirname := temp_string;
      result := true;
    end;
end;

function TRDMeasure.Set_measure_patient_first_name( in_patient_first_name: string ): boolean;
var temp_string:string;
begin
  temp_string := user_data_check_and_correct_name( in_patient_first_name );
  if ( self.patinent_first_name = temp_string ) then
    begin
      result := false;
      Exit;
    end
  else
    begin
      self.patinent_first_name := temp_string;
      result := true;
    end;
end;

function TRDMeasure.Set_measure_patient_middle_name( in_patient_middle_name: string ): boolean;
var temp_string:string;
begin
  temp_string := user_data_check_and_correct_name( in_patient_middle_name );
  if ( self.patinent_middle_name = temp_string ) then
    begin
      result := false;
      Exit;
    end
  else
    begin
      self.patinent_middle_name := temp_string;
      result := true;
    end;

end;


end.
