Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/fhir/bluebutton/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
# Real fhir_id Manager subclass
class RealCrosswalkManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(~Q(fhir_id__startswith='-') & ~Q(fhir_id=''))
return super().get_queryset().filter(~Q(_fhir_id__startswith='-') & ~Q(_fhir_id=''))


# Synthetic fhir_id Manager subclass
class SynthCrosswalkManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(Q(fhir_id__startswith='-'))
return super().get_queryset().filter(Q(_fhir_id__startswith='-'))


def hash_hicn(hicn):
Expand Down
26 changes: 25 additions & 1 deletion apps/fhir/bluebutton/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.core.exceptions import ValidationError
from apps.test import BaseApiTest

from ..models import Crosswalk
from ..models import Crosswalk, check_crosswalks
from ...server.models import ResourceRouter


Expand Down Expand Up @@ -91,3 +91,27 @@ def test_immuatble_user_id_hash(self):
self.assertEqual(cw.user_id_hash, self.test_hash)
with self.assertRaises(ValidationError):
cw.user_id_hash = "239e178537ed3bc486e6a7195a47a82a2cd6f46e911660fe9775f6e0dd3f1130"

def test_crosswalk_real_synth_query_managers(self):
# Test the RealCrosswalkManager and SynthCrosswalkManager queryset managers using
# the check_crosswalks method.

# Create 5x Real (positive FHIR_ID) users
for cnt in range(5):
self._create_user('johnsmith' + str(cnt), 'password',
first_name='John1' + str(cnt),
last_name='Smith',
email='john' + str(cnt) + '@smith.net',
fhir_id='2000000000000' + str(cnt),
user_id_hash='239e178537ed3bc486e6a7195a47a82a2cd6f46e911660fe9775f6e00000000' + str(cnt))

# Create 7x Synthetic (negative FHIR_ID) users
for cnt in range(7):
self._create_user('johndoe' + str(cnt), 'password',
first_name='John1' + str(cnt),
last_name='Doe',
email='john' + str(cnt) + '@doe.net',
fhir_id='-2000000000000' + str(cnt),
user_id_hash='255e178537ed3bc486e6a7195a47a82a2cd6f46e911660fe9775f6e00000000' + str(cnt))

self.assertEqual("{'synthetic': 7, 'real': 5}", str(check_crosswalks()))
6 changes: 4 additions & 2 deletions apps/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ class Meta:
def get_beneficiaries(self, obj):
distinct = AccessToken.objects.filter(application=obj.id).distinct('user').values('user')

real_cnt = Crosswalk.real_objects.filter(user__in=[item['user'] for item in distinct]).values('user', 'fhir_id').count()
synth_cnt = Crosswalk.synth_objects.filter(user__in=[item['user'] for item in distinct]).values('user', 'fhir_id').count()
real_cnt = Crosswalk.real_objects.filter(
user__in=[item['user'] for item in distinct]).values('user', '_fhir_id').count()
synth_cnt = Crosswalk.synth_objects.filter(
user__in=[item['user'] for item in distinct]).values('user', '_fhir_id').count()

return({'real': real_cnt, 'synthetic': synth_cnt})

Expand Down