PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/api/ui/widget/participant_view.class.php

https://github.com/patrickdemond/beartooth
PHP | 247 lines | 161 code | 25 blank | 61 comment | 16 complexity | 8ef491a001186b1d77b06f232a04388c MD5 | raw file
  1. <?php
  2. /**
  3. * participant_view.class.php
  4. *
  5. * @author Patrick Emond <emondpd@mcmaster.ca>
  6. * @filesource
  7. */
  8. namespace beartooth\ui\widget;
  9. use cenozo\lib, cenozo\log, beartooth\util;
  10. /**
  11. * widget participant view
  12. */
  13. class participant_view extends \cenozo\ui\widget\participant_view
  14. {
  15. /**
  16. * Processes arguments, preparing them for the operation.
  17. *
  18. * @author Patrick Emond <emondpd@mcmaster.ca>
  19. * @throws exception\notice
  20. * @access protected
  21. */
  22. protected function prepare()
  23. {
  24. parent::prepare();
  25. $this->add_item( 'quota_state', 'constant', 'Quota State' );
  26. $this->add_item( 'qnaire_name', 'constant', 'Current Questionnaire' );
  27. $this->add_item( 'qnaire_date', 'constant', 'Delay Questionnaire Until' );
  28. $this->add_item( 'data_collection_draw_blood', 'boolean', 'Consent To Draw Blood' );
  29. $this->add_item( 'data_collection_draw_blood_continue', 'boolean', 'Draw Blood (Continue)' );
  30. $this->add_item( 'data_collection_physical_tests_continue', 'boolean', 'Physical Tests (Continue)' );
  31. $this->add_item( 'next_of_kin_first_name', 'string', 'Next of Kin First Name' );
  32. $this->add_item( 'next_of_kin_last_name', 'string', 'Next of Kin Last Name' );
  33. $this->add_item( 'next_of_kin_gender', 'string', 'Next of Kin Gender' );
  34. $this->add_item( 'next_of_kin_phone', 'string', 'Next of Kin Phone' );
  35. $this->add_item( 'next_of_kin_street', 'string', 'Next of Kin Street' );
  36. $this->add_item( 'next_of_kin_city', 'string', 'Next of Kin City' );
  37. $this->add_item( 'next_of_kin_province', 'string', 'Next of Kin Province' );
  38. $this->add_item( 'next_of_kin_postal_code', 'string', 'Next of Kin Postal Code' );
  39. // create the appointment sub-list widget
  40. $this->appointment_list = lib::create( 'ui\widget\appointment_list', $this->arguments );
  41. $this->appointment_list->set_parent( $this );
  42. $this->appointment_list->set_heading( 'Appointments' );
  43. // create the callback sub-list widget
  44. $this->callback_list = lib::create( 'ui\widget\callback_list', $this->arguments );
  45. $this->callback_list->set_parent( $this );
  46. $this->callback_list->set_heading( 'Scheduled Callbacks' );
  47. // create the interview sub-list widget
  48. $this->interview_list = lib::create( 'ui\widget\interview_list', $this->arguments );
  49. $this->interview_list->set_parent( $this );
  50. $this->interview_list->set_heading( 'Interview history' );
  51. }
  52. /**
  53. * Sets up the operation with any pre-execution instructions that may be necessary.
  54. *
  55. * @author Patrick Emond <emondpd@mcmaster.ca>
  56. * @access protected
  57. */
  58. protected function setup()
  59. {
  60. parent::setup();
  61. $operation_class_name = lib::get_class_name( 'database\operation' );
  62. $record = $this->get_record();
  63. $db_next_of_kin = $record->get_next_of_kin();
  64. $db_data_collection = $record->get_data_collection();
  65. $db_effective_qnaire = $record->get_effective_qnaire();
  66. if( is_null( $db_effective_qnaire ) )
  67. {
  68. $qnaire_name = '(none)';
  69. $qnaire_date = '(not applicable)';
  70. }
  71. else
  72. {
  73. $qnaire_name = $db_effective_qnaire->name;
  74. $start_qnaire_date = $record->get_start_qnaire_date();
  75. $qnaire_date = is_null( $start_qnaire_date )
  76. ? 'immediately'
  77. : util::get_formatted_date( $start_qnaire_date );
  78. }
  79. // set the view's items
  80. $db_quota = $record->get_quota();
  81. $this->set_item( 'quota_state',
  82. is_null( $db_quota ) ? '(no quota)' :
  83. ( $db_quota->state_disabled ? 'Disabled' : 'Enabled' ) );
  84. $this->set_item( 'qnaire_name', $qnaire_name );
  85. $this->set_item( 'qnaire_date', $qnaire_date );
  86. $this->set_item(
  87. 'data_collection_draw_blood',
  88. is_null( $db_data_collection ) ? NULL : $db_data_collection->draw_blood );
  89. $this->set_item(
  90. 'data_collection_draw_blood_continue',
  91. is_null( $db_data_collection ) ? NULL : $db_data_collection->draw_blood_continue );
  92. $this->set_item(
  93. 'data_collection_physical_tests_continue',
  94. is_null( $db_data_collection ) ? NULL : $db_data_collection->physical_tests_continue );
  95. $this->set_item(
  96. 'next_of_kin_first_name', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->first_name );
  97. $this->set_item(
  98. 'next_of_kin_last_name', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->last_name );
  99. $this->set_item(
  100. 'next_of_kin_gender', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->gender );
  101. $this->set_item(
  102. 'next_of_kin_phone', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->phone );
  103. $this->set_item(
  104. 'next_of_kin_street', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->street );
  105. $this->set_item(
  106. 'next_of_kin_city', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->city );
  107. $this->set_item(
  108. 'next_of_kin_province', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->province );
  109. $this->set_item(
  110. 'next_of_kin_postal_code', is_null( $db_next_of_kin ) ? '' : $db_next_of_kin->postal_code );
  111. try
  112. {
  113. $this->appointment_list->process();
  114. $this->appointment_list->remove_column( 'uid' );
  115. $this->appointment_list->execute();
  116. $this->set_variable( 'appointment_list', $this->appointment_list->get_variables() );
  117. }
  118. catch( \cenozo\exception\permission $e ) {}
  119. try
  120. {
  121. $this->callback_list->process();
  122. $this->set_variable( 'callback_list', $this->callback_list->get_variables() );
  123. }
  124. catch( \cenozo\exception\permission $e ) {}
  125. try
  126. {
  127. $this->interview_list->process();
  128. $this->set_variable( 'interview_list', $this->interview_list->get_variables() );
  129. }
  130. catch( \cenozo\exception\permission $e ) {}
  131. // add an action for secondary contact if this participant has no active phone numbers or
  132. // too many failed call attempts
  133. $allow_secondary = false;
  134. $interview_mod = lib::create( 'database\modifier' );
  135. $interview_mod->where( 'completed', '=', false );
  136. $interview_list = $this->get_record()->get_interview_list( $interview_mod );
  137. $phone_mod = lib::create( 'database\modifier' );
  138. $phone_mod->where( 'active', '=', true );
  139. if( 0 == $this->get_record()->get_phone_count( $phone_mod ) )
  140. {
  141. $allow_secondary = true;
  142. }
  143. else if( 0 < count( $interview_list ) )
  144. {
  145. $max_failed_calls = lib::create( 'business\setting_manager' )->get_setting(
  146. 'calling', 'max failed calls', $this->get_record()->get_effective_site() );
  147. // should only be one incomplete interview
  148. $db_interview = current( $interview_list );
  149. if( $max_failed_calls <= $db_interview->get_failed_call_count() ) $allow_secondary = true;
  150. }
  151. if( $allow_secondary )
  152. {
  153. $db_operation = $operation_class_name::get_operation( 'widget', 'participant', 'secondary' );
  154. if( lib::create( 'business\session' )->is_allowed( $db_operation ) )
  155. {
  156. $this->add_action( 'secondary', 'Secondary Contacts', NULL,
  157. 'A list of alternate contacts which can be called to update a '.
  158. 'participant\'s contact information' );
  159. }
  160. else $allow_secondary = false;
  161. }
  162. $this->set_variable( 'allow_secondary', $allow_secondary );
  163. // add an action to withdraw the participant
  164. $db_operation = $operation_class_name::get_operation( 'widget', 'participant', 'withdraw' );
  165. $db_last_consent = $this->get_record()->get_last_consent();
  166. if( lib::create( 'business\session' )->is_allowed( $db_operation ) &&
  167. ( is_null( $db_last_consent ) || true == $db_last_consent->accept ) )
  168. {
  169. $this->add_action( 'withdraw', 'Withdraw', NULL,
  170. 'Marks the participant as denying consent and brings up the withdraw script '.
  171. 'in order to process the participant\'s withdraw preferences.' );
  172. }
  173. }
  174. /**
  175. * Overrides the interview list widget's method.
  176. *
  177. * @author Patrick Emond <emondpd@mcmaster.ca>
  178. * @param database\modifier $modifier Modifications to the list.
  179. * @return int
  180. * @interview protected
  181. */
  182. public function determine_interview_count( $modifier = NULL )
  183. {
  184. if( NULL == $modifier ) $modifier = lib::create( 'database\modifier' );
  185. $modifier->where( 'participant_id', '=', $this->get_record()->id );
  186. $interview_class_name = lib::get_class_name( 'database\interview' );
  187. return $interview_class_name::count( $modifier );
  188. }
  189. /**
  190. * Overrides the interview list widget's method.
  191. *
  192. * @author Patrick Emond <emondpd@mcmaster.ca>
  193. * @param database\modifier $modifier Modifications to the list.
  194. * @return array( record )
  195. * @interview protected
  196. */
  197. public function determine_interview_list( $modifier = NULL )
  198. {
  199. if( NULL == $modifier ) $modifier = lib::create( 'database\modifier' );
  200. $modifier->where( 'participant_id', '=', $this->get_record()->id );
  201. $interview_class_name = lib::get_class_name( 'database\interview' );
  202. return $interview_class_name::select( $modifier );
  203. }
  204. /**
  205. * The participant list widget.
  206. * @var appointment_list
  207. * @access protected
  208. */
  209. protected $appointment_list = NULL;
  210. /**
  211. * The participant list widget.
  212. * @var callback_list
  213. * @access protected
  214. */
  215. protected $callback_list = NULL;
  216. /**
  217. * The participant list widget.
  218. * @var interview_list
  219. * @access protected
  220. */
  221. protected $interview_list = NULL;
  222. }