def report_group_btn_clicked(self):
     if self.data_frame is not None and hasattr(self.data_frame,
                                                "save_report_group"):
         try:
             self.data_frame.save_report_group()
         except (ScienceError, Exception) as e:
             error_dialog(e, unknown=True)
     elif self.data_frame is not None:
         error_dialog(
             "Функция save_report_group не реализована у окна {}. Пожалуйста, свяжитесь с разработчиком"
             .format(type(self.data_frame).__name__))
 def add_std(self, fname):
     try:
         datas = science.read_xlsx_std(fname)
     except ClassesError as e:
         error_dialog(e)
         return
     except Exception as e:
         error_dialog(e, unknown=True)
         return
     for data in datas:
         Service.add_weather_measurements_params(data)
     self.from_date.setDate(Service.get_min_date())
     self.to_date.setDate(Service.get_max_date())
     self.update_boxes()
 def add_sample(self, fname):
     try:
         datas = science.read_xlsx_sample(fname)
     except ClassesError as e:
         error_dialog(e)
         return
     except Exception as e:
         error_dialog(e, unknown=True)
         return
     patients_id = self.ui_update.sampels_box.currentText().split(
         '(')[1].split(')')[0]
     for data in datas:
         Service.add_health_measurements_params(data, patients_id)
     self.from_date.setDate(Service.get_min_date())
     self.to_date.setDate(Service.get_max_date())
     self.update_boxes()
 def set_data_frame(self, frame_class, *args):
     if self.data_frame is not None:
         self.data_layout.removeWidget(self.data_frame)
         self.data_frame.hide()
         self.data_frame = None
     try:
         self.data_frame = frame_class(self, *args)
         self.data_layout.insertWidget(0, self.data_frame)
     except (ScienceError, Exception) as e:
         raise ValueError from e
         if frame_class == QFrameDefault:
             error_dialog(
                 "Ошибка в окне по умолчанию. Свяжитесь с разработчиком")
             sys.exit(1)
         error_dialog(e, unknown=True)
         self.data_frame = None
         self.set_data_frame(QFrameDefault)
    def choose_data_frame(self):
        orientation = self.lead_box.currentText().split(' ')[0] == "Погода:"
        lead = self.lead_box.currentText().split(': ')[1]
        slave = self.slave_box.currentText().split(': ')[1]

        # Погода - образец
        if orientation:
            if lead in Standard.standards and (slave in Sample.samples
                                               or slave == "--Групповой--"):
                self.set_data_frame(QFrameStdSample, lead, slave)
            elif lead in Standard.standards and slave == "--Группа--":
                if len(Sample.samples) < 3:
                    error_dialog(
                        "Для составления отчета по группе эталонов необходимо как минимум 3 образца"
                    )
                    return
                self.set_data_frame(QFrameStdMulSamples, lead)
            else:
                error_dialog(
                    "Необработанный случай выбора фрейма: lead={}, slave={}, orient={}"
                    .format(lead, slave, orientation),
                    unknown=True)
        # Образец - погода
        else:
            if (lead in Sample.samples or lead
                    == "--Групповой--") and slave in Standard.standards:
                self.set_data_frame(QFrameSampleStd, lead, slave)
            else:
                error_dialog(
                    "Необработанный случай выбора фрейма: lead={}, slave={}, orient={}"
                    .format(lead, slave, orientation),
                    unknown=True)
 def lead_box_activated(self):
     lead_type = self.lead_box.currentText().split(' ')[0]
     if lead_type == 'Образец:':
         items = [
             "Погода: " + str(self.stds_list[i])
             for i in range(len(self.stds_list))
         ]
     elif lead_type == 'Погода:':
         items = ["Образец: " + str(self.samples_list[i]) for i in range(len(self.samples_list))] + \
                 ["Образец: --Группа--"]
     else:
         error_dialog(
             "Неизвестный тип данных в боксе: {}".format(lead_type),
             unknown=True)
         return
     if self.slave_box.count():
         slave_type = self.slave_box.currentText().split(' ')[0]
         if slave_type != lead_type:
             self.choose_data_frame()
             return
     self.slave_box.clear()
     self.slave_box.addItems(items)
    def accept(self):
        self.result = []
        # Факторы
        if self.btn_all.isChecked():
            factor = FACTORS_ALL
        else:
            for idx in range(4):
                if self.__dict__["btn_{}".format(idx)].isChecked():
                    factor = idx
                    break
            else:
                error_dialog("Не выбран ни один фактор/все факторы")
                return
        self.result.append(factor)
        # Эталоны
        if self.get_stds:
            stds = [cb.text() for cb in self.cbs if cb.isChecked()]
            if not len(stds):
                error_dialog("Выберите по крайней мере один эталон")
                return
            self.result.append(stds)

        QDialog.accept(self)
    def update_boxes(self):
        if self.to_date.date() > Service.get_max_date():
            error_dialog(
                'Ошибка! Дата не должна превосходить максимально возможную: ' +
                Service.get_max_date().strftime('%d.%m.%Y'))
            self.to_date.setDate(Service.get_max_date())
        if self.from_date.date() < Service.get_min_date():
            error_dialog(
                'Ошибка! Дата не должна быть меньше минимальной возможной: ' +
                Service.get_min_date().strftime('%d.%m.%Y'))
            self.from_date.setDate(Service.get_min_date())

        Sample.samples = {}
        Standard.standards = {}
        self.from_date.text()
        self.to_date.text()
        std_items = []
        self.lead_box.clear()
        self.slave_box.clear()
        from_date = self.from_date.text()
        to_date = self.to_date.text()
        self.samples_list = Service.get_all_patients_full_name_date_filter(
            from_date, to_date)
        if int(Service.get_all_weather_date_filter_count(from_date,
                                                         to_date)) != 0:
            self.stds_list = [*STANDART_ITEMS.keys()]
        else:
            self.stds_list = []
        if self.stds_list is not None:
            for standart in STANDART_ITEMS.keys():
                weather_params = Service.get_weather_measurement(
                    from_date, to_date, STANDART_ITEMS.get(standart))
                Standard(standart, weather_params)
            std_items = [
                "Погода: " + str(self.stds_list[i])
                for i in range(len(self.stds_list))
            ]
        if self.samples_list is not None:
            symmetry_all_state = []
            for sample in self.samples_list:
                patients_id = sample.split('(')[1].split(')')[0]
                symmetry_all_state.append(
                    Service.get_all_patients_params_date_filter(
                        patients_id, from_date, to_date, 1))
                symmetry_all_state.append(
                    Service.get_all_patients_params_date_filter(
                        patients_id, from_date, to_date, 2))
                symmetry_all_state.append(
                    Service.get_all_patients_params_date_filter(
                        patients_id, from_date, to_date, 3))
                symmetry_all_state.append(
                    Service.get_all_patients_params_date_filter(
                        patients_id, from_date, to_date, 4))
                Sample(sample, symmetry_all_state)
            if len(self.samples_list) != 0:
                self.samples_list.append("--Групповой--")
            sample_items = [
                "Образец: " + str(self.samples_list[i])
                for i in range(len(self.samples_list))
            ]
        self.lead_box.addItems(std_items + sample_items)