-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundling.py
56 lines (44 loc) · 1.91 KB
/
bundling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import concurrent.futures
from typing import List
import random
from faker import Faker
from patients import add_patient_query, get_patient
from analysis import add_ar_query, gen_ar_request
from core import run_query, authenticate
import logging
engine = Faker()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def do_work(username):
credentials = {
'username': username,
'password': "!Felicity#100" if username == 'admin' else "@Access123!",
}
auth_headers = authenticate(credentials)
pt_variables, client = get_patient(username)
pt_reg = run_query(query=add_patient_query, variables={"payload": pt_variables}, headers=auth_headers)
logger.info(f"Created patient: {pt_reg}")
# add analysis request for created patient
ar_variables = {
"clientRequestId": engine.ssn(),
"clientUid": pt_variables["clientUid"],
"clientContactUid": client["contacts"][0]["uid"],
"patientUid": pt_reg['data']['createPatient']['uid'],
"priority": random.choice([0, 1, 2]),
"samples": [gen_ar_request(username) for _ in range(random.randint(1, 2))],
}
run_query(query=add_ar_query, variables={"payload": ar_variables}, headers=auth_headers)
def patient_plus_ar_reg(usernames: List[str], total):
with concurrent.futures.ThreadPoolExecutor(max_workers=len(usernames)) as executor:
future_to_url = (executor.submit(do_work, random.choice(usernames)) for _ in range(total))
for future in concurrent.futures.as_completed(future_to_url):
try:
data = future.result()
logger.info("Done")
except Exception as exc:
logger.error(exc)
if __name__ == '__main__':
from users import init_users
usernames = init_users()
usernames = list(filter(lambda un: un not in ["admin", "system_daemon"], usernames))
patient_plus_ar_reg(usernames, 5)