示例#1
0
async def delete(book_id: int, db: DatabaseSession = Depends(get_db)):
    model = db.query(Book).filter(Book.id == book_id).first()
    db.delete(model)
    db.commit()
    return {
        'id': model.id,
    }
示例#2
0
async def update(book_id: int, db: DatabaseSession = Depends(get_db)):
    model = db.query(Book).filter(Book.id == book_id).first()
    model.read = True
    db.add(model)
    db.commit()
    return {
        'id': model.id,
    }
示例#3
0
 def __init__(self):
     self.input_to_idschema: Dict = getInputToIdSchemaMapping()
     self.api_helper = MosipSession(conf.server,
                                    conf.client_id,
                                    conf.secret_key,
                                    conf.app_id,
                                    ssl_verify=conf.ssl_verify)
     self.db_session = DatabaseSession(conf.db_host, conf.db_port,
                                       conf.db_user, conf.db_pass)
     self.execute()
示例#4
0
async def create(book: BookModel, db: DatabaseSession = Depends(get_db)):
    now = datetime.now()
    model = Book(title=book.title, created_at=now, read=False)
    db.add(model)
    db.commit()
    return {
        'id': model.id,
        'title': model.title,
        'created_at': model.created_at.isoformat()
    }
示例#5
0
	def delVariantDB(self, data):
		logging.info("delVariantDB")
		with DatabaseSession(self.engine) as session:
				variant_code = md5(data['itemid']  + data['name']).hexdigest()
				variant_data = session.query(Variant).get(variant_code)
				if variant_data == None:
					return False
				else:
					try:
						session.query(Property).filter(Property.variant_code==variant_code).delete(synchronize_session='fetch')
						session.delete(variant_data)
						session.commit()
					except Exception as e:
						session.rollback()

					changelog = Changelog( mode = "DEL",
										   user = data['user'],
										   variants_category = True,
										   item_category = True,
										   item_data = json.dumps({"productcode" : data['itemid']}),
										   variants_data = json.dumps({"variant_code" : variant_code,
																	   "variant_name" : data['name']})
										   )
					session.add(changelog)
					session.flush()
					session.commit()
					logging.debug("Wrote activity log for delVariant")
					return True
示例#6
0
	def addItemDB(self, data):
		logging.info("addItemDB")
		with DatabaseSession(self.engine) as session:
			instance = Item( name = data['name'],
							 brand = data['brand'],
							 category = data['category'],
							 productCode = data['productcode']
							 )
			

			changelog = Changelog( mode = "ADD",
								   user = data['user'],
								   item_category = True,
								   item_data = json.dumps({"productcode" : data['productcode']})
								   )
			session.add(changelog)
			session.flush()
			session.commit()
			logging.debug("Wrote activity log for addItem")
							
			try:			 
				session.add(instance)
				session.flush()
				session.commit()
				return True
			except exc.IntegrityError as e:
				logging.error('Integrity Error Exception when addITEM : \n %s',e )
				session.rollback()
				return False

		return False
