def get_encounters_by_client_id(self, client_id):
        encounters = []
        for encounter_dict in self.db.encounters.find({"client_id":
                                                       client_id}):
            encounter = Encounter()
            encounter.Populate(encounter_dict)
            encounters.append(encounter)

        return encounters
Beispiel #2
0
def encounter_post():
	global logged_in_user
	if (not logged_in_user):
		return render_template('login.html')

	encounter = Encounter()
	encounter.Populate(request.form)
	db.insert_encounter(encounter)
	client_id = encounter.client_id
	return redirect('/client?client_id=' + str(client_id))
Beispiel #3
0
def encounter_put():
	global logged_in_user
	if (not logged_in_user):
		return render_template('login.html')

	encounter = Encounter()
	encounter.Populate(request.form)
	encounter_id = encounter._id
	db.update_encounter(encounter)
	encounter = db.get_encounter_by_id(encounter_id)
	client_id = encounter.client_id
	return url_for('client_get', client_id=client_id)
 def get_encounter_by_id(self, encounter_id):
     """
         Args:
             encounter_id (str): a unique identifier for an encounter
         Returns:
             Encounter: an encounter object
             None: if no such encounter id exists
     """
     encounter_dict = self.db.encounters.find_one(
         {"_id": ObjectId(encounter_id)})
     encounter = Encounter()
     encounter.Populate(encounter_dict)
     return encounter
    def get_all_encounters(self):
        """
            Args:
                None
            Returns:
                list: A list of all encounters currently in the database
            
        """
        encounters = []
        for encounter_dict in self.db.encounters.find():
            encounter = Encounter()
            encounter.Populate(encounter_dict)
            encounters.append(encounter)

        return encounters
Beispiel #6
0
def encounter_search_query():
	query = {}

	for arg in request.args:
                val = request.args.get(arg)
                if val:
                    query[arg] = val
       
	keys = query.keys()
	for key in keys:
		query[key] = re.compile(query[key], re.IGNORECASE)

	encounters = []
	encounterEntries = db.db.encounters.find(query)
	for encounterEntry in encounterEntries:
		encounter = Encounter()
		encounter.Populate(encounterEntry)
		encounters.append(encounter.__dict__)

	return json.dumps(encounters, default=str)
    def generate_random_json(self, client_count, encounter_count):
        clients = []
        encounters = []

        for x in range(client_count):
            client = Client()
            client.Randomize()
            clients.append(client.__dict__)

        for x in range(encounter_count):
            encounter = Encounter()
            encounter.Randomize()
            encounters.append(encounter.__dict__)

        with open('RawData/initialDbData.json', 'w') as json_file:
            json.dump({
                'clients': clients,
                'encounters': encounters
            },
                      json_file,
                      indent=4,
                      sort_keys=True,
                      default=str)
    def initialize_from_json(self):
        self.db.encounters.drop()
        self.db.clients.drop()

        with open('RawData/initialDbData.json') as json_file:
            json_db_entries = json.load(json_file)

            for client in json_db_entries['clients']:
                client_class = Client()
                client_class.Populate(client)
                self.insert_client(client_class)

            clients = list(self.db.clients.find())

            for encounter in json_db_entries['encounters']:
                randomClient = random.choice(clients)
                randomClientId = randomClient['_id']

                encounter['client_id'] = randomClientId

                encounter_class = Encounter()
                encounter_class.Populate(encounter)
                encounterId = self.insert_encounter(encounter_class)

                randomClient['encounter_ids'].append(encounterId)
                self.db.clients.update_one({"_id": ObjectId(randomClientId)},
                                           {"$set": randomClient})

        client_count = len(self.get_all_clients())
        encounter_count = len(self.get_all_encounters())

        self.db.encounters.create_index([("_id", pymongo.ASCENDING)])
        self.db.clients.create_index([("_id", pymongo.ASCENDING)])

        print("Initialized DB with %s clients and %s encounters" %
              (client_count, encounter_count))