<s> from django . core . management . base import LabelCommand <EOL> from corehq . apps . indicators . models import ( CaseDataInFormIndicatorDefinition , FormDataAliasIndicatorDefinition , <EOL> FormDataInCaseIndicatorDefinition , BaseDocumentIndicatorDefinition ) <EOL> from mvp . models import MVP <EOL> from mvp . static_definitions . question_id_mapping import ( CHILD_CLOSE_FORM_QUESTION_IDS , CHILD_VISIT_QUESTION_IDS , <EOL> HOUSEHOLD_VISIT_QUESTION_IDS , PREGNANCY_VISIT_QUESTION_IDS , <EOL> PREGNANCY_CLOSE_FORM_QUESTION_IDS , <EOL> CHILD_REGISTRATION_QUESTION_IDS ) <EOL> class Command ( LabelCommand ) : <EOL> help = "<STR_LIT>" <EOL> args = "<STR_LIT>" <EOL> label = "<STR_LIT>" <EOL> def handle ( self , * args , ** options ) : <EOL> for domain in MVP . DOMAINS : <EOL> shared_args = ( <EOL> MVP . NAMESPACE , <EOL> domain <EOL> ) <EOL> self . create_form_alias_indicators ( CHILD_REGISTRATION_QUESTION_IDS , <EOL> MVP . REGISTRATION_FORMS . get ( '<STR_LIT>' ) , domain , shared_args ) <EOL> self . create_form_alias_indicators ( CHILD_VISIT_QUESTION_IDS , <EOL> MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , domain , shared_args ) <EOL> self . create_form_alias_indicators ( HOUSEHOLD_VISIT_QUESTION_IDS , <EOL> MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , domain , shared_args ) <EOL> self . create_form_alias_indicators ( PREGNANCY_VISIT_QUESTION_IDS , <EOL> MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , domain , shared_args ) <EOL> self . create_form_alias_indicators ( CHILD_CLOSE_FORM_QUESTION_IDS , <EOL> MVP . CLOSE_FORMS . get ( '<STR_LIT>' ) , domain , shared_args ) <EOL> self . create_form_alias_indicators ( PREGNANCY_CLOSE_FORM_QUESTION_IDS , <EOL> MVP . CLOSE_FORMS . get ( '<STR_LIT>' ) , domain , shared_args ) <EOL> pregnancy_edd = CaseDataInFormIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> case_property = "<STR_LIT>" , <EOL> version = <NUM_LIT:1> <EOL> ) <EOL> print pregnancy_edd <EOL> pregnancy_end = CaseDataInFormIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> case_property = "<STR_LIT>" , <EOL> version = <NUM_LIT:1> <EOL> ) <EOL> print pregnancy_end <EOL> child_visit_referral = CHILD_VISIT_QUESTION_IDS . get ( '<STR_LIT>' , { } ) . get ( domain ) <EOL> if child_visit_referral : <EOL> child_case_referral_type = FormDataInCaseIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> case_type = '<STR_LIT>' , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> ** child_visit_referral <EOL> ) <EOL> print child_case_referral_type <EOL> pregnancy_visit_referral = PREGNANCY_VISIT_QUESTION_IDS . get ( '<STR_LIT>' , { } ) . get ( domain ) <EOL> if pregnancy_visit_referral : <EOL> pregnancy_case_referral_type = FormDataInCaseIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> case_type = '<STR_LIT>' , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> ** pregnancy_visit_referral <EOL> ) <EOL> print pregnancy_case_referral_type <EOL> visit_hospital = CHILD_VISIT_QUESTION_IDS . get ( '<STR_LIT>' , { } ) . get ( domain ) <EOL> if visit_hospital : <EOL> visit_hospital_case = FormDataInCaseIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> case_type = '<STR_LIT>' , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> ** visit_hospital <EOL> ) <EOL> print visit_hospital_case <EOL> immediate_danger_sign = CHILD_VISIT_QUESTION_IDS . get ( '<STR_LIT>' , { } ) . get ( domain ) <EOL> if immediate_danger_sign : <EOL> immediate_danger_sign_case = FormDataInCaseIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> case_type = '<STR_LIT>' , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> ** immediate_danger_sign <EOL> ) <EOL> print immediate_danger_sign_case <EOL> diarrhea_medication_in_case = CHILD_VISIT_QUESTION_IDS . get ( '<STR_LIT>' , { } ) . get ( domain ) <EOL> if diarrhea_medication_in_case : <EOL> diarrhea_medication_case = FormDataInCaseIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> case_type = '<STR_LIT>' , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> ** diarrhea_medication_in_case <EOL> ) <EOL> print diarrhea_medication_case <EOL> fever_medication_in_case = CHILD_VISIT_QUESTION_IDS . get ( '<STR_LIT>' , { } ) . get ( domain ) <EOL> if fever_medication_in_case : <EOL> fever_medication_case = FormDataInCaseIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = "<STR_LIT>" , <EOL> case_type = '<STR_LIT>' , <EOL> xmlns = MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> ** fever_medication_in_case <EOL> ) <EOL> print fever_medication_case <EOL> self . insert_dob_into_form ( '<STR_LIT>' , MVP . VISIT_FORMS . get ( '<STR_LIT>' ) , <EOL> shared_args ) <EOL> self . insert_dob_into_form ( '<STR_LIT>' , MVP . CLOSE_FORMS . get ( '<STR_LIT>' ) , <EOL> shared_args ) <EOL> def insert_dob_into_form ( self , indicator_slug , xmlns , shared_args , version = <NUM_LIT:1> ) : <EOL> child_dob = CaseDataInFormIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = indicator_slug , <EOL> xmlns = xmlns , <EOL> case_property = "<STR_LIT>" , <EOL> version = version <EOL> ) <EOL> print child_dob <EOL> def create_form_alias_indicators ( self , question_ids , xmlns , domain , shared_args ) : <EOL> for indicator_slug , ids_per_domain in question_ids . items ( ) : <EOL> indicator_info = ids_per_domain . get ( domain ) <EOL> if indicator_info : <EOL> form_question = FormDataAliasIndicatorDefinition . increment_or_create_unique ( <EOL> * shared_args , <EOL> slug = indicator_slug , <EOL> xmlns = xmlns , <EOL> ** indicator_info <EOL> ) <EOL> print form_question <EOL> def _delete_existing ( self ) : <EOL> print "<STR_LIT>" <EOL> all_indicators = BaseDocumentIndicatorDefinition . view ( "<STR_LIT>" , <EOL> reduce = False , <EOL> include_docs = True , <EOL> startkey = [ "<STR_LIT>" , MVP . NAMESPACE ] , <EOL> endkey = [ "<STR_LIT>" , MVP . NAMESPACE , { } ] <EOL> ) . all ( ) <EOL> for ind in all_indicators : <EOL> ind . delete ( ) </s>
