Example #1
0
 def get_external_value(self, external_data):
     if self.jsonpath is None:
         raise ConfigurationError(f"{self} is not configured to navigate "
                                  "external data")
     try:
         jsonpath = parse_jsonpath(self.jsonpath)
     except Exception as err:
         raise JsonpathError from err
     matches = jsonpath.find(external_data)
     values = [m.value for m in matches]
     return simplify_list(values)
Example #2
0
 def get_external_value(self, external_data):
     if self.jsonpath is None:
         raise ConfigurationError(f"{self} is not configured to navigate "
                                  "external data")
     try:
         jsonpath = parse_jsonpath(self.jsonpath)
     except Exception as err:
         raise JsonpathError from err
     matches = jsonpath.find(external_data)
     values = [m.value for m in matches]
     if not values:
         return None
     elif len(values) == 1:
         return values[0]
     else:
         return values
Example #3
0
    def set_external_value(self, external_data: dict, info: CaseTriggerInfo):
        """
        Builds ``external_data`` by reference.

        Currently implemented for dicts using JSONPath but could be
        implemented for other types as long as they are mutable.
        """
        if self.jsonpath is None:
            raise ConfigurationError(f"{self} is not configured to navigate "
                                     "external data")
        value = self.get_value(info)
        if value is None:
            # Don't set external value if CommCare has no value
            return
        try:
            jsonpath = parse_jsonpath(self.jsonpath)
        except Exception as err:
            raise JsonpathError from err
        jsonpath.update_or_create(external_data, value)