Skip to content

Commit

Permalink
field exclusions for serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Travers Franckle committed May 24, 2012
1 parent 6938051 commit b76be9e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions indivo/models/demographics.py
Expand Up @@ -15,6 +15,29 @@
from indivo.lib.rdf import PatientGraph
from indivo.serializers.json import IndivoJSONEncoder

FIELDS = ('bday',
'email',
'ethnicity',
'gender',
'preferred_language',
'race',
'name_given',
'name_suffix',
'name_family',
'name_prefix',
'tel_2_type',
'tel_2_preferred_p',
'tel_2_number',
'adr_region',
'adr_country',
'adr_postalcode',
'adr_city',
'adr_street',
'tel_1_type',
'tel_1_preferred_p',
'tel_1_number'
)

class Demographics(BaseModel):
""" SMART style demographics """
__metaclass__ = DataModelBase
Expand Down Expand Up @@ -93,12 +116,12 @@ def uri(self):

def as_json(self):
"""JSON string representation of Demographics instance"""
data = serializers.serialize("indivo_python", [self])
data = serializers.serialize("indivo_python", [self], fields=FIELDS)
return simplejson.dumps(data, cls=IndivoJSONEncoder)

def as_xml(self):
"""XML string representation of Demographics instance"""
root = serializers.serialize("indivo_xml", [self])
root = serializers.serialize("indivo_xml", [self], fields=FIELDS)
return etree.tostring(root)

def as_rdf(self):
Expand Down

0 comments on commit b76be9e

Please sign in to comment.