Page 1 of 1

Automatically updating tablea

PostPosted: Mon Jan 26, 2009 3:35 am
by milos
Hello,

I suppose this is simple but I can not make it. I have a table (Visits) consisting of the following fields: PatientID, VisitID, Diagnosis, ICD10, and I have a lookup table (DgList) consisting of two fields: Diagnosis (Primary key) and ICD10. What I would like is that after selecting Diagnosis ICD10 field in the Visits table is automatically updated.
Thanks

PostPosted: Mon Jan 26, 2009 12:27 pm
by shannah
I'm not sure I fully understand the question. Can you elaborate a little bit or try to rephrase it?

Automatically updating table

PostPosted: Tue Jan 27, 2009 2:55 am
by milos
Thank you for the prompt answer. In a rush I made an error in explaining. I will try to explain what I need. The DgList table consist of two fields Diagnosis (primary key) and ICD10 code for diagnosis. Some slightly different diagnoses can have the same ICD10 code. Diagnosis table has three fields: VisitID, Diagnosis and ICD10. This table keeps a list of all diagnosis during particular visit for a patient. During each visit the patient can have one or more diagnosis. Physicians usually know the diagnosis, but not ICD10 code. Therefore, physician chooses the diagnosis from the valuelist. So far everything was simple. The diagnosis is added to Diagnosis table. Now, I would like to add ICD10 code for that particular diagnosis from the DgList table to the Diagnosis table, based on the previously chosen diagnosis, and I don’t know how to do it.
Milos

PostPosted: Tue Jan 27, 2009 11:26 am
by shannah
I see. Probably best to use the beforeSave() trigger in the diagnosis table delegate class to set the value of the ICD10 field:

Code: Select all
function beforeSave(&$record){
    if ( $record->valueChanged('Diagnosis') ){
        $icd10Rec = df_get_record('DgList', array('Diagnosis'=>'='.$record->val('Diagnosis')));
        $record->setValue('ICD10', $icd10Rec->val('ICD10'));
   }
}

PostPosted: Sat Jan 31, 2009 2:56 pm
by milos
Thank you. It works perfectly now.