(name, case_type, domain=None, data_type=None,
                       description=None, group=None, deprecated=None,
                       fhir_resource_prop_path=None, fhir_resource_type=None, remove_path=False,
                       allowed_values=None)
Takes a case property to update and returns an error if there was one
Takes a case property to update and returns an error if there was one
Takes a case property to update and returns an error if there was one
def save_case_property(name, case_type, domain=None, data_type=None,
                       description=None, group=None, deprecated=None,
                       fhir_resource_prop_path=None, fhir_resource_type=None, remove_path=False,
                       allowed_values=None):
    """
    Takes a case property to update and returns an error if there was one
    """
    if not name:
        return ugettext('Case property must have a name')

    prop = CaseProperty.get_or_create(
        name=name, case_type=case_type, domain=domain
    )
    if data_type:
        prop.data_type = data_type
    if description is not None:
        prop.description = description
    if group:
        prop.group = group
    if deprecated is not None:
        prop.deprecated = deprecated
    try:
        prop.full_clean()
    except ValidationError as e:
        return str(e)

    if fhir_resource_type and fhir_resource_prop_path:
        update_fhir_resource_property(prop, fhir_resource_type, fhir_resource_prop_path, remove_path)
    prop.save()

    # If caller has supplied non-None value for allowed_values, then
    # synchronize the supplied dict (key=allowed_value, value=description)
    # with the database stored values for this property.
    err_cnt = 0
    max_len = CasePropertyAllowedValue._meta.get_field('allowed_value').max_length
    if allowed_values is not None:
        obj_pks = []
        for allowed_value, av_desc in allowed_values.items():
            if len(allowed_value) > max_len:
                err_cnt += 1
            else:
                av_obj, _ = CasePropertyAllowedValue.objects.update_or_create(
                    case_property=prop, allowed_value=allowed_value, defaults={"description": av_desc})
                obj_pks.append(av_obj.pk)
        # Delete any database-resident allowed values that were not found in
        # the set supplied by caller.
        prop.allowed_values.exclude(pk__in=obj_pks).delete()

    if err_cnt:
        return ugettext('Unable to save valid values longer than {} characters').format(max_len)
def save_case_property ( name , case_type , domain = None , data_type = None , description = None , group = None , deprecated = None , fhir_resource_prop_path = None , fhir_resource_type = None , remove_path = False , allowed_values = None ) : if not name : return ugettext ( 'Case property must have a name' ) prop = CaseProperty . get_or_create ( name = name , case_type = case_type , domain = domain ) if data_type : prop . data_type = data_type if description is not None : prop . description = description if group : prop . group = group if deprecated is not None : prop . deprecated = deprecated try : prop . full_clean ( ) except ValidationError as e : return str ( e ) if fhir_resource_type and fhir_resource_prop_path : update_fhir_resource_property ( prop , fhir_resource_type , fhir_resource_prop_path , remove_path ) prop . save ( ) # If caller has supplied non-None value for allowed_values, then # synchronize the supplied dict (key=allowed_value, value=description) # with the database stored values for this property. err_cnt = 0 max_len = CasePropertyAllowedValue . _meta . get_field ( 'allowed_value' ) . max_length if allowed_values is not None : obj_pks = [ ] for allowed_value , av_desc in allowed_values . items ( ) : if len ( allowed_value ) > max_len : err_cnt += 1 else : av_obj , _ = CasePropertyAllowedValue . objects . update_or_create ( case_property = prop , allowed_value = allowed_value , defaults = { "description" : av_desc } ) obj_pks . append ( av_obj . pk ) # Delete any database-resident allowed values that were not found in # the set supplied by caller. prop . allowed_values . exclude ( pk__in = obj_pks ) . delete ( ) if err_cnt : return ugettext ( 'Unable to save valid values longer than {} characters' ) . format ( max_len )