diff --git a/apps/bb2_tools/admin.py b/apps/bb2_tools/admin.py index 81c02a60c..2b819ee69 100644 --- a/apps/bb2_tools/admin.py +++ b/apps/bb2_tools/admin.py @@ -20,6 +20,7 @@ ArchivedTokenStats, DummyAdminObject, UserStats, + SyntheticBeneficiaryFilter, ) from apps.fhir.bluebutton.utils import get_patient_by_id @@ -802,6 +803,30 @@ def changelist_view(self, request, extra_context=None): return response +@admin.register(SyntheticBeneficiaryFilter) +class SyntheticBeneficiaryAdmin(admin.ModelAdmin): + # Add fields to display + list_display = ( + "beneficiary_id", + "mbi_unhashed", + "medicaid_un", + "medicaid_pw", + "age", + "part_d_events_total", + ) + + advanced_filter_list = () + + list_filter = ('state',) + + search_fields = ( + "beneficiary_id", + "mbi_unhashed", + "medicaid_un", + "medicaid_pw", + ) + + class UserTypeFilter(admin.SimpleListFilter): title = "User type" parameter_name = "userprofile__type" diff --git a/apps/bb2_tools/migrations/0004_syntheticbeneficiary_syntheticbeneficiaryfilter.py b/apps/bb2_tools/migrations/0004_syntheticbeneficiary_syntheticbeneficiaryfilter.py new file mode 100644 index 000000000..03e6373b1 --- /dev/null +++ b/apps/bb2_tools/migrations/0004_syntheticbeneficiary_syntheticbeneficiaryfilter.py @@ -0,0 +1,52 @@ +# Generated by Django 4.2.17 on 2024-12-18 05:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bb2_tools', '0003_delete_v2user'), + ] + + operations = [ + migrations.CreateModel( + name='SyntheticBeneficiary', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('beneficiary_id', models.CharField(db_column='fhir_id', db_index=True, default=None, max_length=80, unique=True)), + ('mbi_unhashed', models.CharField(db_column='user_mbi', db_index=True, default=None, max_length=11, unique=True, verbose_name='HASH of User MBI ID')), + ('medicaid_un', models.TextField()), + ('medicaid_pw', models.TextField()), + ('age', models.IntegerField()), + ('first_name', models.TextField()), + ('last_name', models.TextField()), + ('address_1', models.TextField()), + ('address_2', models.TextField(blank=True, null=True)), + ('city', models.TextField()), + ('state', models.TextField()), + ('postal_code', models.TextField()), + ('part_d_contract_number', models.TextField(blank=True, null=True)), + ('carrier_claims_total', models.IntegerField(default=0)), + ('dme_claims_total', models.IntegerField(default=0)), + ('hha_claims_total', models.IntegerField(default=0)), + ('hospice_claims_total', models.IntegerField(default=0)), + ('inpatient_claims_total', models.IntegerField(default=0)), + ('outpatient_claims_total', models.IntegerField(default=0)), + ('snf_claims_total', models.IntegerField(default=0)), + ], + ), + migrations.CreateModel( + name='SyntheticBeneficiaryFilter', + fields=[ + ], + options={ + 'verbose_name': 'Synthetic Beneficiary Filter', + 'verbose_name_plural': 'Synthetic Beneficiary Filters', + 'proxy': True, + 'indexes': [], + 'constraints': [], + }, + bases=('bb2_tools.syntheticbeneficiary',), + ), + ] diff --git a/apps/bb2_tools/models.py b/apps/bb2_tools/models.py index f51b7d059..40affb0e7 100644 --- a/apps/bb2_tools/models.py +++ b/apps/bb2_tools/models.py @@ -1,3 +1,4 @@ +from django.db import models from oauth2_provider.models import AccessToken, RefreshToken from apps.accounts.models import UserProfile @@ -84,3 +85,60 @@ class Meta: app_label = "bb2_tools" verbose_name = "Application statistics" verbose_name_plural = "Application statistics" + + +class SyntheticBeneficiary(models.Model): + beneficiary_id = models.CharField( + max_length=80, + null=False, + unique=True, + default=None, + db_column="fhir_id", + db_index=True, + ) + mbi_unhashed = models.CharField( + max_length=11, + verbose_name="Unhashed MBI", + unique=True, + null=False, + default=None, + db_column="user_mbi", + db_index=True, + ) + medicaid_un = models.TextField(null=False) + medicaid_pw = models.TextField(null=False) + age = models.IntegerField(null=False) + first_name = models.TextField(null=False) + last_name = models.TextField(null=False) + address_1 = models.TextField(null=False) + address_2 = models.TextField(blank=True, null=True) + city = models.TextField(null=False) + state = models.TextField(null=False) + postal_code = models.TextField(null=False) + part_d_contract_number = models.TextField(blank=True, null=True) + carrier_claims_total = models.IntegerField(default=0) + dme_claims_total = models.IntegerField(default=0) + hha_claims_total = models.IntegerField(default=0) + hospice_claims_total = models.IntegerField(default=0) + inpatient_claims_total = models.IntegerField(default=0) + outpatient_claims_total = models.IntegerField(default=0) + snf_claims_total = models.IntegerField(default=0) + + @property + def part_d_events_total(self): + return self.carrier_claims_total + \ + self.dme_claims_total + \ + self.hha_claims_total + \ + self.hospice_claims_total + \ + self.inpatient_claims_total + \ + self.outpatient_claims_total + \ + self.snf_claims_total + + +class SyntheticBeneficiaryFilter(SyntheticBeneficiary): + + class Meta: + proxy = True + app_label = "bb2_tools" + verbose_name = "Synthetic Beneficiary Filter" + verbose_name_plural = "Synthetic Beneficiary Filters" diff --git a/apps/dot_ext/migrations/0008_alter_application_data_access_type.py b/apps/dot_ext/migrations/0008_alter_application_data_access_type.py new file mode 100644 index 000000000..53ed8ffac --- /dev/null +++ b/apps/dot_ext/migrations/0008_alter_application_data_access_type.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.17 on 2024-12-18 05:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dot_ext', '0007_merge_20231020_2004'), + ] + + operations = [ + migrations.AlterField( + model_name='application', + name='data_access_type', + field=models.CharField(choices=[('ONE_TIME', 'ONE_TIME - No refresh token needed.'), ('RESEARCH_STUDY', 'RESEARCH_STUDY - No expiration.'), ('THIRTEEN_MONTH', 'THIRTEEN_MONTH - Access expires in 13-months.')], default='THIRTEEN_MONTH', max_length=16, null=True, verbose_name='Data Access Type:'), + ), + ] diff --git a/hhs_oauth_server/settings/base.py b/hhs_oauth_server/settings/base.py index 9c17aee88..79a22b985 100644 --- a/hhs_oauth_server/settings/base.py +++ b/hhs_oauth_server/settings/base.py @@ -150,6 +150,7 @@ "rest_framework", "rest_framework_csv", "django_filters", + "advanced_filters", # 1st Party (in-house) ---------- "apps.accounts", "apps.capabilities",