我有一個遞歸函數,帶有一個我遇到問題的錯誤。邏輯如下: 表單具有各種類型的字段。一種類型的字段是引用字段,它將表單鏈接到另一個表單。而且,參考文獻可以鏈接。例如:我可以有一個處方表格,裏面有一個參考文獻,對醫生有一個提及人的參考。同樣的相遇表格有一個對病人的引用,也指人。遞歸函數邏輯問題
因此,醫生姓氏的參考字段鏈看起來像處方上的字段49指的是遇到。 Encounter上的Field 7是指Doctor。 Doctor上的第6場是指Person。個人領域1指的是姓氏。 [49-7-6-1]
患者姓氏的引用鏈將遵循相同的邏輯[49-5-4-1]。
我的問題是這樣的。使用當前函數,如果我在較低級別分支引用,則引用鏈字符串會有問題。 [49-5-4-1]代替患者姓氏[49-5-4-1],我得到[49-7-5-4-1]。
功能如下:
function get_reference_fields($form_id, $base_fields = array(), $ref_field_id = null, $ref_string = null, $field_name = null,$base_form = null,$form_name=null) {
if(!$base_form) {
$base_form = $form_id;
}
App::import('model', 'Section');
$zmr_sections = new Section();
$sectionList = $zmr_sections->getSectionList($form_id);
if ($sectionList) {
$new_base_fields = $this->Field->find('list', array('joins' => array(
array(
'table' => 'field_types',
'alias' => 'Type',
'type' => 'left',
'foreignKey' => false,
'conditions' => array('Type.id = Field.field_type_id')
)), 'conditions' => array('Type.base_type != "formatting" AND Type.base_type != "reference" AND Type.base_type != "reverse reference"', 'Field.active=1', 'Field.section_id IN (' . $sectionList . ')')));
if ($ref_field_id) {
$newFields = array();
foreach ($new_base_fields AS $key => $field) {
if ($field_name) {
$field = $form_name . ' - ' . $field;
}
$newFields[$ref_string . '-' . $key] = $field;
}
$new_base_fields = $newFields;
}
if (!$base_fields) {
$base_fields = array();
}
$base_fields = $base_fields + $new_base_fields;
$reference_fields = $this->Field->find('all', array('joins' => array(
array(
'table' => 'field_types',
'alias' => 'Type',
'type' => 'left',
'foreignKey' => false,
'conditions' => array('Type.id = Field.field_type_id')
)), 'conditions' => array('Type.base_type' => 'reference', 'Field.active=1', 'Field.section_id IN (' . $sectionList . ')')));
foreach ($reference_fields AS $reference_field) {
$field_name = $reference_field['Field']['name'];
$query = "SELECT form_id FROM zmr_lists WHERE id=" . $reference_field['Field']['zmr_list_id'];
$list_data = $this->query($query);
$new_form_id = $list_data[0]['zmr_lists']['form_id'];
if($form_id == $base_form){
$ref_string = $reference_field['Field']['id'];
$form_name = $this->Field->Section->Form->field('Form.label',array('Form.id'=>$new_form_id));
}else{
$ref_string .= '-'. $reference_field['Field']['id'];
$form_name .= '-'. $this->Field->Section->Form->field('Form.label',array('Form.id'=>$new_form_id));
}
$base_fields = $this->get_reference_fields($new_form_id, $base_fields, $reference_field['Field']['id'], $ref_string, $field_name,$base_form,$form_name);
}
}
return $base_fields;
}
================================= =
而且,對於數據集的樣本結果是:
[49-7-6-48] => Doctor - Primary Role
[49-7-6-43] => Doctor - State
[49-7-6-11] => Doctor - Password
[49-7-6-2] => Doctor - Last Name
[49-7-6-10] => Doctor - Username
[49-7-6-28] => Doctor - City
[49-7-6-1] => Doctor - First Name
[49-7-6-24] => Doctor - Middle Initial
[49-7-6-27] => Doctor - Address2
[49-7-6-25] => Doctor - Date of Birth
[49-7-6-47] => Doctor - Phone Number
[49-7-6-26] => Doctor - Address1
[49-7-5-68] => PSG Study - Patient ID Number
[49-7-5-67] => PSG Study - Insurance Provider's Name
[49-7-5-74] => PSG Study - PCP referral required?
[49-7-5-73] => PSG Study - Pre-Authorization Obtained?
[49-7-5-22] => PSG Study - Special Needs
[49-7-5-76] => PSG Study - PCP Phone Number
[49-7-5-69] => PSG Study - Group Number
[49-7-5-70] => PSG Study - Relationship to Insured Member
[49-7-5-71] => PSG Study - Referring Doctor
[49-7-5-75] => PSG Study - If Yes, PCP Name:
[49-7-5-72] => PSG Study - Diagnoses:
[49-7-5-4-48] => Patient - Primary Role
[49-7-5-4-43] => Patient - State
[49-7-5-4-11] => Patient - Password
[49-7-5-4-2] => Patient - Last Name
[49-7-5-4-10] => Patient - Username
[49-7-5-4-28] => Patient - City
[49-7-5-4-1] => Patient - First Name
[49-7-5-4-24] => Patient - Middle Initial
[49-7-5-4-27] => Patient - Address2
[49-7-5-4-25] => Patient - Date of Birth
[49-7-5-4-47] => Patient - Phone Number
[49-7-5-4-26] => Patient - Address1
=========================
誰能幫我找出一種算法正常地生成參考鏈?請注意,表單在技術上可能是指自己。例如,醫生可以有另一位醫生的參考(見習生或主管等)
只是爲了確認,你說,最初的「$ zmr_sections-> getSectionList($ form_id);」打電話,而不是主要表格(我想是49)沒有得到第5部分,它應該,還是它回來了,但沒有包含在結果中?儘管這個循環可能效率很低,但在這方面我看不出任何明顯的錯誤。 – 2011-03-09 16:35:49
實際的問題是,當它參考了醫生之後,當它循環通過時,它不會將該ID放到醫生的領域,而是在患者鏈上附加到醫生的領域。患者連鎖店不應該包括7。 – 2011-03-09 16:37:46