示例#7
0
	def editVariantDB(self, data):
		logging.info("editVariantDB")
		with DatabaseSession(self.engine) as session:
			variant_code = md5( data['itemid']  + data['name']  ).hexdigest()
			variant_data = session.query(Variant).get(variant_code)
			if variant_data == None:
				return False
			else:
				temp = {}
				if  variant_data.name != data["name"]:
					 variant_data.name = data["name"]
					 temp["name"] = data["name"]

				print variant_data.sellingPrice, data["sellingprice"] 
				if variant_data.sellingPrice != data["sellingprice"]:
					variant_data.sellingPrice = data["sellingprice"]
					temp["sellingprice"] = data["sellingprice"]

				if variant_data.costPrice != data["costprice"]:
					variant_data.costPrice = data["costprice"]
					temp["costprice"] = data["costprice"]

				if variant_data.quantity != data["quantity"]:
					variant_data.quantity = data["quantity"]
					temp["quantity"] = data["quantity"]

				properties = json.loads(data['properties'])
				variant_data.name = data["name"]
				variant_data.sellingPrice = data["sellingprice"]
				variant_data.costPrice = data["costprice"]
				variant_data.quantity = data["quantity"]

				session.add(variant_data)
				session.flush()
				session.commit()

				session.query(Property).filter(Property.variant_code==variant_code).update({ "size":properties['size'],
										"cloth": properties['cloth'] }, 
										synchronize_session='fetch')
				session.commit()

				print temp
				if temp != {}:
	
					temp["variant_code"] = variant_code
					changelog = Changelog( mode = "EDIT",
										   user = data['user'],
										   item_category = True,
										   variants_category = True,
										   item_data = json.dumps({"productcode" : data['itemid']}),
										   variants_data = json.dumps(temp)
										  )
					session.add(changelog)
					session.flush()
					session.commit()
					logging.debug("Wrote activity log for editVariant")


				return True     
 def select_doctor_by_patient(patientId):
     with DatabaseSession() as session:
         doctor = session.query(Doctor, Patient) \
             .with_entities(Doctor) \
             .filter(patientId == Patient.id) \
             .filter(Doctor.id == Patient.doctorId) \
             .first()
         return doctor
 def get_patient_list_from_doctor(self, doctorId):
     """
     :param doctorId:
     :return: patient list
     """
     with DatabaseSession() as session:
         patients = session.query(Patient) \
             .filter(doctorId == Patient.doctorId)
         return patients
 def update_user_type(self, userId, userType):
     with DatabaseSession() as session:
         account = session.query(Account) \
             .filter(userId == Account.id).first()
         if account_is_none(account):
             return False
         account.userType = userType
         session.commit()
         return account
 def update_push_token(self, userId, pushToken):
     with DatabaseSession() as session:
         account = session.query(Account) \
             .filter(userId == Account.id).first()
         if account_is_none(account):
             return False
         account.pushToken = pushToken
         session.commit()
         return True
 def update_profile_image(self, googleId, image):
     with DatabaseSession() as session:
         account = session.query(Account) \
             .filter(googleId == Account.id).first()
         if account_is_none(account):
             return False
         account.image = image
         session.commit()
         return account
 def update_doctorId_in_patient(self, doctorId, patientId):
     with DatabaseSession() as session:
         account = session.query(Patient) \
             .filter(patientId == Patient.googleId).first()
         if account_is_none(account):
             return False
         account.doctorId = doctorId
         session.commit()
         return True
 def get_all_patient_measures(self, patientId):
     """
     :param patientId:
     :return: a list of measures
     """
     with DatabaseSession() as session:
         events = session.query(Measure) \
             .filter(patientId == Measure.patientId) \
             .all()
         return events
 def get_all_patient_prescriptions(self, patientId):
     """
     :param patientId:
     :return: a list of prescriptions
     """
     with DatabaseSession() as session:
         events = session.query(Prescription) \
             .filter(patientId == Prescription.patientId) \
             .all()
         return events
 def get_all_doctor(self):
     """
     :return: list of all doctor
     """
     with DatabaseSession() as session:
         doctor = session.query(Doctor) \
             .all()
         #for d in doctor:
         #   print(d.name)
         return doctor
 def get_user_by_id(self, userId):
     """
     :param userId:
     :return: user entry
     """
     with DatabaseSession() as session:
         account = session.query(Account) \
             .filter(userId == Account.id) \
             .first()
         return account
 def get_last_patient_comment(self, patientId):
     """
     :param patientId:
     :return:
     """
     with DatabaseSession() as session:
         comment = session.query(Schedule) \
             .filter(patientId == Schedule.patientId) \
             .order_by(text('dateStart desc')) \
             .first()
         return comment
 def get_push_token(self, googleId):
     """
     :param googleId:
     :return: pushToken
     """
     with DatabaseSession() as session:
         pushToken = session.query(Account) \
             .filter(googleId == Account.id) \
             .first()
         if pushToken is None:
             return None
         return pushToken.pushToken
    def get_doctor(self, doctorId):
        """

        :param doctorId:
        :return: doctor row
        """
        with DatabaseSession() as session:
            doctor = session.query(Doctor) \
                .filter(doctorId == Doctor.googleId) \
                .first()
            if doctor is None:
                return False
            return doctor
    def get_patient(self, patientId):
        """

        :param patientId:
        :return: patient row
        """
        with DatabaseSession() as session:
            patient = session.query(Patient) \
                .filter(patientId == Patient.googleId) \
                .first()
            if patient is None:
                return False
            return patient
 def get_doctor_image(self, doctorId):
     """
     :param doctorId: it works also with patientId
     :return: return the doctor image
     """
     with DatabaseSession() as session:
         image = session.query(Account) \
             .with_entities(Account.image) \
             .filter(doctorId == Account.id) \
             .first()
         if image is not None:
             image = image.image
         return image
