Esempio n. 1
0
    def save_data_value(self, data_value):
        data_element = DataElement.objects.get(identifier=data_value['dataElement'])
        category_option = CategoryOptionCombo.objects.get(identifier=data_value['categoryOptionCombo'])
        facility = Facility.objects.get(identifier=data_value['orgUnit'])
        district = facility.sub_county.district
        region = district.region

        try:
            dv = DataValue()
            dv.data_set = self.data_set
            dv.facility = facility
            dv.district = district
            dv.region = region
            dv.data_element = data_element
            dv.category_option_combo = category_option
            dv.age_group = dv.category_option_combo.age_group
            dv.period = int(self.period)
            dv.original_period = data_value['period']
            dv.value = data_value['value']
            dv.save()
        except IntegrityError, e:
            dv = DataValue.objects.get(facility=facility, data_element=data_element,
                                       category_option_combo=category_option, period=self.period)
            dv.value = data_value['value']
            dv.save()