Example #1
0
def _get_or_create_data_dict(dbm, name, slug, primitive_type, description=None):
    try:
        ddtype = get_datadict_type_by_slug(dbm, slug)
    except DataObjectNotFound:
        ddtype = create_datadict_type(dbm=dbm, name=name, slug=slug,
            primitive_type=primitive_type, description=description)
    return ddtype
Example #2
0
def create_data_dict(dbm, name, slug, primitive_type, description=None):
    try:
        existing = get_datadict_type_by_slug(dbm, slug)
        existing.delete()
    except DataObjectNotFound:
        pass
    return create_datadict_type(dbm, name, slug, primitive_type, description)
def create_data_dict(dbm, name, slug, primitive_type, description=None):
    try:
        existing = get_datadict_type_by_slug(dbm, slug)
        existing.delete()
    except DataObjectNotFound:
        pass
    return create_datadict_type(dbm, name, slug, primitive_type, description)
Example #4
0
def get_or_create_data_dict(dbm, name, slug, primitive_type, description=None):
    try:
        #  Check if is existing
        ddtype = get_datadict_type_by_slug(dbm, slug)
    except DataObjectNotFound:
        #  Create new one
        ddtype = create_datadict_type(dbm=dbm, name=name, slug=slug,
            primitive_type=primitive_type, description=description)
    return ddtype
Example #5
0
    def test_should_create_load_edit_datadict(self):
        FIRST_NAME_SLUG = 'first_name'

        name_type = create_datadict_type(self.dbm, name='First name', slug=FIRST_NAME_SLUG, primitive_type='string')

        saved_type = get_datadict_type(self.dbm, name_type.id)
        self.assertEqual(name_type.id, saved_type.id)
        self.assertEqual(name_type.slug, saved_type.slug)

        ddtype = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)

        self.assertEqual(name_type.id, ddtype.id)
        self.assertEqual(name_type.slug, ddtype.slug)

        ddtype.description = "new desc"
        ddtype.save()

        saved = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)
        self.assertEqual("new desc", saved.description)
    def test_should_return_ddtype_by_slug(self):
        expected = DataDictType(self.dbm, "name", "slug", primitive_type="string")
        db_row = Mock()
        db_row.doc = expected._doc._data
        self.dbm.load_all_rows_in_view.return_value = [db_row]

        actual = get_datadict_type_by_slug(self.dbm, "slug")

        self.assertIsInstance(actual, DataDictType)
        self.assertEqual(expected.id, actual.id)
Example #7
0
def _add_location_field_if_absent(datasender, dbm, logger):
    if "location" not in datasender.data and '_geo' in datasender.aggregation_paths.keys(
    ):
        logger.info('Adding location field to datasender %s' %
                    datasender.short_code)
        data = ("location", datasender.aggregation_paths["_geo"],
                get_datadict_type_by_slug(dbm, slug='location'))
        datasender.update_latest_data([data])
    else:
        logger.info('Location field already present for datasender %s' %
                    datasender.short_code)
Example #8
0
    def test_should_create_load_edit_datadict(self):
        FIRST_NAME_SLUG = 'first_name'

        name_type = create_datadict_type(self.dbm,
                                         name='First name',
                                         slug=FIRST_NAME_SLUG,
                                         primitive_type='string')

        saved_type = get_datadict_type(self.dbm, name_type.id)
        self.assertEqual(name_type.id, saved_type.id)
        self.assertEqual(name_type.slug, saved_type.slug)

        ddtype = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)

        self.assertEqual(name_type.id, ddtype.id)
        self.assertEqual(name_type.slug, ddtype.slug)

        ddtype.description = "new desc"
        ddtype.save()

        saved = get_datadict_type_by_slug(self.dbm, slug=FIRST_NAME_SLUG)
        self.assertEqual("new desc", saved.description)