示例#23
0
	def addVariantDB(self, data):
		logging.info("addVariantDB")
		with DatabaseSession(self.engine) as session:

			var_code = md5( data['itemid']  + data['name']  ).hexdigest()
			properties = json.loads(data['properties'])
			instance = Variant( 
								var_code = var_code,
								name = data['name'],
								sellingPrice = data['sellingprice'],
								costPrice = data['costprice'],
								quantity = data['quantity'],
								item_id = data["itemid"]
								)

			changelog = Changelog( mode = "ADD",
					   user = data['user'],
					   item_category = True,
					   variants_category = True,
					   item_data = json.dumps({"productcode" : data['itemid']}),
					   variants_data = json.dumps({"variant_code" : var_code,
												   "variant_name" : data['name']})
					  )
			session.add(changelog)
			session.flush()
			session.commit()
			logging.debug("Wrote activity log for addVariant")

			
			try:
				session.add(instance)
				session.flush()
				session.commit()
			except exc.IntegrityError as e:
				logging.error('Integrity Error Exception when addITEM : \n %s',e )
				session.rollback()
				return False

			properties = Property( cloth = properties['cloth'],
								   size = properties['size'] ,
								   variant_code = var_code
								  )

			session.add(properties)
			session.flush()
			session.commit()



			return True
		return False
 def get_event_by_patient(self, patientId):
     """
     :param patientId:
     :return: a list of Event objects
     .. note:: you can access to parameters like this:
         for ev in event:
             print(ev.dateStart)
     """
     with DatabaseSession() as session:
         events = session.query(Patient, Schedule) \
             .with_entities(Schedule) \
             .filter(patientId == Schedule.patientId) \
             .all()
         return events
 def select_event_by_doctor(self, doctorId):
     """
     :param doctorId:
     :return: a list of Event objects
     .. note:: you can access to parameters like this:
         for ev in event:
             print(ev.dateStart)
     """
     with DatabaseSession() as session:
         events = session.query(Doctor, Schedule) \
             .with_entities(Schedule) \
             .filter(doctorId == Schedule.doctorId) \
             .all()
         return events
 def get_prescription_file(self, patientId, pathFileSystem):
     """
     :param patientId:
     :param pathFileSystem:
     :return: return the prescription image
     """
     with DatabaseSession() as session:
         file = session.query(Prescription) \
             .with_entities(Prescription.pathFileSystem) \
             .filter(patientId == Prescription.patientId) \
             .filter(pathFileSystem == Prescription.pathFileSystem) \
             .first()
         if file is not None:
             file = file.pathFileSystem
         return file
示例#27
0
    def delete_account_by_email(self, email):
        """
        Deletes a user account by email, if it exists;
        :param email: user's email
        """
        user_entity = Account

        with DatabaseSession() as session:
            data = session.query(user_entity). \
                filter(user_entity.email == email). \
                first()
            if data is None:
                return False

            session.delete(data)
            session.commit()
            return True
示例#28
0
	def editItemDB(self, data):
		logging.info("editItemDB")
		with DatabaseSession(self.engine) as session:
			item_data = session.query(Item).get(data['productcode'])
			if item_data == None:
				return False
			else:
				temp = {}
				if item_data.name != data["name"]:
					item_data.name = data["name"]
					temp["name"] = data["name"]

				if item_data.brand != data["brand"]:
					item_data.brand = data["brand"]
					temp["brand"] = data["brand"]

				if item_data.category != data["category"]:
					item_data.category = data["category"]
					temp["category"] = data["category"]

				session.add(item_data)
				session.commit()

				if temp != {} :

					temp["productcode"] = data["productcode"]

					changelog = Changelog( mode = "EDIT",
										   user = data['user'],
										   item_category = True,
										   item_data = json.dumps(temp)
										)
					session.add(changelog)
					session.flush()
					session.commit()
					logging.debug("Wrote activity log for editItem")

				return True	
		return False
示例#29
0
async def get(book_id: int, db: DatabaseSession = Depends(get_db)):
    return db.query(Book).filter(Book.id == book_id).first()
示例#30
0
async def index(db: DatabaseSession = Depends(get_db)):
    return db.query(Book).order_by(desc(Book.id)).all()