#NEWLINE# def testPillboxCheck( self ) : #NEWLINE# #INDENT# '\n        This test tries to accomplish a few things\n        0: ensure the content of the signal is correctly set\n        1: verify that the dots_observations view is working correctly in reporting dates correclty back in order\n        2: Ensure that if you fill out the questions on the form, it won\'t redundantly fill out the pillbox cells again as well\n        3: ensure that proper ART/NonART sequences are put in the correct buckets when combined into a "DOTS Day" cell\n\n        todo: get label day_slot to work correctly\n        ' #NEWLINE# self . testSignal ( ) #NEWLINE# observations = query_observations ( CASE_ID , START_DATE , END_DATE ) #NEWLINE# td = ( END_DATE - START_DATE ) #NEWLINE# def check_obs_props( obs , props ) : #NEWLINE# #INDENT# for ( k , v ) in props . items ( ) : #NEWLINE# #INDENT# if k . endswith ( '_date' ) : #NEWLINE# #INDENT# obs_datetime = getattr ( obs , k ) #NEWLINE# val_datetime = dateutil . parser . parse ( v ) #NEWLINE# if ( k in ( 'completed_date' , 'created_date' ) ) : #NEWLINE# #INDENT# obs_datetime = ServerTime ( obs_datetime ) . user_time ( PACT_TIMEZONE ) . done ( ) #NEWLINE# #UNINDENT# obs_date = obs_datetime . date ( ) #NEWLINE# val_date = val_datetime . date ( ) #NEWLINE# self . assertEquals ( obs_date , val_date ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertEquals ( getattr ( obs , k ) , v , msg = ( "Error, observation %s\n\t%s didn't match: %s != %s" % ( json . dumps ( obs . to_json ( ) , indent = 4 ) , k , getattr ( obs , k ) , v ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for d in range ( td . days ) : #NEWLINE# #INDENT# this_day = ( START_DATE + timedelta ( days = d ) ) #NEWLINE# day_submissions = filter_obs_for_day ( this_day . date ( ) , observations ) #NEWLINE# day_data = DOTDay . merge_from_observations ( day_submissions ) #NEWLINE# if ( this_day . date ( ) == START_DATE . date ( ) ) : #NEWLINE# #INDENT# art_first = day_data . art . dose_dict [ 1 ] [ 0 ] #NEWLINE# art_first_check_props = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 2 , #NEWLINE# 'day_note' : 'art first noon' , #NEWLINE# 'day_index' : 20 , #NEWLINE# 'note' : '' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'pillbox' , #NEWLINE# 'observed_date' : '2012-11-17T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 1 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : True , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( art_first , art_first_check_props ) #NEWLINE# non_art_first_1 = day_data . nonart . dose_dict [ 1 ] [ 0 ] #NEWLINE# non_art_first_1_props = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 3 , #NEWLINE# 'day_note' : 'non art first evening' , #NEWLINE# 'day_index' : 20 , #NEWLINE# 'note' : '' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'pillbox' , #NEWLINE# 'observed_date' : '2012-11-17T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 1 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : False , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( non_art_first_1 , non_art_first_1_props ) #NEWLINE# non_art_first_2 = day_data . nonart . dose_dict [ 2 ] [ 0 ] #NEWLINE# non_art_first_2_props = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 3 , #NEWLINE# 'day_note' : 'non art bedtime first' , #NEWLINE# 'day_index' : 20 , #NEWLINE# 'note' : '' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'pillbox' , #NEWLINE# 'observed_date' : '2012-11-17T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 2 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : False , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( non_art_first_2 , non_art_first_2_props ) #NEWLINE# #UNINDENT# if ( this_day . date ( ) == ( ANCHOR_DATE - timedelta ( days = 1 ) ) . date ( ) ) : #NEWLINE# #INDENT# self . assertEquals ( len ( day_data . art . dose_dict . keys ( ) ) , 2 ) #NEWLINE# art_slast = day_data . art . dose_dict [ 0 ] [ 0 ] #NEWLINE# art_slast_props = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 2 , #NEWLINE# 'day_note' : '2nd to last last filled by questions' , #NEWLINE# 'day_index' : 1 , #NEWLINE# 'note' : '' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'pillbox' , #NEWLINE# 'observed_date' : '2012-12-06T05:00:00Z' , #NEWLINE# 'day_slot' : ( - 1 ) , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 0 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : True , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( art_slast , art_slast_props ) #NEWLINE# nonart_slast0 = day_data . nonart . dose_dict [ 0 ] [ 0 ] #NEWLINE# non_art0 = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 3 , #NEWLINE# 'day_note' : '' , #NEWLINE# 'day_index' : 1 , #NEWLINE# 'note' : '' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'direct' , #NEWLINE# 'observed_date' : '2012-12-06T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'empty' , #NEWLINE# 'dose_number' : 0 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : False , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( nonart_slast0 , non_art0 ) #NEWLINE# nonart_slast1 = day_data . nonart . dose_dict [ 1 ] [ 0 ] #NEWLINE# non_art1 = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 3 , #NEWLINE# 'day_note' : 'non art noon second to last' , #NEWLINE# 'day_index' : 1 , #NEWLINE# 'note' : '' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'pillbox' , #NEWLINE# 'observed_date' : '2012-12-06T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 1 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : False , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( nonart_slast1 , non_art1 ) #NEWLINE# nonart_slast2 = day_data . nonart . dose_dict [ 2 ] [ 0 ] #NEWLINE# non_art2 = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 3 , #NEWLINE# 'day_note' : 'art evening second to last' , #NEWLINE# 'day_index' : 1 , #NEWLINE# 'note' : '' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'pillbox' , #NEWLINE# 'observed_date' : '2012-12-06T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 2 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : False , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( nonart_slast2 , non_art2 ) #NEWLINE# #UNINDENT# if ( this_day . date ( ) == ANCHOR_DATE . date ( ) ) : #NEWLINE# #INDENT# self . assertEqual ( len ( day_data . nonart . dose_dict [ 0 ] ) , 1 ) #NEWLINE# non_art_last = day_data . nonart . dose_dict [ 0 ] [ 0 ] #NEWLINE# non_art_last_props = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 3 , #NEWLINE# 'day_note' : '' , #NEWLINE# 'day_index' : 0 , #NEWLINE# 'note' : 'Anchor same' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'direct' , #NEWLINE# 'observed_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 0 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : False , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( non_art_last , non_art_last_props ) #NEWLINE# non_art_last_noon = day_data . nonart . dose_dict [ 1 ] [ 0 ] #NEWLINE# non_art_last_noon_props = { #NEWLINE# #INDENT# 'encounter_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'total_doses' : 3 , #NEWLINE# 'day_note' : 'non art noon last' , #NEWLINE# 'day_index' : 0 , #NEWLINE# 'note' : 'Anchor same' , #NEWLINE# 'pact_id' : '999999' , #NEWLINE# 'provider' : 'ctsims' , #NEWLINE# 'method' : 'pillbox' , #NEWLINE# 'observed_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'completed_date' : '2012-12-16T22:00:28.847000Z' , #NEWLINE# 'adherence' : 'partial' , #NEWLINE# 'dose_number' : 1 , #NEWLINE# 'is_reconciliation' : False , #NEWLINE# 'anchor_date' : '2012-12-07T05:00:00Z' , #NEWLINE# 'created_date' : '2012-12-16T21:37:52.771000Z' , #NEWLINE# 'is_art' : False , #NEWLINE# '_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# 'doc_id' : 'a1811d7e-c968-4b63-aea5-6195ce0d8759' , #NEWLINE# #UNINDENT# } #NEWLINE# check_obs_props ( non_art_last_noon , non_art_last_noon_props ) #NEWLINE# #UNINDENT# pass