Skip to content

Commit 1a8d284

Browse files
change namespace for file, add additional necessary constraints
1 parent 25c215f commit 1a8d284

File tree

2 files changed

+54
-39
lines changed

2 files changed

+54
-39
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from django.core.management.base import BaseCommand
2+
from django.contrib.auth.models import User
3+
from oauth2_provider.models import AccessToken, RefreshToken
4+
from apps.fhir.bluebutton.models import Crosswalk
5+
from apps.dot_ext.models import ArchivedToken, Application
6+
from apps.authorization.models import update_grants, DataAccessGrant, ArchivedDataAccessGrant
7+
from tqdm import tqdm
8+
9+
APPLICATION_SCOPES_FULL = ['patient/Patient.read', 'profile',
10+
'patient/ExplanationOfBenefit.read', 'patient/Coverage.read',
11+
'capability-a', 'capability-b']
12+
APPLICATION_SCOPES_NON_DEMOGRAPHIC = ['patient/ExplanationOfBenefit.read',
13+
'patient/Coverage.read', 'capability-a', 'capability-b']
14+
15+
BENEFICIARY_COUNT = 10000
16+
DEVELOPER_COUNT = 50
17+
APPLICATION_PER_DEVELOPER = 2
18+
19+
def flush_database():
20+
"""Flush all data from the database."""
21+
crosswalk_rows = list(Crosswalk.objects.filter(fhir_id_v2__isnull=False))
22+
23+
# Modify in memory
24+
for crosswalk in crosswalk_rows:
25+
crosswalk.fhir_id_v2 = None
26+
27+
# Bulk update in chunks with progress
28+
batch_size = 1000
29+
total_updated = 0
30+
31+
for i in tqdm(range(0, len(crosswalk_rows), batch_size), desc='Writing to database'):
32+
batch = crosswalk_rows[i:i + batch_size]
33+
Crosswalk.objects.bulk_update(batch, ['fhir_id_v2'], batch_size=batch_size)
34+
total_updated += len(batch)
35+
36+
print(f'Updated {total_updated} rows')
37+
38+
def generate_test_data(bene_count, dev_count, app_per_dev):
39+
#TODO
40+
x = bene_count
41+
42+
class Command(BaseCommand):
43+
help = ('Create dev users and create'
44+
' apps for each of them, create bene users from '
45+
'synthetic data and crosswalk for each bene.')
46+
47+
def add_arguments(self, parser):
48+
parser.add_argument('--flush', default=False, help='Flush the database')
49+
50+
def handle(self, *args, **options):
51+
flush = bool(options['flush'])
52+
53+
if flush:
54+
flush_database()

apps/testclient/management/commands/load_test_data.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)