mirror of
https://github.com/beak-insights/felicity-lims.git
synced 2025-02-24 17:02:55 +08:00
seperated felicity faker from main project
This commit is contained in:
parent
90c4eca3ec
commit
e40b84fd18
5 changed files with 0 additions and 222 deletions
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
from patients import start_patient_reg
|
|
||||||
from analysis import start_ar_reg
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print("Faking Felicity Data....... .....")
|
|
||||||
# start_patient_reg()
|
|
||||||
start_ar_reg()
|
|
|
@ -1,80 +0,0 @@
|
||||||
import concurrent.futures
|
|
||||||
from faker import Faker
|
|
||||||
import requests
|
|
||||||
import random
|
|
||||||
import time
|
|
||||||
from core import run_query, authenticate, do_work
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
engine = Faker()
|
|
||||||
|
|
||||||
add_ar_query = """
|
|
||||||
mutation AddAnalysisRequest ($clientRequestId: String!, $clientUid: Int!, $patientUid: Int!, $samples: [ARSampleInputType!]!) {
|
|
||||||
createAnalysisRequest(clientRequestId: $clientRequestId, clientUid: $clientUid, patientUid: $patientUid, samples: $samples) {
|
|
||||||
uid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def gen_sample():
|
|
||||||
randoms = [
|
|
||||||
{
|
|
||||||
"sampletypes": [2,3],
|
|
||||||
"analyses": [None, 1,2,3],
|
|
||||||
"profiles": [None, 1,2],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"sampletypes": [4],
|
|
||||||
"analyses": [3],
|
|
||||||
"profiles": [None],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
while True:
|
|
||||||
selected = random.choice(randoms)
|
|
||||||
s_typ = random.choice(selected.get("sampletypes"))
|
|
||||||
anal = random.choice(selected.get("analyses"))
|
|
||||||
prof = random.choice(selected.get("profiles"))
|
|
||||||
|
|
||||||
if anal or prof:
|
|
||||||
break
|
|
||||||
|
|
||||||
return {
|
|
||||||
"sampleType": s_typ,
|
|
||||||
"profiles": [prof] if prof else [],
|
|
||||||
"analyses": [anal] if anal else []
|
|
||||||
}
|
|
||||||
|
|
||||||
ar_variables = [ # list of lists - each list will be run in its own thread -> simulating multi user regs
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"clientRequestId": engine.ssn(),
|
|
||||||
"clientUid": random.randint(1, 9),
|
|
||||||
"patientUid": random.randint(5, 1650),
|
|
||||||
"priority":random.choice([0, 1]),
|
|
||||||
"samples": [gen_sample() for _x in range(random.randint(1, 5))],
|
|
||||||
} for i in range(100)
|
|
||||||
] for x in range(10)
|
|
||||||
]
|
|
||||||
|
|
||||||
# def do_work1(var_list):
|
|
||||||
# auth_headers = authenticate()
|
|
||||||
#
|
|
||||||
# for variables in var_list:
|
|
||||||
# run_query(query=add_patient_query, variables=variables, headers=auth_headers)
|
|
||||||
#
|
|
||||||
|
|
||||||
def start_ar_reg():
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
|
|
||||||
future_to_url = (executor.submit(do_work, add_ar_query, variables) for variables in ar_variables)
|
|
||||||
|
|
||||||
for future in concurrent.futures.as_completed(future_to_url):
|
|
||||||
try:
|
|
||||||
data = future.result()
|
|
||||||
logger.info("Done")
|
|
||||||
except Exception as exc:
|
|
||||||
logger.error(exc)
|
|
|
@ -1,46 +0,0 @@
|
||||||
import requests
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def run_query(query=None, variables=None, headers=None):
|
|
||||||
if not query:
|
|
||||||
raise Exception("Query must be provided")
|
|
||||||
|
|
||||||
request = requests.post(
|
|
||||||
'http://127.0.0.1:8000/felicity-gql',
|
|
||||||
json={'query': query, 'variables': variables} if query else {'query': self.query, 'variables': variables},
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
if request.status_code == 200:
|
|
||||||
logger.info(request.json())
|
|
||||||
return request.json()
|
|
||||||
else:
|
|
||||||
raise Exception(f"({request.status_code}): Query Failed: {request.text}")
|
|
||||||
|
|
||||||
|
|
||||||
def authenticate():
|
|
||||||
qry = """
|
|
||||||
mutation AuthenticateUser($username: String!, $password: String!) {
|
|
||||||
authenticateUser(password: $password, username: $username) {
|
|
||||||
token
|
|
||||||
tokenType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
variables = {
|
|
||||||
'username': 'admin',
|
|
||||||
'password': 'admin',
|
|
||||||
}
|
|
||||||
auth = run_query(query=qry, variables=variables)
|
|
||||||
token = auth["data"]["authenticateUser"]['token']
|
|
||||||
return {"Authorization": f"bearer {token}"}
|
|
||||||
|
|
||||||
|
|
||||||
def do_work(query: str = None, var_list: list= None):
|
|
||||||
auth_headers = authenticate()
|
|
||||||
|
|
||||||
for variables in var_list:
|
|
||||||
run_query(query=query, variables=variables, headers=auth_headers)
|
|
|
@ -1,84 +0,0 @@
|
||||||
import concurrent.futures
|
|
||||||
from faker import Faker
|
|
||||||
import requests
|
|
||||||
import random
|
|
||||||
import time
|
|
||||||
from core import run_query, authenticate, do_work
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
engine = Faker()
|
|
||||||
|
|
||||||
add_patient_query = """
|
|
||||||
mutation AddPatient(
|
|
||||||
$clientPatientId: String!,
|
|
||||||
$firstName: String!,
|
|
||||||
$middleName: String,
|
|
||||||
$lastName: String!,
|
|
||||||
$age: Int!,
|
|
||||||
$gender: Int!,
|
|
||||||
$dateOfBirth: DateTime,
|
|
||||||
$ageDobEstimated: Boolean,
|
|
||||||
$clientUid: Int!,
|
|
||||||
$phoneMobile: String!,
|
|
||||||
$phoneHome: String!,
|
|
||||||
$consentSms: Boolean,
|
|
||||||
){
|
|
||||||
createPatient(
|
|
||||||
clientPatientId: $clientPatientId,
|
|
||||||
firstName: $firstName,
|
|
||||||
middleName: $middleName,
|
|
||||||
lastName: $lastName,
|
|
||||||
age: $age,
|
|
||||||
gender: $gender,
|
|
||||||
dateOfBirth: $dateOfBirth,
|
|
||||||
ageDobEstimated: $ageDobEstimated,
|
|
||||||
clientUid: $clientUid,
|
|
||||||
phoneMobile: $phoneMobile,
|
|
||||||
phoneHome: $phoneHome,
|
|
||||||
consentSms: $consentSms
|
|
||||||
) {
|
|
||||||
uid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
patient_variables = [ # list of lists - each list will be run in its own thread -> simulating multi user regs
|
|
||||||
[
|
|
||||||
{
|
|
||||||
'clientPatientId': engine.ssn(),
|
|
||||||
'firstName': engine.first_name(),
|
|
||||||
'middleName': engine.first_name(),
|
|
||||||
'lastName': engine.last_name(),
|
|
||||||
'age': random.randint(1, 90),
|
|
||||||
'gender': random.choice([1, 2, 3]),
|
|
||||||
'dateOfBirth': str(engine.date_time()),
|
|
||||||
'ageDobEstimated': engine.boolean(),
|
|
||||||
'clientUid': 1,
|
|
||||||
'phoneMobile': engine.phone_number(),
|
|
||||||
'phoneHome': engine.phone_number(),
|
|
||||||
'consentSms': engine.boolean(),
|
|
||||||
} for i in range(100)
|
|
||||||
] for x in range(10)
|
|
||||||
]
|
|
||||||
|
|
||||||
# def do_work1(var_list):
|
|
||||||
# auth_headers = authenticate()
|
|
||||||
#
|
|
||||||
# for variables in var_list:
|
|
||||||
# run_query(query=add_patient_query, variables=variables, headers=auth_headers)
|
|
||||||
#
|
|
||||||
|
|
||||||
def start_patient_reg():
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
|
|
||||||
future_to_url = (executor.submit(do_work, add_patient_query, variables) for variables in patient_variables)
|
|
||||||
|
|
||||||
for future in concurrent.futures.as_completed(future_to_url):
|
|
||||||
try:
|
|
||||||
data = future.result()
|
|
||||||
logger.info("Done")
|
|
||||||
except Exception as exc:
|
|
||||||
logger.error(exc)
|
|
Loading…
Reference in a new issue