<s> from corehq . apps . change_feed import topics <EOL> from dimagi . ext . couchdbkit import Document <EOL> from . import signals <EOL> from corehq . apps . users . models import CommCareCase <EOL> from custom . succeed . reports import VISIT_SCHEDULE , LAST_INTERACTION_LIST , PM3 <EOL> import fluff <EOL> from custom . utils . utils import flat_field <EOL> from fluff . filters import CustomFilter <EOL> LAST_VISIT = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : - <NUM_LIT:1> <EOL> } <EOL> class _ ( Document ) : <EOL> pass <EOL> def get_randomization_date ( case ) : <EOL> return case [ '<STR_LIT>' ] <EOL> def get_next_visit ( case ) : <EOL> actions = list ( case [ '<STR_LIT>' ] ) <EOL> next_visit = VISIT_SCHEDULE [ <NUM_LIT:0> ] <EOL> for visit_key , visit in enumerate ( VISIT_SCHEDULE ) : <EOL> is_ignored = case . get_case_property ( visit [ '<STR_LIT>' ] ) <EOL> completed = case . get_case_property ( visit [ '<STR_LIT>' ] ) <EOL> if completed != '<STR_LIT>' and is_ignored is not None and is_ignored . lower ( ) == '<STR_LIT:yes>' : <EOL> try : <EOL> next_visit = VISIT_SCHEDULE [ visit_key + <NUM_LIT:1> ] <EOL> except IndexError : <EOL> next_visit = LAST_VISIT <EOL> else : <EOL> for key , action in enumerate ( actions ) : <EOL> if visit [ '<STR_LIT>' ] == action [ '<STR_LIT>' ] : <EOL> try : <EOL> next_visit = VISIT_SCHEDULE [ visit_key + <NUM_LIT:1> ] <EOL> del actions [ key ] <EOL> break <EOL> except IndexError : <EOL> next_visit = LAST_VISIT <EOL> return next_visit <EOL> def visit_name ( case ) : <EOL> next_visit = get_next_visit ( case ) <EOL> return next_visit [ '<STR_LIT>' ] <EOL> def visit_days ( case ) : <EOL> next_visit = get_next_visit ( case ) <EOL> return next_visit [ '<STR_LIT>' ] <EOL> def is_active ( case ) : <EOL> active = '<STR_LIT:True>' <EOL> for action in case [ '<STR_LIT>' ] : <EOL> if PM3 == action [ '<STR_LIT>' ] : <EOL> active = '<STR_LIT:False>' <EOL> break <EOL> return active <EOL> def last_interaction ( case ) : <EOL> last_inter = None <EOL> for action in case [ '<STR_LIT>' ] : <EOL> if action [ '<STR_LIT>' ] in LAST_INTERACTION_LIST : <EOL> last_inter = action <EOL> return last_inter [ '<STR_LIT:date>' ] <EOL> def get_property ( case , property ) : <EOL> try : <EOL> category = case [ property ] <EOL> except AttributeError : <EOL> category = '<STR_LIT>' <EOL> return category <EOL> class RandomizationDate ( fluff . Calculator ) : <EOL> @ fluff . date_emitter <EOL> def date ( self , case ) : <EOL> yield { <EOL> '<STR_LIT:date>' : get_randomization_date ( case ) , <EOL> '<STR_LIT:value>' : <NUM_LIT:1> <EOL> } <EOL> class UCLAPatientFluff ( fluff . IndicatorDocument ) : <EOL> document_class = CommCareCase <EOL> domains = ( '<STR_LIT>' , ) <EOL> document_filter = CustomFilter ( lambda c : c . type == '<STR_LIT>' ) <EOL> group_by = ( '<STR_LIT>' , ) <EOL> save_direct_to_sql = True <EOL> kafka_topic = topics . CASE <EOL> name = flat_field ( lambda case : case . full_name ) <EOL> mrn = flat_field ( lambda case : case [ '<STR_LIT>' ] ) <EOL> owner_id = flat_field ( lambda case : case . owner_id ) <EOL> user_id = flat_field ( lambda case : case . user_id ) <EOL> bp_category = flat_field ( lambda case : get_property ( case , '<STR_LIT>' ) ) <EOL> care_site = flat_field ( lambda case : get_property ( case , '<STR_LIT>' ) . lower ( ) ) <EOL> is_active = flat_field ( lambda case : is_active ( case ) ) <EOL> visit_name = flat_field ( lambda case : visit_name ( case ) ) <EOL> visit_days = flat_field ( lambda case : visit_days ( case ) ) <EOL> last_interaction = flat_field ( lambda case : last_interaction ( case ) ) <EOL> emitter = RandomizationDate ( ) <EOL> UCLAPatientFluffPillow = UCLAPatientFluff . pillow ( ) </s>
