Exemplo n.º 1
0
def make_user_as_a_datasender(manager, organization, current_user_name,
                              mobile_number):
    total_entity = get_entity_count_for_type(manager, [REPORTER])
    reporter_short_code = 'rep' + str(total_entity + 1)
    entity = create_entity(dbm=manager,
                           entity_type=REPORTER_ENTITY_TYPE,
                           short_code=reporter_short_code,
                           location=[organization.country_name()])
    mobile_number_type = get_or_create_data_dict(manager,
                                                 name='Mobile Number Type',
                                                 slug='mobile_number',
                                                 primitive_type='string')
    name_type = get_or_create_data_dict(manager,
                                        name='Name',
                                        slug='name',
                                        primitive_type='string')
    data = [(MOBILE_NUMBER_FIELD, mobile_number, mobile_number_type),
            (NAME_FIELD, current_user_name, name_type)]
    entity.add_data(data=data)

    if organization.in_trial_mode:
        data_sender = DataSenderOnTrialAccount.objects.model(
            mobile_number=mobile_number, organization=organization)
        data_sender.save()
    return entity.short_code
Exemplo n.º 2
0
def _create_couchdb_datasender(manager, organization, current_user_name, mobile_number):
    total_entity = get_entity_count_for_type(manager, [REPORTER])
    reporter_short_code = 'rep' + str(total_entity + 1)
    entity = create_entity(dbm=manager, entity_type=REPORTER_ENTITY_TYPE, short_code=reporter_short_code,
                           location=[organization.country_name()])
    mobile_number_type = get_or_create_data_dict(manager, name='Mobile Number Type', slug='mobile_number',
                                                 primitive_type='string')
    name_type = get_or_create_data_dict(manager, name='Name', slug='name', primitive_type='string')
    data = [(MOBILE_NUMBER_FIELD, mobile_number, mobile_number_type), (NAME_FIELD, current_user_name, name_type)]
    entity.add_data(data=data)
    return reporter_short_code
Exemplo n.º 3
0
def create_default_reporter(manager):
    try:
        entity = get_by_short_code(manager, REPORTER_SHORT_CODE, REPORTER_ENTITY_TYPE)
        entity.delete()
    except DataObjectNotFound:
        pass
    entity = create_entity(dbm=manager, entity_type=REPORTER_ENTITY_TYPE, short_code=REPORTER_SHORT_CODE, location=DEFAULT_LOCATION)

    mobile_number_type = get_or_create_data_dict(manager, name='Mobile Number Type', slug='mobile_number',
                                                 primitive_type='string')
    name_type = get_or_create_data_dict(manager, name='Name', slug='name', primitive_type='string')

    data = [(MOBILE_NUMBER_FIELD, TEST_REPORTER_MOBILE_NUMBER,mobile_number_type),(NAME_FIELD,'TEST',name_type)]
    entity.add_data(data=data)
def migration_to_add_email_data_for_web_users_in_couch(db_name):
    logger = logging.getLogger(db_name)
    logger.info('Starting Migration')
    mark_as_completed(db_name)
    manager = get_db_manager(db_name)
    try:
        form_model = get_form_model_by_code(manager, REGISTRATION_FORM_CODE)
    except FormModelDoesNotExistsException as f:
        logger.warning(f.message)
        return
    email_type = get_or_create_data_dict(manager,
                                         name='Name',
                                         slug='name',
                                         primitive_type='string')

    email_field = TextField(name=EMAIL_FIELD,
                            code=EMAIL_FIELD,
                            label="What is the subject's email",
                            defaultValue="",
                            ddtype=email_type,
                            instruction="Enter email id",
                            constraints=[TextLengthConstraint(max=50)],
                            required=False)
    try:
        form_model.add_field(email_field)
        form_model.save()
        logger.info("Migrated registration form")
    except QuestionCodeAlreadyExistsException as e:
        logger.warning('email field is present' + e.message)
    except Exception as e:
        logger.exception(e.message)
