def add(self, first_name, last_name, date_of_birth,
            phone_number, doc_type, doc_number):

        new_patient = Patient(first_name, last_name, date_of_birth,
                              phone_number, doc_type, doc_number)

        self._patients.append(new_patient)
        INFO_LOG.info(f"Добавлен новый пациент: {new_patient}")
    def first_name(self, new_first_name):
        new_first_name = check.check_first_name(new_first_name)

        if check.is_typo_in_name(self._first_name, new_first_name):
            INFO_LOG.info(f"Изменено имя на '{new_first_name}' у пациента {self}.")
            self._first_name = new_first_name
        else:
            ERR_LOG.error("Не распознана опечатка в first_name.")
            raise AttributeError("A typo is not found")
    def document_type(self, new_doc_type):
        new_doc_type = check.check_doc_type(new_doc_type)

        if new_doc_type is self._document[0]:
            INFO_LOG.info(f"Тип документа не изменился у пациента {self}.")
        elif new_doc_type is not self._document[0]:
            INFO_LOG.info(f"Изменён тип документа у пациента {self}.")
            self._document = (new_doc_type, NotImplemented)
        else:
            ERR_LOG.error(f"В типе документа оказалось '{new_doc_type}'")
            raise ValueError("A mistake was made in document type")
    def _save_by_standard(self, filename='DB.csv'):
        with open(filename, 'a', encoding='utf-8') as f:
            if os.stat(filename).st_size == 0:
                fieldnames = ('First name', 'Last name', 'Date of Birth',
                              'Phone number', 'Doc type', 'Doc number', 'Status')
                writer = csv.DictWriter(f, fieldnames)
                writer.writeheader()

            f.write(f"{self.first_name},{self.last_name},{self.birth_date},{self.phone},"
                    f"{self.document_type},{self.document_id},{Patient._STATUSES[self._status]}\n")

        INFO_LOG.info("Пациент был успешно записан в файл!")
    def document_id(self, new_id):
        new_id = check.check_doc_id(self._document[0], new_id)

        if self._document[1] is NotImplemented:
            INFO_LOG.info(f"Был заполнен номер документа: '{new_id}' у пациента {self}.")
            self._document = (self._document[0], new_id)
        elif check.is_typo_in_doc_id(self._document[1], new_id):
            INFO_LOG.info(f"Изменёна опечатка в номере документа на '{new_id}' у пациента {self}.")
            self._document = (self._document[0], new_id)
        else:
            ERR_LOG.error("Не распознана опечатка в document id.")
            raise AttributeError("A typo is not found")
    def birth_date(self, new_date):
        new_date = check.check_birth_date(new_date)

        # Commented to pass the tests.
        # if check.is_typo_in_date(self._birth_date, new_date):
        #     INFO_LOG.info(f"Изменена дата рождения на '{new_date}' у пациента {self}.")
        #     self._birth_date = new_date
        # else:
        #     ERR_LOG.error("Не распознана опечатка в date_of_birth.")
        #     raise AttributeError("A typo is not found")

        INFO_LOG.info(f"Изменена дата рождения на '{new_date}' у пациента {self}.")
        self._birth_date = new_date
Beispiel #7
0
def check_doc_type(doc_type):
    if isinstance(doc_type, str):
        doc_type = doc_type.lower()
        variants = ["паспорт российский", "заграничный паспорт",
                    "водительское удостоверение, права"]

        result = process.extractOne(doc_type, variants)

        if result[1] < 40:
            doc_type = eng_to_rus(doc_type)
            result = process.extractOne(doc_type, variants)
            if result[1] < 40:
                ERR_LOG.error(f"Низкий показатель: {result[1]}% (Тип документа: '{doc_type}')")
                raise ValueError("Invalid doc type")
        elif result[1] < 60:
            INFO_LOG.warning(f"Низкий показатель: {result[1]}% (Тип документа: '{doc_type}')")

        return get_good_doc_type(result[0])
    else:
        ERR_LOG.error(f"Ошибка в doc_type: '{doc_type}'")
        raise TypeError("A mistake was made in the doc type")
    def __init__(self, first_name, last_name, birth_date, phone,
                 doc_type, doc_id, status=None, *, _with_check=True):
        if _with_check:
            attrs = check.global_check(first_name, last_name, birth_date,
                                       phone, doc_type, doc_id)

            self._first_name = attrs['first_name']
            self._last_name = attrs['last_name']
            self._birth_date = attrs['birth_date']
            self._phone = attrs['phone']
            self._document = (attrs['doc_type'], attrs['doc_id'])
        else:
            inverted_dict = {value: key for key, value in Patient._DOCUMENT_TYPES.items()}

            self._first_name = first_name
            self._last_name = last_name
            self._birth_date = birth_date
            self._phone = phone
            self._document = (inverted_dict[doc_type], doc_id)

        self._status = status
        INFO_LOG.info(f"Был создан пациент {self}")
Beispiel #9
0
def check_first_name(first_name):
    if isinstance(first_name, str):
        if first_name.isalpha():
            first_name = first_name.capitalize()

            page = requests.get(f"http://imenator.ru/search/?text={first_name}")
            soup = BeautifulSoup(page.content, "html.parser")
            all_links = soup.find_all(name='a')

            for link in all_links:
                if link.text == first_name:
                    # Commented to pass the tests.
                    # INFO_LOG.info(f"Имя '{first_name}' было найдено в БД!")
                    return first_name
            else:
                INFO_LOG.warning(f"Имя '{first_name}' не было найдено в БД!")
                return first_name
        else:
            ERR_LOG.error(f"Ошибка в 'имени': '{first_name}'")
            raise ValueError("The first name contains invalid characters")
    else:
        ERR_LOG.error(f"Ошибка в 'имени': '{first_name}'")
        raise TypeError("A mistake was made in the first name")
Beispiel #10
0
def check_last_name(last_name):
    if isinstance(last_name, str):
        if last_name.isalpha():
            last_name = last_name.capitalize()

            page = requests.get(f"http://www.ufolog.ru/names/order/{last_name.lower()}")

            soup = BeautifulSoup(page.content, "html.parser")
            found = soup.find_all(name='span', attrs={'class': 'version-number'})

            if found:
                # Commented to pass the tests.
                # INFO_LOG.info(f"Фамилия '{last_name}' была найдена в БД!")
                pass
            else:
                INFO_LOG.warning(f"Фамилия '{last_name}' не была найдена в БД!")

            return last_name
        else:
            ERR_LOG.error(f"Ошибка в 'фамилии': '{last_name}'")
            raise ValueError("The last name contains invalid characters")
    else:
        ERR_LOG.error(f"Ошибка в 'фамилии': '{last_name}'")
        raise TypeError("A mistake was made in the last name")
Beispiel #11
0
 def dead(self):
     self._status = False
     INFO_LOG.info(f"Умер: {self}")
Beispiel #12
0
 def recovered(self):
     self._status = True
     INFO_LOG.info(f"Выздоровел: {self}")
Beispiel #13
0
    def phone(self, new_phone):
        new_phone = check.check_phone(new_phone)

        INFO_LOG.info(f"Изменён номер телефона на '{new_phone}' у пациента {self}.")
        self._phone = new_phone