unit class_measure; interface uses SysUtils, Classes, Dialogs, DataUnit, ConstUnit, DB, check_user_data, user_types, class_point, class_param, 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; total_sent: integer; current_sent: integer; 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; procedure Check_and_save_measure_info; function Load_current_params_values_to_database: TQuery_results; procedure Check_errors(var message_:params_record); public point_values: TRDPointList; counted_values: TRDCounted_Values; diagnoz: TRDMeasure_diagnoz; //опции manual_point_switch: boolean; //ручное переключение точек program_calculation: boolean; //программный расчет параметров time_to_load_to_database: integer; //момент загрузки данных в базу null_wrong_values: boolean; procedure Inc_total_sent; procedure Check_current_sent; //функция установки информации об измерении 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; function Get_measure_ID: string; function Get_measure_date: string; function Get_measure_description: string; function Get_measure_patinet_ID: string; function Get_measure_patinet_sirname: string; function Get_measure_patinet_first_name: string; function Get_measure_patinet_middle_name: string; function Get_total_sent: integer; function Get_current_sent: integer; procedure Set_total_sent(in_count: integer); procedure Set_current_sent(in_count: integer); function Write_values(incoming_params: params_record):boolean; procedure Load_values_to_database; constructor Create; virtual; destructor Destroy; override; end; implementation procedure TRDMeasure.Check_and_save_measure_info; begin //создаем запись об измерении with SQL_DM.mysql_query_sp do begin try Close; SQL.Text := ' CALL rd_add_new_measure(:in_measure_ID, :in_measure_Date, :in_Patient_ID,'+ ' :in_description, @out_ErrorMessage, @out_ID_measure);'; Prepare; Params.ParamByName( 'in_measure_ID' ).Value := self.ID; Params.ParamByName( 'in_measure_Date' ).Value := self.date; Params.ParamByName( 'in_Patient_ID' ).Value := self.patinent_id; Params.ParamByName( 'in_description' ).Value := self.description; Execute; except on E: Exception do begin Exit; end; end; try Close; //выборка выходных переменных процедуры SQL.Clear; SQL.Text := 'SELECT @out_ID_measure, @out_ErrorMessage;'; Execute; except on E: Exception do begin Exit; end; end; //Result.Success := strtobool( FieldByName( '@out_Success' ).AsString ); //Result.Error_message := ( FieldByName( '@out_ErrorMessage' ).AsString ); Exit; end; end; 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 := ''; total_sent := 0; current_sent := 0; manual_point_switch := FALSE; time_to_load_to_database := 0; null_wrong_values := TRUE; 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.Get_current_sent: integer; begin result := self.current_sent; end; function TRDMeasure.Get_measure_date: string; begin Assert( ( self.date <> '' ), 'поле ДАТА ИЗМЕРЕНИЯ класса RDMeasure пустое!'+'{C981D9F6-EC5E-42ED-B547-9AB5FEF20EEC}'); result := self.date; end; function TRDMeasure.Get_measure_description: string; begin Assert( ( self.description <> '' ), 'поле ОПИСАНИЕ ИЗМЕРЕНИЯ класса RDMeasure пустое!'+'{A93FBFD4-4263-435B-A33A-27817CB7657E}'); result := self.description; end; function TRDMeasure.Get_measure_ID: string; begin Assert( ( self.ID <> '' ), 'поле ID ИЗМЕРЕНИЯ класса RDMeasure пустое!'+'{96CFE632-B213-48AF-B792-1B2B8582CBAD}'); result := self.ID; end; function TRDMeasure.Get_measure_patinet_first_name: string; begin Assert( ( self.patinent_first_name <> '' ), 'поле ИМЯ ПАЦИЕНТА класса RDMeasure пустое!'+'{0F770629-9D13-460F-A79A-7166485EB287}'); result := self.patinent_first_name; end; function TRDMeasure.Get_measure_patinet_ID: string; begin Assert( ( self.patinent_id <> '' ), 'поле ID ПАЦИЕНТА класса RDMeasure пустое!'+'{FF4DC3FC-59A7-4FCF-9FB5-C6B7EE87B3AE}'); result := self.patinent_id; end; function TRDMeasure.Get_measure_patinet_middle_name: string; begin Assert( ( self.patinent_middle_name <> '' ), 'поле ОТЧЕСТВО ПАЦИЕНТА класса RDMeasure пустое!'+'{FD65F36E-053C-423E-A52C-52FC44E7A7E9}'); result := self.patinent_middle_name; end; function TRDMeasure.Get_measure_patinet_sirname: string; begin Assert( ( self.patinent_sirname <> '' ), 'поле ФАИМЛИЯ ПАЦИЕНТА класса RDMeasure пустое!'+'{7E87A710-04F5-42F2-AE68-BFD519E9E23F}'); result := self.patinent_sirname; end; function TRDMeasure.Get_total_sent: integer; begin result := self.total_sent; end; procedure TRDMeasure.Inc_total_sent; begin inc(total_sent); inc(current_sent); end; function TRDMeasure.Load_current_params_values_to_database:TQuery_results; var i: integer; value: double; param: TRDParam; begin Result.Success := FALSE; //создаем запись о значениях, // 3 --> начиная с R // Count - 1 --> без учета Iсм for i := 3 to point_values.Get_current_point.Params.Count - 1 do begin param := point_values.Get_current_point.Params.Find_by_index( i - 1 ); //showmessage (param.Get_name); value := param.models.Get_current_model.sources.src_device.Get_values[ current_sent ]; //showmessage (value); {$REGION 'Запрос к базе на создание записи'} with SQL_DM.mysql_query_sp do begin try Close; Params.Clear; SQL.Text:= ''; SQL.Text := ' CALL rd_insert_values(:in_measure_ID, :in_param_ID, :in_repeat_ID,'+ ' :in_point_ID, :in_value, @out_ErrorMessage, @out_Success);'; Params.ParamByName( 'in_measure_ID' ).Value := self.ID; Params.ParamByName( 'in_param_ID' ).Value := i; Params.ParamByName( 'in_repeat_ID' ).Value := self.current_sent; Params.ParamByName( 'in_point_ID' ).Value := self.point_values.Get_current_item_index + 1; DecimalSeparator := '.'; Params.ParamByName( 'in_value' ).Value := value; DecimalSeparator := ','; Prepare; Execute; except on E: Exception do begin Exit; end; end; try Close; //выборка выходных переменных процедуры SQL.Clear; SQL.Text := 'SELECT @out_Success, @out_ErrorMessage;'; Execute; except on E: Exception do begin Exit; end; end; Result.Success :=Result.Success and strtobool( FieldByName( '@out_Success' ).AsString ); Result.Error_message := ( FieldByName( '@out_ErrorMessage' ).AsString ); end; {$ENDREGION} end; end; procedure TRDMeasure.Load_values_to_database; begin //информация об измрении Check_and_save_measure_info; case time_to_load_to_database of ttltd_IMMEDIATELY: begin if not Load_current_params_values_to_database.Success then; end; ttltd_AFTER_POINT: begin end; ttltd_AFTER_LIMB: begin end; ttltd_AFTER_ALL_LIMBS: begin end; ttltd_AFTER_ALL_POINTS: begin end; end; 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; procedure TRDMeasure.Set_current_sent (in_count: integer); begin self.current_sent := in_count; end; function TRDMeasure.Set_measure_date( in_measure_date: string ): boolean; begin Assert( ( in_measure_date <> '' ) , 'Входное поле Date измерения класса RDMeasure недопустимо!'+'{EFCE36FB-9E58-4437-9492-856026C3105C}'); try strtodatetime( 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.patinent_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; procedure TRDMeasure.Set_total_sent(in_count: integer); begin self.total_sent := in_count; end; function TRDMeasure.Write_values(incoming_params: params_record): boolean; begin //проверка на ошибки Check_errors(incoming_params); // пока очень упрощенно with self.point_values.Get_current_point.Params do begin Find_by_name('R').models.Get_current_model.sources.src_device.Set_one_value( incoming_params.R_device, self.current_sent ); //showmessage(Find_by_name('R').models.Get_current_model.sources.src_device.Get_values[current_sent]); Find_by_name('G0').models.Get_current_model.sources.src_device.Set_one_value( incoming_params.g0_device, self.current_sent ); Find_by_name('G1').models.Get_current_model.sources.src_device.Set_one_value( incoming_params.g1_device, self.current_sent ); Find_by_name('G2').models.Get_current_model.sources.src_device.Set_one_value( incoming_params.g2_device, self.current_sent ); Find_by_name('G3').models.Get_current_model.sources.src_device.Set_one_value( incoming_params.g3_device, self.current_sent ); Find_by_name('C').models.Get_current_model.sources.src_device.Set_one_value( incoming_params.C_device, self.current_sent ); Find_by_name('Uсм').models.Get_current_model.sources.src_device.Set_one_value( incoming_params.Usm_device, self.current_sent ); end; result := true; 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; procedure TRDMeasure.Check_current_sent; begin if ( ( current_sent mod REPEAT_AMOUNT ) = 0 ) then begin point_values.Next_point; end; end; procedure TRDMeasure.Check_errors(var message_:params_record); begin ///////////////////////////////// //Обработка ошибок в измерении // ///////////////////////////////// if message_.U_mis then begin //если была ошибка, то обнуляем результаты if null_wrong_values then begin message_.R_calc:=0; message_.C_calc:=0; message_.g0_calc:=0; message_.g1_calc:=0; message_.g2_calc:=0; message_.g3_calc:=0; message_.Usm_calc:=0; message_.R_device:=0; message_.C_device:=0; message_.g0_device:=0; message_.g1_device:=0; message_.g2_device:=0; message_.g3_device:=0; message_.Usm_device:=0; end; end; if message_.I_mis then begin //если была ошибка, то обнуляем результаты if null_wrong_values then begin message_.R_calc:=0; message_.C_calc:=0; message_.g0_calc:=0; message_.g1_calc:=0; message_.g2_calc:=0; message_.g3_calc:=0; message_.Usm_calc:=0; message_.R_device:=0; message_.C_device:=0; message_.g0_device:=0; message_.g1_device:=0; message_.g2_device:=0; message_.g3_device:=0; message_.Usm_device:=0; end; end; end; end.