

def as_json(self):
    ' Serializes to JSON by inspecting `elementProperties()` and creating\n        a JSON dictionary of all registered properties.\n        '
    js = {
        
    }
    found = set()
    nonoptionals = set()
    for (name, jsname, typ, is_list, of_many, not_optional) in self.elementProperties():
        if not_optional:
            nonoptionals.add((of_many or jsname))
        val = getattr(self, name)
        if (val is None):
            continue
        if is_list:
            if (len(val) > 0):
                found.add((of_many or jsname))
            js[jsname] = [(v.as_json() if hasattr(v, 'as_json') else v) for v in val]
        else:
            found.add((of_many or jsname))
            js[jsname] = (val.as_json() if hasattr(val, 'as_json') else val)
    if (len((nonoptionals - found)) > 0):
        for nonop in (nonoptionals - found):
            logging.warning("Element '{}' is not optional, you should provide a value for it on {}".format(nonop, self))
    return js

dataset/ETHPy150Open smart-on-fhir/client-py/fhirclient/models/fhirabstractbase.py FHIRAbstractBase.as_json/original