Пример #1
0
    def _parse(self):
        if not self.is_multisection:
            for key in self.form_data:
                if key == "timestamp":
                    self.global_timestamp = self.form_data[key]
                elif key.endswith("_timestamp"):
                    self.form_timestamps[key] = self.form_data[key]
                elif key == "custom_consent_data":
                    self.custom_consents = self.form_data[key]
                elif key == "PatientDataAddressSection":
                    self.address_data = self.form_data[key]
                elif is_delimited_key(key):
                    form_model, section_model, cde_model = models_from_mongo_key(
                        self.registry_model, key)
                    value = self.form_data[key]
                    self.parsed_data[(form_model, section_model,
                                      cde_model)] = self._parse_value(value)
        else:
            # multisections extracted from the form like this (ugh):
            # the delimited keys  will(should) always be cdes from the same form and section
            # {u'testmultisection': [
            # {u'DELETE': False, u'testform____testmultisection____DM1FatigueTV': u'DM1FatigueDozingNever',
            #  u'testform____testmultisection____DM1FatigueDrug': u'd1'},
            #
            # {u'DELETE': False, u'testform____testmultisection____DM1FatigueTV': u'DM1FatigueDozingSlightChance', u'testform____testmultisection____DM1FatigueDrug': u'd2'}]}

            multisection_code = self._get_multisection_code()

            self._parse_multisection(multisection_code)
Пример #2
0
    def display_name(self, key):
        if is_delimited_key(key):
            try:
                form_model, section_model, cde_model = models_from_mongo_key(
                    self.registry_model, key)
            except BadKeyError:
                logger.error("key %s refers to non-existant models" % key)
                return key

            human_name = "%s/%s/%s" % (
                form_model.name, section_model.display_name, cde_model.name)
            return human_name
        else:
            return key
Пример #3
0
    def display_value(self, key, mongo_value):
        # return the display value for ranges
        if is_delimited_key(key):
            try:
                form_model, section_model, cde_model = models_from_mongo_key(
                    self.registry_model, key)
            except BadKeyError:
                logger.error("Key %s refers to non-existant models" % key)
                return mongo_value

            if cde_model.pv_group:
                # look up the stored code and return the display value
                range_dict = cde_model.pv_group.as_dict()
                for value_dict in range_dict["values"]:
                    if mongo_value == value_dict["code"]:
                        return value_dict["value"]
        return mongo_value
Пример #4
0
 def _parse_all_forms(self):
     # used in questionnaire approval handling where all form data was being saved in one go
     # generated questionnaire gets fanned out to all forms
     for key in self.form_data:
         if key == "timestamp":
             self.global_timestamp = self.form_data[key]
         elif key.endswith("_timestamp"):
             self.form_timestamps[key] = self.form_data[key]
         elif key == "custom_consent_data":
             pass
         elif key == "PatientDataAddressSection":
             pass
         elif is_multisection(key):
             self._parse_multisection(key)
         elif is_delimited_key(key):
             form_model, section_model, cde_model = models_from_mongo_key(self.registry_model, key)
             value = self.form_data[key]
             self.parsed_data[(form_model, section_model, cde_model)] = self._parse_value(value)
Пример #5
0
    def _parse_multisection(self, multisection_code):
        self._parse_timestamps()
        the_form_model = None
        the_section_model = None
        multisection_item_list = self.form_data[multisection_code]
        if len(multisection_item_list) == 0:
            from rdrf.models.definition.models import Section
            section_model = Section.objects.get(code=multisection_code)
            self.parsed_multisections[(self.form_model, section_model)] = []
            return
        items = []
        for item_dict in multisection_item_list:
            if "DELETE" in item_dict and item_dict["DELETE"]:
                continue

            # rdrf #606
            if not item_dict:
                continue

            item = []

            for key in item_dict:
                if is_delimited_key(key):
                    value = item_dict[key]
                    form_model, section_model, cde_model = models_from_mongo_key(
                        self.registry_model, key)
                    if the_form_model is None:
                        the_form_model = form_model
                    if the_section_model is None:
                        the_section_model = section_model

                    value = self._parse_value(value)

                    cde_dict = {"code": cde_model.code, "value": value}
                    item.append(cde_dict)
            items.append(item)

        if the_form_model is None:
            # rdrf #606
            # this can arise if a multisection is completely blanked out
            # no form model / no data
            return
        self.parsed_multisections[(the_form_model, the_section_model)] = items