Skip to content

Commit

Permalink
[DA-4659] Adding check for test account for NPH Opt In Sync (#4037)
Browse files Browse the repository at this point in the history
* adding test account check

* fix iter in test
  • Loading branch information
dtharpeuno authored Jan 9, 2025
1 parent b72d5d1 commit 65792bd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
12 changes: 10 additions & 2 deletions rdr_service/dao/ppsc_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sqlalchemy.orm import aliased

from rdr_service.dao.base_dao import BaseDao, UpsertableDao
from rdr_service.model.ppsc import Participant, Site, NPHOptInEvent, ProfileUpdatesEvent
from rdr_service.model.ppsc import Participant, Site, NPHOptInEvent, ProfileUpdatesEvent, ParticipantStatusEvent
from rdr_service.model.study_nph import EligibleParticipants


Expand Down Expand Up @@ -135,6 +135,12 @@ def get_eligible_participant_records(self):
).outerjoin(
EligibleParticipants,
EligibleParticipants.primary_participant_id == ProfileUpdatesEvent.participant_id
).outerjoin(
ParticipantStatusEvent,
and_(
ParticipantStatusEvent.participant_id == ProfileUpdatesEvent.participant_id,
ParticipantStatusEvent.event_type_name.ilike('%Test Account%')
)
).filter(
ProfileUpdatesEvent.data_element_name.in_(
['piiname_first',
Expand All @@ -145,7 +151,8 @@ def get_eligible_participant_records(self):
'language_preference']
),
profile_updates_alias.id.is_(None),
EligibleParticipants.id.is_(None)
EligibleParticipants.id.is_(None),
ParticipantStatusEvent.id.is_(None)
).group_by(
ProfileUpdatesEvent.participant_id,
case(
Expand Down Expand Up @@ -210,3 +217,4 @@ def insert_bulk(self, batch: List[Dict]) -> None:
self.model_type,
batch
)

11 changes: 10 additions & 1 deletion rdr_service/data_gen/generators/ppsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rdr_service import clock
from rdr_service.dao import database_factory
from rdr_service.model.ppsc import Participant, Activity, EnrollmentEventType, ConsentEvent, ProfileUpdatesEvent, \
SurveyCompletionEvent, PartnerActivity, Site, ParticipantEventActivity, NPHOptInEvent
SurveyCompletionEvent, PartnerActivity, Site, ParticipantEventActivity, NPHOptInEvent, ParticipantStatusEvent
from rdr_service.model.ppsc_partner_data_transfer import (
PPSCDataTransferAuth, PPSCDataTransferEndpoint,
PPSCDataTransferRecord, PPSCHealthData, PPSCBiobankSample, PPSCEHR, PPSCCore, RTINphOptIn, RTIDataTransferEndpoint
Expand Down Expand Up @@ -215,3 +215,12 @@ def create_database_nph_opt_in_event(self, **kwargs):
event = self._nph_opt_in_event(**kwargs)
self._commit_to_database(event)
return event

@staticmethod
def _participant_status_event(**kwargs):
return ParticipantStatusEvent(**kwargs)

def create_database_participant_status_event(self, **kwargs):
participant_status_event = self._participant_status_event(**kwargs)
self._commit_to_database(participant_status_event)
return participant_status_event
21 changes: 20 additions & 1 deletion tests/ppsc_tests/test_ppsc_partner_data_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,32 @@ def test_get_eligible_nph_participants(self) -> None:
event_authored_time=clock.CLOCK.now()
)

# add test participant
if current_participant_ids[num] == 100000001:
status_elements = {
'activity_status': 'test',
'activity_date_time': clock.CLOCK.now()
}
for key in status_elements:
self.ppsc_data_gen.create_database_participant_status_event(
participant_id=current_participant_ids[num],
event_type_name='Test Account',
event_id=participant_event_activity_profile.id,
data_element_name=key,
data_element_value=status_elements[key],
event_authored_time=clock.CLOCK.now()
)

nph_opt_in_sync = NphOptInSync()
nph_opt_in_sync.run_sync()

self.assertEqual(len(nph_opt_in_sync.items_ready_for_sync), 2)
self.assertEqual(len(nph_opt_in_sync.items_ready_for_sync), 1)

current_sync_ids = [obj.participant_id for obj in nph_opt_in_sync.items_ready_for_sync]

# check test participant not included
self.assertTrue(100000001 not in current_sync_ids)

# eligible records
updated_eligible_records = [obj for obj in self.eligible_dao.get_all()
if obj.primary_participant_id in current_sync_ids]
Expand Down

0 comments on commit 65792bd

Please sign in to comment.