def create_clinic_projects(CLINIC_ENTITY_TYPE, manager):
    name_type = create_data_dict(manager,
                                 name='Name',
                                 slug='Name',
                                 primitive_type='string')
    # Entity id is a default type in the system.
    entity_id_type = get_datadict_type_by_slug(manager, slug='entity_id')
    age_type = create_data_dict(manager,
                                name='Age Type',
                                slug='age',
                                primitive_type='integer')
    date_type = create_data_dict(manager,
                                 name='Report Date',
                                 slug='date',
                                 primitive_type='date')
    select_type = create_data_dict(manager,
                                   name='Choice Type',
                                   slug='choice',
                                   primitive_type='select')
    geo_code_type = create_data_dict(manager,
                                     name='GeoCode Type',
                                     slug='geo_code',
                                     primitive_type='geocode')
    question1 = TextField(label="entity_question",
                          code="EID",
                          name="What is associated entity?",
                          language="eng",
                          entity_question_flag=True,
                          ddtype=entity_id_type,
                          length=TextConstraint(min=1, max=12))
    question2 = TextField(label="Name",
                          code="NA",
                          name="What is your name?",
                          length=TextConstraint(min=1, max=10),
                          defaultValue="some default value",
                          language="eng",
                          ddtype=name_type)
    question3 = IntegerField(label="Father age",
                             code="FA",
                             name="What is age of father?",
                             range=NumericConstraint(min=18, max=100),
                             ddtype=age_type)
    question4 = DateField(label="Report date",
                          code="RD",
                          name="What is reporting date?",
                          date_format="dd.mm.yyyy",
                          ddtype=date_type)
    question5 = SelectField(label="Blood Group",
                            code="BG",
                            name="What is your blood group?",
                            options=[("O+", "a"), ("O-", "b"), ("AB", "c"),
                                     ("B+", "d")],
                            single_select_flag=True,
                            ddtype=select_type)
    question6 = SelectField(label="Symptoms",
                            code="SY",
                            name="What are symptoms?",
                            options=[("Rapid weight loss", "a"),
                                     ("Dry cough", "b"), ("Pneumonia", "c"),
                                     ("Memory loss", "d"),
                                     ("Neurological disorders ", "e")],
                            single_select_flag=False,
                            ddtype=select_type)
    question7 = GeoCodeField(name="What is the GPS code for clinic",
                             code="GPS",
                             label="What is the GPS code for clinic?",
                             language="eng",
                             ddtype=geo_code_type)
    form_model = FormModel(manager,
                           name="AIDS",
                           label="Aids form_model",
                           form_code="cli001",
                           type='survey',
                           fields=[
                               question1, question2, question3, question4,
                               question5, question6, question7
                           ],
                           entity_type=CLINIC_ENTITY_TYPE)
    try:
        qid = form_model.save()
    except DataObjectAlreadyExists as e:
        get_form_model_by_code(manager, "cli001").delete()
        qid = form_model.save()
    project = Project(name="Clinic Test Project",
                      goals="This project is for automation",
                      project_type="survey",
                      entity_type=CLINIC_ENTITY_TYPE[-1],
                      devices=["sms"],
                      activity_report='no',
                      sender_group="close")
    project.qid = qid
    project.state = ProjectState.ACTIVE
    try:
        project.save(manager)
    except Exception:
        pass
    form_model2 = FormModel(manager,
                            name="AIDS",
                            label="Aids form_model",
                            form_code="cli002",
                            type='survey',
                            fields=[
                                question1, question2, question3, question4,
                                question5, question6, question7
                            ],
                            entity_type=CLINIC_ENTITY_TYPE)
    try:
        qid2 = form_model2.save()
    except DataObjectAlreadyExists as e:
        get_form_model_by_code(manager, "cli002").delete()
        qid2 = form_model2.save()
    project2 = Project(name="Clinic2 Test Project",
                       goals="This project is for automation",
                       project_type="survey",
                       entity_type=CLINIC_ENTITY_TYPE[-1],
                       devices=["sms"],
                       activity_report='no',
                       sender_group="close")
    project2.qid = qid2
    project2.state = ProjectState.ACTIVE
    try:
        project2.save(manager)
    except Exception:
        pass
