db.define_table('patient',
    ...,
    format='%(first_name)s %(last_name)s')

"format" can also be a function that takes a row object and generates the 
desired output.

The "format" attribute is used to create a default "represent" attribute 
for any reference fields that reference this table.

Anthony

On Wednesday, June 26, 2013 10:24:32 AM UTC-4, Tom Russell wrote:
>
> db.define_table('patient',
>     #db.patient.id.readable=False # Since we do not want to expose the id 
> field on the grid
>     Field('alternatepid', label='Alternate PID', writable=False, 
> readable=False),
>     Field('first_name', label='First Name', requires=IS_NOT_EMPTY()),
>     Field('middle_name', label='Middle Name'),
>     Field('last_name', label='Last Name', requires=IS_NOT_EMPTY()),
>     Field('suffix', label='Suffix', requires=IS_IN_SET(['I', 'II', 'III', 
> 'IV', 'V', 'Jr', 'Sr'])),
>     Field('date_of_birth', 'date', label='Date of Birth', 
> required=IS_DATE(), requires=IS_NOT_EMPTY()),
>     Field('gender', label='Gender', requires=IS_IN_SET(['Male', 'Female', 
> 'Other'])),
>     Field('full_name',  label='Full Name', writable=False, readable=False),
>     Field('address1', label='Address1', requires=IS_NOT_EMPTY()),
>     Field('address2', label='Address2'),
>     Field('city',  label='City', requires=IS_NOT_EMPTY()),
>     Field('state',  label='State', requires=IS_NOT_EMPTY()),
>     Field('zipcode',  label='Zip Code', requires=IS_NOT_EMPTY()),
>     Field('addresstype',  label='AddressType'),
>     Field('county',  label='County', ),
>     Field('country',  label='Country', requires=IS_IN_SET(COUNTRIES)),
>     Field('phone',  label='Phone', ),
>     Field('mobile_phone',  label='Mobile Phone'),
>     Field('emailaddress',  label='Email Address', requires = 
> IS_EMAIL(error_message='invalid email!')),
>     Field('ethnicity',  label='Ethnicity', 
> requires=IS_IN_SET(['Caucasian', 'Hispanic', 'Chinese'])),
>     Field('age', label='Age'),
>     Field('marital_status',  label='Marital Status', 
> requires=IS_IN_SET(['Single', 'Married', 'Divorced', 'Separated', 
> 'Widowed'])),
>     Field('comment', 'text', label='Comment'),
>     Field('government_id_number',  label='Government ID Number', 
> requires=IS_NOT_EMPTY()),
>     Field('is_newborn', 'boolean',  label='Is Newborn', ),
>     Field('medical_record_number',  label='MRN', readable=True, 
> requires=IS_NOT_EMPTY()),
>     Field('other_id_type',  label='Other ID Type', 
> requires=IS_IN_SET(['Work', 'Library Card', 'Drivers License', 'School ID', 
> 'Other'])),
>     Field('other_id', label='Other ID'),
>     )
>
>
> db.define_table(
>     'dependents',
>     #Field('patient name', db.linked patient, represent=lambda c, 
> row:first_name of patient(c), requires=IS_IN_DB(db,'field.id
> ','%(patient)s')),
>     Field('patient','reference patient', writable=False, readable=False),
>     Field('dep_firstname', label='First Name'),
>     Field('dep_middlename', label='Middle Name'),
>     Field('dep_lastname', label='Last Name'),
>     Field('dep_relationship', label='Relationship', 
> requires=IS_IN_SET(['Son', 'Daughter', 'Other'])),
>     )
>
> db.define_table(
>     'emergencycontacts',
>     Field('patient','reference patient', writable=False, readable=False),
>     Field('em_first_name', label='First Name'),
>     Field('em_middle_name', label='Middle Name'),
>     Field('em_last_name', label='Last Name'),
>     Field('em_address1', label='Address1'),
>     Field('em_address2', label='Address2'),
>     Field('em_city', label='City'),
>     Field('em_state', label='State'),
>     Field('em_zipcode', label='Zip Code'),
>     Field('em_country', label='Country', requires=IS_IN_SET(COUNTRIES)),
>     Field('em_phone', label='Phone'),
>     Field('em_relationship', label='Relationship', 
> requires=IS_IN_SET(['Aunt', 'Uncle', 'Parent', 'Sibling', 'Spouse', 
> 'Guardian'])),
>     )
>
> I'd like to reference the first and last name of the patient the record is 
> associated with.
>
> Thanks.
>
>
> On Wed, Jun 26, 2013 at 10:20 AM, Anthony <[email protected] <javascript:>
> > wrote:
>
>> Can you show your three table definitions? The simplest method is just to 
>> specify a "format" attribute for db.patient, which will be used by any 
>> referencing fields.
>>
>> Anthony
>>
>>
>> On Wednesday, June 26, 2013 1:06:03 AM UTC-4, Tom Russell wrote:
>>>
>>> Another question on the smartgrid.
>>>
>>> I have linked tables in my smartgrid like:
>>>
>>> grid = SQLFORM.smartgrid(db.patient, deletable=True, editable=True, 
>>> create=False, maxtextlength=64, paginate=25, links=links,
>>>     links_in_grid=True, linked_tables=['**emergencycontacts','**
>>> dependents'])
>>>
>>> When clicking on the linked table it shows the id of patient since thats 
>>> what reference but how can I show the name of the patient rather than the 
>>> id of patient?
>>>
>>> Thanks,
>>>
>>> Tom
>>>
>>  -- 
>>  
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to