/**
  * The user has to respond to the checklist questions provided by this function.
  * @param type $form_state
  * @param type $disabled
  * @param type $myvalues
  * @param type $sSectionTitle
  * @param type $sChecklistType
  * @param type $modality_abbr
  * @param type $protocol_shortname
  * @return element for a renderable form array
  */
 function getPageChecklistArea(&$form_state, $disabled, $myvalues, $sSectionTitle, $sChecklistType, $modality_abbr, $protocol_shortname)
 {
     $root = array('#type' => 'fieldset', '#title' => t($sSectionTitle), '#attributes' => array('class' => array('checklist-dataentry-area')), '#disabled' => $disabled);
     $root[] = array('#markup' => '<div class="safety-checklist">');
     //die('LOOK all answers>>>'.print_r($myvalues['questions'],TRUE));
     //Grab all the relevant questions.
     $aQuestionRef = $this->getAllQuestions($sChecklistType, $modality_abbr, $protocol_shortname);
     //First grab all the checklist questions already answered by other users.
     if (isset($myvalues['questions']['otheruser'])) {
         $aAnsweredByOtherUsers = $myvalues['questions']['otheruser'];
         $otherusersarea = array();
         foreach ($aAnsweredByOtherUsers as $nUID => $aFromOneUser) {
             if (is_array($aFromOneUser)) {
                 //die('Look now>>>'.$nUID.'>>>'.print_r($aFromOneUser,TRUE));
                 $oOtherUser = new \raptor\UserInfo($nUID, FALSE);
                 $username = $oOtherUser->getFullName();
                 $otherusersarea[$nUID] = array('#type' => 'fieldset', '#title' => t('Answers from ' . $username), '#attributes' => array('class' => array('otheruser-safety-checklist-answers-area')), '#disabled' => TRUE);
                 $element = array('#markup' => '<ol>');
                 $otherusersarea[$nUID][] = $element;
                 $questionnumber = 0;
                 foreach ($aFromOneUser as $sShortName => $aOneQuestionAnswer) {
                     $details = $aQuestionRef[$sShortName];
                     $question_tx = $details['question_tx'];
                     $comment_prompt_tx = $details['comment_prompt_tx'];
                     $response = $aOneQuestionAnswer['response'];
                     $comment = $aOneQuestionAnswer['comment'];
                     $element = array('#markup' => '<li>' . $question_tx . '<p>' . $response . '</p>');
                     $otherusersarea[$nUID][] = $element;
                     if (trim($comment) > '') {
                         $element = array('#markup' => '<p class="comment-prompt">' . $comment_prompt_tx . '</p><p>' . $comment . '</p>');
                         $otherusersarea[$nUID][] = $element;
                     }
                 }
                 $element = array('#markup' => '</ol>');
                 $otherusersarea[$nUID][] = $element;
             }
         }
         $root['other_answers'] =& $otherusersarea;
     }
     //Now show the content for this user.
     if (!$disabled || isset($myvalues['questions']['thisuser']) && is_array($myvalues['questions']['thisuser'])) {
         $questionnumber = 0;
         foreach ($aQuestionRef as $aOneQuestion) {
             $questionnumber++;
             if ($aOneQuestion['subtype'] == 'core') {
                 $title = 'Core Question ' . $questionnumber;
             }
             if ($aOneQuestion['subtype'] == 'modality') {
                 $title = 'Modality Specific Question ' . $questionnumber;
             }
             if ($aOneQuestion['subtype'] == 'protocol') {
                 $title = 'Protocol Specific Question ' . $questionnumber;
             }
             $shortname = $aOneQuestion['question_shortname'];
             $element = $this->getOneChecklistQuestion($myvalues, $title, $questionnumber, $aOneQuestion, $disabled);
             $root['questions']['thisuser'][$shortname] = $element;
         }
         $root['questions']['#tree'] = TRUE;
         $root[] = array('#markup' => '</div><!-- end of safety checklist for modality=[' . $modality_abbr . '] of protocol=[' . $protocol_shortname . '] -->');
     }
     return $root;
 }