def create_clinic_projects(CLINIC_ENTITY_TYPE, manager):
    name_type = create_data_dict(manager, name='Name', slug='Name', primitive_type='string')
    # Entity id is a default type in the system.
    entity_id_type = get_datadict_type_by_slug(manager, slug='entity_id')
    age_type = create_data_dict(manager, name='Age Type', slug='age', primitive_type='integer')
    date_type = create_data_dict(manager, name='Report Date', slug='date', primitive_type='date')
    select_type = create_data_dict(manager, name='Choice Type', slug='choice', primitive_type='select')
    geo_code_type = create_data_dict(manager, name='GeoCode Type', slug='geo_code', primitive_type='geocode')
    question1 = TextField(label="entity_question", code="EID", name="What is associated entity?",
                          language="eng", entity_question_flag=True, ddtype=entity_id_type,
                          length=TextConstraint(min=1, max=12))
    question2 = TextField(label="Name", code="NA", name="What is your name?",
                          length=TextConstraint(min=1, max=10),
                          defaultValue="some default value", language="eng", ddtype=name_type)
    question3 = IntegerField(label="Father age", code="FA", name="What is age of father?",
                             range=NumericConstraint(min=18, max=100), ddtype=age_type)
    question4 = DateField(label="Report date", code="RD", name="What is reporting date?",
                          date_format="dd.mm.yyyy", ddtype=date_type)
    question5 = SelectField(label="Blood Group", code="BG", name="What is your blood group?",
                            options=[("O+", "a"), ("O-", "b"), ("AB", "c"), ("B+", "d")], single_select_flag=True,
                            ddtype=select_type)
    question6 = SelectField(label="Symptoms", code="SY", name="What are symptoms?",
                            options=[("Rapid weight loss", "a"), ("Dry cough", "b"), ("Pneumonia", "c"),
                                     ("Memory loss", "d"), ("Neurological disorders ", "e")], single_select_flag=False,
                            ddtype=select_type)
    question7 = GeoCodeField(name="What is the GPS code for clinic", code="GPS", label="What is the GPS code for clinic?",
                             language="eng", ddtype=geo_code_type)
    form_model = FormModel(manager, name="AIDS", label="Aids form_model",
                           form_code="cli001", type='survey',
                           fields=[question1, question2, question3, question4, question5, question6, question7],
                           entity_type=CLINIC_ENTITY_TYPE
    )
    try:
        qid = form_model.save()
    except DataObjectAlreadyExists as e:
        get_form_model_by_code(manager, "cli001").delete()
        qid = form_model.save()
    project = Project(name="Clinic Test Project", goals="This project is for automation", project_type="survey",
                      entity_type=CLINIC_ENTITY_TYPE[-1], devices=["sms"], activity_report='no',sender_group="close")
    project.qid = qid
    project.state = ProjectState.ACTIVE
    try:
        project.save(manager)
    except Exception:
        pass
    form_model2 = FormModel(manager, name="AIDS", label="Aids form_model",
                            form_code="cli002", type='survey',
                            fields=[question1, question2, question3, question4, question5, question6, question7],
                            entity_type=CLINIC_ENTITY_TYPE)
    try:
        qid2 = form_model2.save()
    except DataObjectAlreadyExists as e:
        get_form_model_by_code(manager, "cli002").delete()
        qid2 = form_model2.save()
    project2 = Project(name="Clinic2 Test Project", goals="This project is for automation", project_type="survey",
                       entity_type=CLINIC_ENTITY_TYPE[-1], devices=["sms"], activity_report='no', sender_group="close")
    project2.qid = qid2
    project2.state = ProjectState.ACTIVE
    try:
        project2.save(manager)
    except Exception:
        pass