Пример #1
0
def _get_episode_case_properties(episode_case_properties, occurence_case, person_case, use_new_2b_structure):
    """
    :return: Example : {'dateofInitiation': '2016-12-01', 'pregdate': '2016-12-01', 'dotdesignation': u'tbhv_to',
    'ptbyr': '2016', 'dotpType': '7', 'dotmob': u'1234567890', 'dotname': u'asdfasdf', 'Ptype': '1',
    'poccupation': 1, 'disease_classification': 'P', 'sitedetail: 1}
    """
    episode_properties = {}

    if use_new_2b_structure:
        occurence_case_properties = occurence_case.dynamic_case_properties()
        episode_site_choice = occurence_case_properties.get('site_choice')
        patient_occupation = person_case.dynamic_case_properties().get('occupation', 'other')
        episode_disease_classification = occurence_case_properties.get('disease_classification', '')
    else:
        episode_site_choice = episode_case_properties.get('site_choice')
        patient_occupation = episode_case_properties.get('occupation', 'other')
        episode_disease_classification = episode_case_properties.get('disease_classification', '')

    if episode_site_choice:
        site_detail = episode_site.get(episode_site_choice, 'others')
        episode_properties["sitedetail"] = site_detail

    episode_case_date = episode_case_properties.get('date_of_diagnosis', None)
    if episode_case_date:
        episode_date = datetime.datetime.strptime(episode_case_date, "%Y-%m-%d").date()
    else:
        episode_date = datetime.date.today()

    episode_year = episode_date.year

    episode_properties.update({
        "poccupation": occupation.get(
            patient_occupation,
            occupation['other']
        ),
        "pregdate": str(episode_date),
        "ptbyr": str(episode_year),
        "disease_classification": disease_classification.get(
            episode_disease_classification,
            ''
        ),
        "dcpulmunory": dcpulmonory.get(episode_disease_classification, "N"),
        "dcexpulmunory": dcexpulmonory.get(episode_disease_classification, "N"),
        "dotname": (' '.join(
            [episode_case_properties.get(TREATMENT_SUPPORTER_FIRST_NAME, ''),
             episode_case_properties.get(TREATMENT_SUPPORTER_LAST_NAME, '')])
        ),
        "dotmob": episode_case_properties.get(TREATMENT_SUPPORTER_PHONE, ''),
        # Can this mandatory field be made N/A if in case we don't collect this as in spec
        "dotdesignation": episode_case_properties.get('treatment_supporter_designation', ''),
        "dotpType": treatment_support_designation.get(
            episode_case_properties.get('treatment_supporter_designation', 'other_community_volunteer'),
            treatment_support_designation['other_community_volunteer']
        ),
        "dateofInitiation": episode_case_properties.get(TREATMENT_START_DATE, str(datetime.date.today())),
        "Ptype": patient_type_choice.get(episode_case_properties.get('patient_type_choice', ''), ''),
    })

    return episode_properties
Пример #2
0
    def get_payload(self, repeat_record, episode_case):
        person_case = self._get_person_case(episode_case)
        episode_case_properties = episode_case.dynamic_case_properties()
        person_case_properties = person_case.dynamic_case_properties()

        person_locations = self._get_person_locations(episode_case)
        episode_case_date = episode_case_properties.get('date_of_diagnosis', None)
        if episode_case_date:
            episode_date = datetime.datetime.strptime(episode_case_date, "%Y-%m-%d").date()
        else:
            episode_date = datetime.date.today()
        return {
            "Stocode": person_locations.sto,
            "Dtocode": person_locations.dto,
            "TBUcode": person_locations.tu,
            "HFIDNO": person_locations.pcp,
            "pname": sanitize_text_for_xml(person_case.name),
            "fhname": self._get_husband_father_name(person_case_properties),
            "age": (_get_person_age(person_case_properties) or '0'),
            "gender": person_case_properties.get('sex', '').capitalize(),
            "Address": self._get_address(person_case_properties),
            "pin": (person_case_properties.get('current_address_postal_code') or DUMMY_VALUES['pincode']),
            "lno": person_case_properties.get('phone_number', ''),
            "mno": '0',
            "tbdiagdate": _format_date(str(episode_date)),
            "tbstdate": _format_date(
                episode_case_properties.get(TREATMENT_START_DATE, str(datetime.date.today()))),
            "Type": (disease_classification.get(episode_case_properties.get('disease_classification'))
                     or NOT_AVAILABLE_VALUE),
            "B_diagnosis": basis_of_diagnosis.get(episode_case_properties.get('basis_of_diagnosis'), ''),
            "D_SUSTest": (drug_susceptibility_test_status.get(episode_case_properties.get('dst_status'))
                          or NOT_AVAILABLE_VALUE),
            "Treat_I": (episode_case_properties.get('treatment_initiation_status') or NOT_AVAILABLE_VALUE),
            "usersid": settings.ENIKSHAY_PRIVATE_API_USERS.get(person_locations.sto, ''),
            "password": settings.ENIKSHAY_PRIVATE_API_PASSWORD,
            "Source": ENIKSHAY_ID,
        }
def _get_episode_case_properties(episode_case_properties):
    """
    :return: Example : {'dateofInitiation': '2016-12-01', 'pregdate': '2016-12-01', 'dotdesignation': u'tbhv_to',
    'ptbyr': '2016', 'dotpType': '7', 'dotmob': u'1234567890', 'dotname': u'asdfasdf', 'Ptype': '1',
    'poccupation': 1, 'disease_classification': 'P', 'sitedetail: 1}
    """
    episode_properties = {}

    episode_site_choice = episode_case_properties.get('site_choice', None)
    if episode_site_choice:
        site_detail = episode_site.get(episode_site_choice, 'others')
        episode_properties["sitedetail"] = site_detail

    episode_case_date = episode_case_properties.get('date_of_diagnosis', None)
    if episode_case_date:
        episode_date = datetime.datetime.strptime(episode_case_date,
                                                  "%Y-%m-%d").date()
    else:
        episode_date = datetime.date.today()

    episode_year = episode_date.year
    episode_properties.update({
        "poccupation":
        occupation.get(episode_case_properties.get('occupation', 'other'),
                       occupation['other']),
        "pregdate":
        str(episode_date),
        "ptbyr":
        str(episode_year),
        "disease_classification":
        disease_classification.get(
            episode_case_properties.get('disease_classification', ''), ''),
        "dcpulmunory":
        dcpulmonory.get(
            episode_case_properties.get('disease_classification', ''), "N"),
        "dcexpulmunory":
        dcexpulmonory.get(
            episode_case_properties.get('disease_classification', ''), "N"),
        "dotname": (' '.join([
            episode_case_properties.get('treatment_supporter_first_name', ''),
            episode_case_properties.get('treatment_supporter_last_name', '')
        ])),
        "dotmob":
        episode_case_properties.get('treatment_supporter_mobile_number', ''),
        # Can this mandatory field be made N/A if in case we don't collect this as in spec
        "dotdesignation":
        episode_case_properties.get('treatment_supporter_designation', ''),
        "dotpType":
        treatment_support_designation.get(
            episode_case_properties.get('treatment_supporter_designation',
                                        'other_community_volunteer'),
            treatment_support_designation['other_community_volunteer']),
        "dateofInitiation":
        episode_case_properties.get('treatment_initiation_date',
                                    str(datetime.date.today())),
        "Ptype":
        patient_type_choice.get(
            episode_case_properties.get('patient_type_choice', ''), ''),
    })

    return episode_properties