Exemplo n.º 5
0
 def create_form_for_entity_type(self):
     string_data_type = get_or_create_data_dict(self.manager,
                                                name='Name',
                                                slug='name',
                                                primitive_type='string')
     school_name_field = TextField(name="name",
                                   code="q1",
                                   label="What's the name?",
                                   ddtype=string_data_type)
     address_field = TextField(name="address",
                               code="q2",
                               label="Where is the clinic?",
                               ddtype=string_data_type)
     unique_id_field = TextField(
         name="unique_id",
         code="q3",
         label="What is the clinic's Unique ID Number?",
         ddtype=string_data_type,
         entity_question_flag=True)
     form_model = FormModel(
         self.manager,
         "clinic",
         form_code=FORM_CODE,
         entity_type=["clinic"],
         is_registration_model=True,
         fields=[school_name_field, address_field, unique_id_field])
     form_model.save()
Exemplo n.º 6
0
def _construct_registration_form(manager):
    location_type = get_or_create_data_dict(manager, name='Location Type', slug='location', primitive_type='string')
    geo_code_type = get_or_create_data_dict(manager, name='GeoCode Type', slug='geo_code', primitive_type='geocode')
    description_type = get_or_create_data_dict(manager, name='description Type', slug='description',
                                               primitive_type='string')
    mobile_number_type = get_or_create_data_dict(manager, name='Mobile Number Type', slug='mobile_number',
                                                 primitive_type='string')
    name_type = get_or_create_data_dict(manager, name='Name', slug='name', primitive_type='string')
    entity_id_type = get_or_create_data_dict(manager, name='Entity Id Type', slug='entity_id', primitive_type='string')

    #Create registration questionnaire

    question1 = HierarchyField(name=ENTITY_TYPE_FIELD_NAME, code=ENTITY_TYPE_FIELD_CODE,
                               label="What is associated subject type?",
                               language="eng", ddtype=entity_id_type, instruction="Enter a type for the subject")

    question2 = TextField(name=NAME_FIELD, code=NAME_FIELD_CODE, label="What is the subject's name?",
                          defaultValue="some default value", language="eng", ddtype=name_type, instruction="Enter a subject name")
    question3 = TextField(name=SHORT_CODE_FIELD, code=SHORT_CODE, label="What is the subject's Unique ID Number",
                          defaultValue="some default value", language="eng", ddtype=name_type, instruction="Enter a id, or allow us to generate it",
                          entity_question_flag=True)
    question4 = HierarchyField(name=LOCATION_TYPE_FIELD_NAME, code=LOCATION_TYPE_FIELD_CODE,
                               label="What is the subject's location?",
                               language="eng", ddtype=location_type, instruction="Enter a region, district, or commune")
    question5 = GeoCodeField(name=GEO_CODE_FIELD, code=GEO_CODE, label="What is the subject's GPS co-ordinates?",
                             language="eng", ddtype=geo_code_type, instruction="Enter lat and long. Eg 20.6, 47.3")
    question6 = TextField(name=DESCRIPTION_FIELD, code=DESCRIPTION_FIELD_CODE, label="Describe the subject",
                          defaultValue="some default value", language="eng", ddtype=description_type, instruction="Describe your subject in more details (optional)")
    question7 = TextField(name=MOBILE_NUMBER_FIELD, code=MOBILE_NUMBER_FIELD_CODE,
                          label="What is the mobile number associated with the subject?",
                          defaultValue="some default value", language="eng", ddtype=mobile_number_type, instruction="Enter the subject's number")
    form_model = FormModel(manager, name="reg", form_code=REGISTRATION_FORM_CODE, fields=[
        question1, question2, question3, question4, question5, question6, question7], entity_type=["Registration"])
    return form_model
