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