Esempio n. 1
0
class DiagnoseSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Diagnose

    id = ma.auto_field()
    code = ma.auto_field()
    mkb = fields.Nested('MkbSchema')
Esempio n. 2
0
class MkbSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Mkb

    id = ma.auto_field()
    name = ma.auto_field()
    codes = ma.auto_field()
Esempio n. 3
0
class TestSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Test

    id = ma.auto_field()
    name = ma.auto_field()
    unit = ma.auto_field()
    type = ma.auto_field()
Esempio n. 4
0
class DepartmentSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Department

    id = ma.auto_field()
    code = ma.auto_field()
    name = ma.auto_field()
    region = ma.auto_field()
Esempio n. 5
0
class ProductDetailsSchema(ma.SQLAlchemySchema):
    class Meta:
        model = ProductModel

    product_name = ma.auto_field()
    sale_price = ma.auto_field()
    mrp = ma.auto_field()
    discount = fields.Float()
Esempio n. 6
0
class SampleSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Sample

    id = ma.auto_field()
    type = ma.auto_field()
    date = ma.auto_field()
    patient_id = ma.auto_field()
    results = fields.Nested('SampleResultSchema', many=True)
Esempio n. 7
0
class ItemSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = ItemModel
        include_relationships = True
        include_fk = True
        load_instance = True

    id = ma.auto_field(dump_only=True)
    store = ma.auto_field(load_only=True)
Esempio n. 8
0
class UserSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = UserModel
        include_relationships = True
        load_instance = True

    id = ma.auto_field(dump_only=True)
    password = ma.auto_field(load_only=True)
    activated = ma.auto_field(dump_only=True)
Esempio n. 9
0
class PatientSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Patient

    id = ma.auto_field()
    patient_id = ma.auto_field()
    gender = ma.auto_field()
    birth_date = ma.auto_field()
    diagnoses = fields.Nested('DiagnoseSchema', many=True)
    samples = fields.Nested('SampleSchema', many=True)
Esempio n. 10
0
class UserSchema(ma.SQLAlchemySchema):
    class Meta:
        model = User

    id = ma.auto_field()
    username = ma.auto_field()
    firstname = ma.auto_field()
    lastname = ma.auto_field()
    isAdmin = ma.auto_field()

    user_profile = ma.Nested("UserProfileSchema")
Esempio n. 11
0
class UserSignUpSchema(ma.SQLAlchemySchema):
    class Meta:
        model = UserModel
        load_only = ("password",)
        dump_only = ("id",)

    # This auto fielding code can be removed by putting ma.SQLAlchemyAutoSchema instead of ma.SQLAlchemySchema
    id = ma.auto_field()
    username = ma.auto_field()
    email = ma.auto_field()
    mobile_number = ma.auto_field()
    password = ma.auto_field()
Esempio n. 12
0
class StoreSchema(ma.SQLAlchemyAutoSchema):
    items = ma.Nested(ItemSchema, many=True)

    class Meta:
        model = StoreModel
        include_relationships = True
        include_fk = True
        load_instance = True

    id = ma.auto_field(dump_only=True)
Esempio n. 13
0
class PositionSchema(ma.SQLAlchemySchema):
    class Meta:
        model = PositionsModel
        ordered = True

    __envelope__ = {
        "single": None,
        "many": "positions"
    }  # for dumping many as dict with key 'positions'

    id = ma.auto_field(dump_only=True)
    quantity = ma.auto_field()
    position_date = ma.Date(
        data_key='date',
        required=True)  # position_date will be called date in payload
    unit_cost = ma.auto_field()
    stock_id = ma.auto_field(dump_only=True)

    def get_envelope_key(self, many):
        """Helper to get the envelope key."""
        key = self.__envelope__["many"] if many else self.__envelope__["single"]
        #assert key is not None, "Envelope key undefined"
        return key

    @post_dump(pass_many=True)
    def wrap_with_envelope(self, data, many, **kwargs):
        key = self.get_envelope_key(many)
        return {key: data}

    @validates(UNIT_COST)
    def validate_unit_cost(self, value):
        value = float(value)
        if value != round(value, 2):
            raise ValidationError(NOT_VALID_COST)

    @validates(QUANTITY)
    def validate_quantity(self, value):
        if value <= 0:
            raise ValidationError(NOT_POSITIVE_VALUE)
Esempio n. 14
0
class StockSchema(ma.SQLAlchemySchema):
    class Meta:
        model = StockModel
        ordered = True
        positions = ma.Nested(PositionSchema, many=True)

    id = ma.auto_field(dump_only=True)
    symbol = SymbolUpper(required=True)
    desc = ma.auto_field(required=True)
    quantity = ma.auto_field(missing=0)  # missing for default value
    unit_cost = ma.auto_field(missing=0)  # missing for default value
    stop_quote = ma.auto_field(missing=0)  # missing for default value
    price = PriceConvert(dump_only=True)

    @validates(SYMBOL)
    def validate_symbol(self, value):
        if len(value) > SYMBOL_MAX_LEN or not value.isalpha():
            raise ValidationError(NOT_VALID_SYMBOL)

    @validates(DESC)
    def validate_desc(self, value):
        if len(value) > DESC_MAX_LEN or not value.isprintable():
            raise ValidationError(NOT_VALID_DESC)
Esempio n. 15
0
class SampleResultSchema(ma.SQLAlchemySchema):
    class Meta:
        model = SampleResult

    result = ma.auto_field()
    test = fields.Nested('TestSchema')
Esempio n. 16
0
class DishSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Dish

    id = ma.auto_field()
    dish_name = ma.auto_field()
    main_dish = ma.auto_field()
    description = ma.auto_field()
    course = ma.auto_field()
    cuisine = ma.auto_field()
    prep_hour = ma.auto_field()
    prep_minute = ma.auto_field()
    cook_hour = ma.auto_field()
    cook_minute = ma.auto_field()
    serving_count = ma.auto_field()
    es_keywords = ma.auto_field()
    status = ma.auto_field()
    created_at = ma.auto_field()
    updated_at = ma.auto_field()

    user = ma.Nested("UserSchema", many=False)
    ingredients = ma.Nested("IngredientSchema", many=True)
    instruction = ma.Nested("PrepInstructionSchema", many=True)