Ejemplo n.º 1
0
 def adaugare(self, nume, producator, pret, reteta):
     med = Medicament(nume, producator, pret, reteta)
     med.id_entity = self.id_count
     self.__vali.validare(med)
     self.__repo.creeaza(med)
     self.__undo_op.append(lambda: self.__repo.sterge(med.id_entity))
     self.__redo_op.append(lambda: self.__repo.creeaza(med))
Ejemplo n.º 2
0
 def medicament_increase_price(self, percentage, bound_value):
     result = map(
         lambda c: Medicament(c.id_entity, c.name, c.manufacturer, (
             1 + percentage) * c.price, c.requires_prescription)
         if c.price < bound_value else c, self.get_all())
     for ent in result:
         self.__repository.update(ent)
Ejemplo n.º 3
0
    def modificare(self, id_med, nume, producator, pret, reteta):
        med_de_modificat = self.__repo.citeste(id_med)
        if nume == '':
            nume = med_de_modificat.nume
        if producator == '':
            producator = med_de_modificat.producator
        if pret == '':
            pret = med_de_modificat.pret
        else:
            pret = float(pret)
        if reteta == '':
            reteta = med_de_modificat.reteta
        med = Medicament(nume, producator, pret, reteta)

        med.id_entity = med_de_modificat.id_entity
        self.__vali.validare(med)
        self.__repo.modifica(med)
        self.__undo_op.append(lambda: self.__repo.modifica(med_de_modificat))
        self.__redo_op.append(lambda: self.__repo.modifica(med))
Ejemplo n.º 4
0
 def update_medicament(self, id_medicament, name, manufacturer, price,
                       requires_prescription):
     """
     Updates a medicament.
     :param id_medicament:int, the id of the medicament.
     :param name:char, the name of the medicament.
     :param manufacturer:char, the name of the manufacturer.
     :param price:float, the price of the medicament, must be positive.
     :param requires_prescription:bool, True if the medicament requires a prescription, False otherwise.
     :return:
     """
     medicament = Medicament(id_medicament, name, manufacturer, price,
                             requires_prescription)
     self.__validator.validate(medicament)
     if requires_prescription == "yes":
         requires_prescription = True
     else:
         requires_prescription = False
     medicament = Medicament(id_medicament, name, manufacturer, price,
                             requires_prescription)
     self.__repository.update(medicament)
    def add_transaction(self, id_transaction, id_medicament, id_client_card,
                        number_of_meds, date_of_transaction):
        """
        Adds a new transaction.
        :param id_transaction: int, the id of the transaction
        :param id_medicament: int, the id of the medicament
        :param id_client_card: string for now, to be int, the id of the client card
        :param number_of_meds: int, the number of purchased meds
        :param date_of_transaction: date, the date of the transaction
        :param hour_of_transaction: date, the hour of the transaction
        """
        if id_client_card == "":
            id_client_card = None
        else:
            id_client_card = int(id_client_card)

        if self.__medicament_repository.read(id_medicament) is None:
            raise TransactionError(
                "There is no medicament with the ID {}".format(id_medicament))

        if self.__client_card_repository.read(
                id_client_card) is None and id_client_card is not None:
            raise TransactionError(
                "There is no client card with the ID {}".format(
                    id_client_card))

        effective_price = number_of_meds * self.__medicament_repository.read(
            id_medicament).price

        if self.__client_card_repository.read(id_client_card) is not None:
            if self.__medicament_repository.read(
                    id_medicament).requires_prescription is True:
                total_paid = 0.85 * effective_price
            else:
                total_paid = 0.9 * effective_price

        if id_client_card is None:
            total_paid = effective_price
        disc = effective_price - total_paid

        transaction = Transaction(id_transaction, id_medicament,
                                  id_client_card, number_of_meds,
                                  date_of_transaction, total_paid, disc)

        medicament = self.__medicament_repository.read(id_medicament)
        new_medicament = Medicament(id_medicament, medicament.name,
                                    medicament.manufacturer, medicament.price,
                                    medicament.requires_prescription)
        self.__medicament_repository.update(new_medicament)
        # de ce pisici e asta aici?

        client_card = self.__client_card_repository.read(id_client_card)
        # print(client_card)
        if client_card in self.__client_card_repository.read():
            new_client_card = ClientCard(id_client_card, client_card.surname,
                                         client_card.first_name,
                                         client_card.CNP,
                                         client_card.birth_date,
                                         client_card.register_date)
            self.__client_card_repository.update(new_client_card)

        client_card = self.__client_card_repository.read(id_client_card)
        new_client_card = ClientCard
        # again, de ce pisici e asta aici?

        self.__transaction_repository.create(transaction)
Ejemplo n.º 6
0
from domain.medicament import Medicament

med1 = Medicament(1, "Nurofen", "Paduden", 13, "no")
med2 = Medicament(2, "Aspirin", "Bayer", 10, "no")
med3 = Medicament(3, "Vicodin", "Abbott", 65, "yes")
med4 = Medicament(3, "aacodin", "Abbott", 65, "yes")

assert med1.id_entity == 1
assert med2.price == 10
assert med3.manufacturer == "Abbott"
assert med1 != med2
assert med3 == med4