Exemplo n.º 7
0
def create_default_reporter(manager):
    try:
        entity = get_by_short_code(manager, REPORTER_SHORT_CODE,
                                   REPORTER_ENTITY_TYPE)
        entity.delete()
    except DataObjectNotFound:
        pass
    entity = create_entity(dbm=manager,
                           entity_type=REPORTER_ENTITY_TYPE,
                           short_code=REPORTER_SHORT_CODE,
                           location=DEFAULT_LOCATION)

    mobile_number_type = get_or_create_data_dict(manager,
                                                 name='Mobile Number Type',
                                                 slug='mobile_number',
                                                 primitive_type='string')
    name_type = get_or_create_data_dict(manager,
                                        name='Name',
                                        slug='name',
                                        primitive_type='string')

    data = [(MOBILE_NUMBER_FIELD, TEST_REPORTER_MOBILE_NUMBER,
             mobile_number_type), (NAME_FIELD, 'TEST', name_type)]
    entity.add_data(data=data)
 def _create_default_dd_type(cls):
     cls.entity_type = ["HealthFacility", "Clinic"]
     safe_define_type(cls.manager, ["HealthFacility", "Clinic"])
     cls.default_ddtype = get_or_create_data_dict(
         cls.manager, 'Default String Datadict Type', 'string_default',
         'string')
Exemplo n.º 9
0
def _construct_registration_form(manager):
    location_type = get_or_create_data_dict(manager,
                                            name='Location Type',
                                            slug='location',
                                            primitive_type='string')
    geo_code_type = get_or_create_data_dict(manager,
                                            name='GeoCode Type',
                                            slug='geo_code',
                                            primitive_type='geocode')
    description_type = get_or_create_data_dict(manager,
                                               name='description Type',
                                               slug='description',
                                               primitive_type='string')
    mobile_number_type = get_or_create_data_dict(manager,
                                                 name='Mobile Number Type',
                                                 slug='mobile_number',
                                                 primitive_type='string')
    name_type = get_or_create_data_dict(manager,
                                        name='Name',
                                        slug='name',
                                        primitive_type='string')
    entity_id_type = get_or_create_data_dict(manager,
                                             name='Entity Id Type',
                                             slug='entity_id',
                                             primitive_type='string')

    #Create registration questionnaire

    question1 = HierarchyField(name=ENTITY_TYPE_FIELD_NAME,
                               code=ENTITY_TYPE_FIELD_CODE,
                               label="What is associated subject type?",
                               language="eng",
                               ddtype=entity_id_type,
                               instruction="Enter a type for the subject")

    question2 = TextField(name=NAME_FIELD,
                          code=NAME_FIELD_CODE,
                          label="What is the subject's name?",
                          defaultValue="some default value",
                          language="eng",
                          ddtype=name_type,
                          instruction="Enter a subject name")
    question3 = TextField(name=SHORT_CODE_FIELD,
                          code=SHORT_CODE,
                          label="What is the subject's Unique ID Number",
                          defaultValue="some default value",
                          language="eng",
                          ddtype=name_type,
                          instruction="Enter a id, or allow us to generate it",
                          entity_question_flag=True)
    question4 = HierarchyField(
        name=LOCATION_TYPE_FIELD_NAME,
        code=LOCATION_TYPE_FIELD_CODE,
        label="What is the subject's location?",
        language="eng",
        ddtype=location_type,
        instruction="Enter a region, district, or commune")
    question5 = GeoCodeField(name=GEO_CODE_FIELD,
                             code=GEO_CODE,
                             label="What is the subject's GPS co-ordinates?",
                             language="eng",
                             ddtype=geo_code_type,
                             instruction="Enter lat and long. Eg 20.6, 47.3")
    question6 = TextField(
        name=DESCRIPTION_FIELD,
        code=DESCRIPTION_FIELD_CODE,
        label="Describe the subject",
        defaultValue="some default value",
        language="eng",
        ddtype=description_type,
        instruction="Describe your subject in more details (optional)")
    question7 = TextField(
        name=MOBILE_NUMBER_FIELD,
        code=MOBILE_NUMBER_FIELD_CODE,
        label="What is the mobile number associated with the subject?",
        defaultValue="some default value",
        language="eng",
        ddtype=mobile_number_type,
        instruction="Enter the subject's number")
    form_model = FormModel(manager,
                           name="reg",
                           form_code=REGISTRATION_FORM_CODE,
                           fields=[
                               question1, question2, question3, question4,
                               question5, question6, question7
                           ],
                           entity_type=["Registration"])
    return form_model