From fb21e6fea377bb78216ece892a5becd205e99c1d Mon Sep 17 00:00:00 2001 From: Dave Tisza Date: Tue, 4 Feb 2020 17:08:30 -0500 Subject: [PATCH 1/4] Change to use _fhir_id in Real/Synth mgr queryset --- apps/fhir/bluebutton/models.py | 4 ++-- apps/metrics/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/fhir/bluebutton/models.py b/apps/fhir/bluebutton/models.py index 9fb45cede..c2be5bcd8 100644 --- a/apps/fhir/bluebutton/models.py +++ b/apps/fhir/bluebutton/models.py @@ -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): diff --git a/apps/metrics/views.py b/apps/metrics/views.py index 7b58db939..f3ea860d3 100644 --- a/apps/metrics/views.py +++ b/apps/metrics/views.py @@ -169,8 +169,8 @@ 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}) From 75b9b530115fa7d5f151ede74b2c54bc2f84274b Mon Sep 17 00:00:00 2001 From: Dave Tisza Date: Tue, 4 Feb 2020 17:59:00 -0500 Subject: [PATCH 2/4] Add test for Crosswalk synth/real query managers --- apps/fhir/bluebutton/tests/test_models.py | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/fhir/bluebutton/tests/test_models.py b/apps/fhir/bluebutton/tests/test_models.py index 2108999a7..3857f99b0 100644 --- a/apps/fhir/bluebutton/tests/test_models.py +++ b/apps/fhir/bluebutton/tests/test_models.py @@ -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 @@ -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): + user = 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): + user = 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())) From 76a9bc65fcdfdb85991724e88d70e6ef10dbfd76 Mon Sep 17 00:00:00 2001 From: Dave Tisza Date: Wed, 5 Feb 2020 12:28:06 -0500 Subject: [PATCH 3/4] Fix flake8 --- apps/fhir/bluebutton/tests/test_models.py | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/fhir/bluebutton/tests/test_models.py b/apps/fhir/bluebutton/tests/test_models.py index 3857f99b0..9c05dc49a 100644 --- a/apps/fhir/bluebutton/tests/test_models.py +++ b/apps/fhir/bluebutton/tests/test_models.py @@ -95,23 +95,23 @@ def test_immuatble_user_id_hash(self): 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): - user = 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)) + 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): - user = 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())) + 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())) From 2903f00cef1fe75ffbf4aabb3e3c6402336bf0f5 Mon Sep 17 00:00:00 2001 From: Dave Tisza Date: Wed, 5 Feb 2020 12:59:18 -0500 Subject: [PATCH 4/4] Fix flake8 --- apps/metrics/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/metrics/views.py b/apps/metrics/views.py index f3ea860d3..cd8fc7eeb 100644 --- a/apps/metrics/views.py +++ b/apps/metrics/views.py @@ -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})