Beispiel #2
0
 /**
  * Write the values into the database.
  * @param type associative array where 'username' MUST be one of the values so we know what record to update.
  */
 function updateDatabase($clickedbutton, $myvalues)
 {
     $bSuccess = TRUE;
     //Assume happy case.
     $successMsg = NULL;
     $nSiteID = $this->m_oContext->getSiteID();
     $nIEN = $myvalues['tid'];
     $nUID = $this->m_oContext->getUID();
     $sCWFS = $this->m_oUtility->getCurrentWorkflowState($nSiteID, $nIEN);
     $updated_dt = date("Y-m-d H:i:s", time());
     $sFullTicketID = $nSiteID . '-' . $nIEN;
     if (isset($myvalues['collaboration_uid']) && is_numeric($myvalues['collaboration_uid'])) {
         //Handle it this way because simple javascript submit seems to assume Approve button otherwise.
         $clickedvalue = 'Collaborate';
     } else {
         $clickedvalue = $clickedbutton['#value'];
     }
     //die('>>>>clicked['.$clickedbutton["#value"].'] values>>>>'.print_r($myvalues,TRUE));
     if ($bSuccess) {
         if (substr($clickedvalue, 0, 7) == 'Approve') {
             //################
             // APPROVAL BLOCK
             //################
             $sNewWFS = 'AP';
             $bSuccess = $this->m_oUtility->saveAllProtocolFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
             if ($bSuccess) {
                 $this->writeContraindicationAcknowledgements($nSiteID, $nIEN, $nUID, $myvalues);
                 //Write success message
                 $successMsg = 'Approved ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
             }
         } else {
             if (substr($clickedvalue, 0, 7) == 'Request') {
                 //#######################
                 // REQUEST APPROVAL BLOCK
                 //#######################
                 $sNewWFS = 'RV';
                 $bSuccess = $this->m_oUtility->saveAllProtocolFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
                 if ($bSuccess) {
                     $this->writeContraindicationAcknowledgements($nSiteID, $nIEN, $nUID, $myvalues);
                     //Write success message
                     $successMsg = 'Requested approval for ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                 }
             } else {
                 if (substr($clickedvalue, 0, 11) == 'Acknowledge') {
                     //##################
                     // ACKNOWLEDGE BLOCK
                     //##################
                     //Save checklist settings.
                     $aAnswers = isset($myvalues['questions']['thisuser']) ? $myvalues['questions']['thisuser'] : NULL;
                     $bSuccess = $this->saveChecklist($nSiteID, $nIEN, $nUID, $updated_dt, $aAnswers);
                     if ($bSuccess) {
                         $this->writeContraindicationAcknowledgements($nSiteID, $nIEN, $nUID, $myvalues);
                         $sNewWFS = 'PA';
                         $this->m_oUtility->changeTicketWorkflowStatus($nSiteID, $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt);
                         //Write success message
                         $successMsg = 'Acknowledged ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                     }
                 } else {
                     if (substr($clickedvalue, 0, 4) == 'Exam') {
                         //####################
                         // EXAM COMPLETE BLOCK
                         //####################
                         $sNewWFS = 'EC';
                         $bSuccess = $this->m_oUtility->saveAllExamFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
                         if ($bSuccess) {
                             $this->writeContraindicationAcknowledgements($nSiteID, $nIEN, $nUID, $myvalues);
                             //Write success message
                             $successMsg = 'Exam completed ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                         }
                     } else {
                         if (substr($clickedvalue, 0, 5) == 'Inter') {
                             //######################################################
                             // INTERPRETATION COMPLETE BLOCK with NO commit to Vista
                             //######################################################
                             $sNewWFS = 'QA';
                             $bSuccess = $this->m_oUtility->saveAllInterpretationFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
                             if ($bSuccess) {
                                 $this->m_oUtility->changeTicketWorkflowStatus($nSiteID, $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt);
                                 //Write success message
                                 $successMsg = 'Interpretation completed ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                             }
                         } else {
                             if (substr($clickedvalue, 0, 2) == 'QA') {
                                 //##########################################
                                 // QA COMPLETE BLOCK with NO commit to Vista
                                 //##########################################
                                 $sNewWFS = 'QA';
                                 //Stays in QA forever
                                 $bSuccess = $this->m_oUtility->saveAllQAFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
                                 if ($bSuccess) {
                                     $this->m_oUtility->changeTicketWorkflowStatus($nSiteID, $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt);
                                     //Write success message
                                     $successMsg = 'QA completed ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                 }
                             } else {
                                 if (strpos($clickedvalue, 'Commit') !== FALSE) {
                                     //######################
                                     // COMMIT TO VISTA BLOCK
                                     //######################
                                     $sNewWFS = 'QA';
                                     //Stays in QA forever
                                     if (strpos($clickedvalue, 'Interpret') !== FALSE) {
                                         $bSuccess = $this->m_oUtility->saveAllInterpretationFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
                                     } elseif (strpos($clickedvalue, 'QA') !== FALSE) {
                                         $bSuccess = $this->m_oUtility->saveAllQAFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
                                     } else {
                                         throw new \Exception('Did not recognize button click value [' . $clickedvalue . ']');
                                     }
                                     if ($bSuccess) {
                                         $bSuccess = $this->commitDataToVista($nSiteID, $nIEN, $nUID, $sCWFS, $myvalues);
                                         if ($bSuccess) {
                                             $this->m_oUtility->changeTicketWorkflowStatus($nSiteID, $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt);
                                             if (substr($clickedvalue, 0, 5) == 'Inter') {
                                                 //We were in interpret mode so write the QA message
                                                 $successMsg = 'Interpretation completed and updated VISTA for ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                             } else {
                                                 //Write success message for QA mode
                                                 $successMsg = 'QA completed and updated VISTA for ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                             }
                                         }
                                     }
                                 } else {
                                     if (substr($clickedvalue, 0, 12) == 'Cancel Order') {
                                         //####################
                                         // CANCEL ORDER BLOCK
                                         //####################
                                         //Cancel the order now
                                         try {
                                             $is_okay = TRUE;
                                             $orderIENs = $this->getSelectedOrderIENs($myvalues);
                                             $reasonCode = $myvalues['cancelreason'];
                                             $cancelcomment = $myvalues['cancelcomment'];
                                             die('TODO CANCEL THESE IENS >>>>' . print_r($orderIENs, TRUE) . '<br>For reason="' . $reasonCode . '"' . '<br>comment="' . $cancelcomment . '"' . '<br>Hit the back button to test again');
                                             /*
                                                                 $oInsert = db_insert('raptor_ticket_suspend_notes')
                                                    ->fields(array(
                                                        'siteid' => $nSiteID,
                                                        'IEN' => $nIEN,
                                                        'notes_tx' => $myvalues['notes_tx'],
                                                        'author_uid' => $nUID,
                                                        'created_dt' => $updated_dt,
                                                    ))
                                                    ->execute();
                                             * 
                                             */
                                         } catch (\Exception $e) {
                                             error_log('Failed to create raptor_ticket_suspend_notes: ' . $e . "\nDetails..." . print_r($myvalues, true));
                                             form_set_error('suspend_notes_tx', 'Failed to save notes for this ticket!');
                                             $bSuccess = FALSE;
                                         }
                                         $sNewWFS = 'IA';
                                         $this->m_oUtility->changeTicketWorkflowStatus($nSiteID, $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt);
                                         //Write success message
                                         $successMsg = 'Cancelled Order ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                     } else {
                                         if (substr($clickedvalue, 0, 7) == 'Suspend' || substr($clickedvalue, 0, 6) == 'Remove') {
                                             //################
                                             // SUSPEND BLOCK
                                             //################
                                             //Create the raptor_ticket_suspend_notes record now
                                             try {
                                                 $oInsert = db_insert('raptor_ticket_suspend_notes')->fields(array('siteid' => $nSiteID, 'IEN' => $nIEN, 'notes_tx' => $myvalues['suspend_notes_tx'], 'author_uid' => $nUID, 'created_dt' => $updated_dt))->execute();
                                             } catch (\Exception $e) {
                                                 error_log('Failed to create raptor_ticket_suspend_notes: ' . $e . "\nDetails..." . print_r($myvalues, true));
                                                 form_set_error('suspend_notes_tx', 'Failed to save notes for this ticket!');
                                                 $bSuccess = FALSE;
                                             }
                                             $sNewWFS = 'IA';
                                             $this->m_oUtility->changeTicketWorkflowStatus($nSiteID, $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt);
                                             //Write success message
                                             $successMsg = 'Suspended ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                         } else {
                                             if (substr($clickedvalue, 0, 9) == 'Unsuspend') {
                                                 //################
                                                 // UNSUSPEND BLOCK
                                                 //################
                                                 //Create the raptor_ticket_unsuspend_notes record now
                                                 try {
                                                     $oInsert = db_insert('raptor_ticket_unsuspend_notes')->fields(array('siteid' => $nSiteID, 'IEN' => $nIEN, 'notes_tx' => 'Unsuspended by user', 'author_uid' => $nUID, 'created_dt' => $updated_dt))->execute();
                                                 } catch (\Exception $e) {
                                                     error_log('Failed to create raptor_ticket_unsuspend_notes: ' . $e . "\nDetails..." . print_r($myvalues, true));
                                                     form_set_error('unsuspend_notes_tx', 'Failed to save notes for this ticket!');
                                                     $bSuccess = FALSE;
                                                 }
                                                 $sNewWFS = 'AC';
                                                 $this->m_oUtility->changeTicketWorkflowStatus($nSiteID, $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt);
                                                 //Write success message
                                                 $successMsg = 'Unsuspended ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                             } else {
                                                 if (substr($clickedvalue, 0, 7) == 'Reserve' || substr($clickedvalue, 0, 11) == 'Collaborate') {
                                                     //#############################
                                                     // RESERVE or COLLABORATE BLOCK
                                                     //#############################
                                                     $this->writeContraindicationAcknowledgements($nSiteID, $nIEN, $nUID, $myvalues);
                                                     $sMode = NULL;
                                                     //Indicate which of the two modes. C or R
                                                     if (substr($clickedvalue, 0, 11) == 'Collaborate') {
                                                         //Collaborate with the selected user.
                                                         $sMode = 'C';
                                                         $collaboration_uid = $myvalues['collaboration_uid'];
                                                         $collaboration_note_tx = $myvalues['collaboration_note_tx'];
                                                     } else {
                                                         //Collaborate with yourself.
                                                         $sMode = 'R';
                                                         $collaboration_uid = $nUID;
                                                         $collaboration_note_tx = 'Reserving for myself.';
                                                     }
                                                     //Create the raptor_ticket_collaboration record now
                                                     try {
                                                         $result = db_select('raptor_ticket_collaboration', 'p')->fields('p')->condition('siteid', $nSiteID, '=')->condition('IEN', $nIEN, '=')->condition('collaborator_uid', $collaboration_uid, '=')->condition('active_yn', 1, '=')->execute();
                                                         $nRows = $result->rowCount();
                                                         if ($nRows > 0 && $sMode == 'R') {
                                                             //No need to write records for a reservation if same user.  Note: not same thing as collaborate case!
                                                             $successMsg = 'Already reserved ' . $myvalues['tid'] . ' (' . $myvalues['procName'] . ') by the same user.';
                                                         } else {
                                                             //Deactivate any existing collaboration records
                                                             try {
                                                                 $updated = db_update('raptor_ticket_collaboration')->fields(array('active_yn' => 0))->condition('siteid', $nSiteID, '=')->condition('IEN', $nIEN, '=')->condition('active_yn', 1, '=')->execute();
                                                             } catch (\Exception $ex) {
                                                                 $showmsg = 'Unable deactivate existing collaboration settings!';
                                                                 error_log($showmsg . '  Failed to reserve because failed update: ' . $ex . "\nDetails..." . print_r($myvalues, true));
                                                                 drupal_set_message($showmsg, 'error');
                                                                 return 0;
                                                             }
                                                             try {
                                                                 $oInsert = db_insert('raptor_ticket_collaboration')->fields(array('siteid' => $nSiteID, 'IEN' => $nIEN, 'requester_uid' => $nUID, 'requested_dt' => $updated_dt, 'requester_notes_tx' => $collaboration_note_tx, 'collaborator_uid' => $collaboration_uid, 'active_yn' => 1))->execute();
                                                             } catch (\Exception $ex) {
                                                                 $showmsg = 'Unable insert collaboration record!';
                                                                 error_log($showmsg . ' Failed to collaborate because failed raptor_ticket_collaboration insert: ' . $ex . "\nDetails..." . print_r($myvalues, true));
                                                                 drupal_set_message($showmsg, 'error');
                                                                 return 0;
                                                             }
                                                         }
                                                     } catch (\Exception $ex) {
                                                         error_log('Failed to create raptor_ticket_collaboration: ' . $ex . "\nDetails..." . print_r($myvalues, true));
                                                         form_set_error('protocol1_nm', 'Failed to reserve this ticket!');
                                                         $bSuccess = FALSE;
                                                     }
                                                     $sNewWFS = 'CO';
                                                     $this->m_oUtility->saveAllProtocolFieldValues($nSiteID, $nIEN, $nUID, $sCWFS, $sNewWFS, $updated_dt, $myvalues);
                                                     //Write success message
                                                     if ($sMode == 'C') {
                                                         $oOtherUser = new \raptor\UserInfo($collaboration_uid);
                                                         $sFullname = $oOtherUser->getFullName();
                                                         $successMsg = 'Collaboration with ' . $sFullname . ' set for ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                                     } else {
                                                         $successMsg = 'Reserved ' . $sFullTicketID . ' (' . $myvalues['procName'] . ')';
                                                     }
                                                 } else {
                                                     //Did not recognize the button STOP EVERYTHING!
                                                     $diemsg = 'Did NOT recognize the [' . $clickedvalue . '] button pressed in updateDatabase!!!>>>' . print_r($myvalues, TRUE);
                                                     error_log($diemsg);
                                                     die($diemsg);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!$bSuccess) {
         drupal_set_message('Trouble processing the page.', 'error');
     } else {
         if ($successMsg == NULL || strlen(trim($successMsg)) == 0) {
             //If this happens, help us debug.
             drupal_set_message('Missing success message', 'warning');
         } else {
             drupal_set_message($successMsg);
         }
     }
     return $bSuccess;
 }