/** * Get the values to populate the form. * @return type result of the queries as an array */ function getFieldValues() { $oMdwsDao = $this->m_oContext->getMdwsClient(); //$myvalues['patientid'] = 'TODO'; //!!!!! $myvalues['all_visits'] = \raptor\MdwsUtils::getVisits($oMdwsDao); $myvalues['selected_vid'] = NULL; return $myvalues; }
/** * Get all the form contents for rendering * @return type renderable array */ public function getForm($form, &$form_state, $disabled, $myvalues) { $oUser = $this->m_oContext->getUserInfo(); $localmsg = NULL; if (!$oUser->getPrivilegeSetting('SP1')) { $disabled = TRUE; //Do not let this user edit the schedule information. $localmsg = 'Your account does not have privileges to edit the schedule information.'; } $form['data_entry_area1'] = array('#prefix' => "\n<section id='raptor-admin-container' class='user-profile-dataentry'>\n", '#suffix' => "\n</section>\n", '#disabled' => $disabled); //Hidden values $form['hiddenthings']['tid'] = array('#type' => 'hidden', '#value' => $myvalues['tid']); $form['hiddenthings']['procName'] = array('#type' => 'hidden', '#value' => $myvalues['procName']); $form['hiddenthings']['suggested_alreadyset_uid'] = array('#type' => 'hidden', '#value' => $myvalues['suggested_alreadyset_uid']); $form['data_entry_area1']['toppart']['heading'] = array('#markup' => '<table id="raptor-schedule-table"><tbody>' . '<tr><th>Tracking ID</th><td>' . $myvalues['tid'] . '</td>' . '<th>Patient Name</th><td>' . $myvalues['PatientName'] . '</td></tr>' . '<tr><th>Study</th><td>' . $myvalues['procName'] . '</td>' . '<th>Patient DOB</th><td>' . $myvalues['PatientDOB'] . '</td></tr>' . '<tr><th>Requested Date</th><td>' . $myvalues['RequestedDate'] . '</td>' . '<th>Urgency</th><td>' . $myvalues['Urgency'] . '</td></tr>' . '</tbody></table>'); $form['data_entry_area1']['toppart']['location_tx'] = array('#type' => 'textfield', '#title' => t('Location'), '#default_value' => $myvalues['location_tx'], '#size' => 20, '#maxlength' => 20, '#required' => FALSE); if ($disabled || !is_array($myvalues['rooms'])) { } else { $htmlroomoptions = '<ul>'; $aRooms = $myvalues['rooms']; foreach ($aRooms as $aRoom) { $htmlroomoptions .= '<li><span class="location-option selectable-text"><a href="javascript:setTextboxByName(' . "'location_tx','" . $aRoom[0] . "' )" . '"' . ' title="' . $aRoom[1] . '" >' . $aRoom[0] . '</a></span>'; } $htmlroomoptions .= '</ul>'; $form['data_entry_area1']['toppart']['rooms'] = array('#markup' => $htmlroomoptions); } $form['data_entry_area1']['toppart']['event_date_tx'] = array('#type' => 'textfield', '#title' => t('Event Date'), '#default_value' => $myvalues['event_date_tx'], '#size' => 20, '#maxlength' => 20, '#required' => FALSE, '#attributes' => array('class' => array('datepicker'))); $form['data_entry_area1']['toppart']['event_starttime_tx'] = array('#type' => 'textfield', '#title' => t('Start Time'), '#default_value' => $myvalues['event_starttime_tx'], '#size' => 20, '#maxlength' => 20, '#required' => FALSE); $form['data_entry_area1']['toppart']['duration_am'] = array('#type' => 'textfield', '#title' => t('Duration (minutes)'), '#default_value' => $myvalues['duration_am'], '#size' => 3, '#maxlength' => 3, '#required' => FALSE); //Provide clickable duration options on same row as duration field if ($disabled) { $myvalues['durations'] = array(); //Empty list of minutes } else { if (!isset($myvalues['durations']) || !is_array($myvalues['durations']) || count($myvalues['durations']) == 0) { //Default hardcoded list. $myvalues['durations'] = array('10', '15', '20', '30', '45', '60'); } } $htmldurations = '<ul>'; $aDurations = $myvalues['durations']; foreach ($aDurations as $aDuration) { $htmldurations .= '<li><span class="duration-option selectable-text"><a href="javascript:setTextboxByName(' . "'duration_am','" . $aDuration . "' )" . '"' . ' title="' . $aDuration . ' minutes" >' . $aDuration . '</a></span>'; } $htmldurations .= '</ul>'; $form['data_entry_area1']['toppart']['durations'] = array('#markup' => $htmldurations); $optionsConfirmed = array(0 => t('No'), 1 => t('Yes' . (isset($myvalues['confirmed_by_patient_dt']) ? ' (' . $myvalues['confirmed_by_patient_dt'] . ')' : ''))); $form['data_entry_area1']['middlepart']['confirmed_by_patient_yn'] = array('#type' => 'radios', '#title' => t('Confirmed by patient'), '#default_value' => isset($myvalues['confirmed_by_patient_dt']) ? 1 : 0, '#options' => $optionsConfirmed, '#description' => t('Has the patient confirmed this appointment?')); $mdwsDao = $this->m_oContext->getMdwsClient(); $aCancelOptions = \raptor\MdwsUtils::getRadiologyCancellationReasons($mdwsDao); $fulloptionlist = array(); $fulloptionlist[] = ''; foreach ($aCancelOptions as $option) { $fulloptionlist[] = $option; } $form['data_entry_area1']['middlepart']['canceled_reason_tx'] = array("#type" => "select", "#title" => t("Reason for cancelation (If canceled)"), "#options" => $fulloptionlist, '#default_value' => $myvalues['canceled_reason_tx'], "#description" => t("Select reason for canceling this procedure." . (isset($myvalues['canceled_dt']) ? ' ( Canceled ' . $myvalues['canceled_dt'] . ' )' : '')), "#required" => FALSE); if (is_array($myvalues['assignment_options'])) { $options = $myvalues['assignment_options']; } else { $options[''] = ''; } $form['data_entry_area1']['middlepart']['suggested_uid'] = array("#type" => "select", "#title" => t("Attention of suggestion"), "#options" => $options, '#default_value' => $myvalues['suggested_uid'], "#description" => t('Suggested for the attention of a specific Resident or Radiologist' . ($myvalues['suggested_alreadyset_note'] != NULL ? ' (' . $myvalues['suggested_alreadyset_note'] . ')' : '')), "#required" => FALSE); $form['data_entry_area1']['bottom']['notes_tx'] = array('#type' => 'textarea', '#title' => t('Scheduler Notes'), '#rows' => 3, '#disabled' => $disabled, '#default_value' => $myvalues['notes_tx']); $optionsConfirmed = array(0 => t('No'), 1 => t('Yes')); $form['data_entry_area1']['bottom']['notes_critical_yn'] = array('#type' => 'radios', '#title' => t('Notes contain patient care information?'), '#default_value' => isset($myvalues['notes_critical_yn']) ? $myvalues['notes_critical_yn'] : 0, '#options' => $optionsConfirmed, '#description' => t('Should system ask Radiologist and Technologist to confirm reading the note?')); if ($localmsg != NULL) { $form['data_entry_area1']['bottom']['buttonmsg'] = array('#markup' => '<p class="action-button-message">' . $localmsg . '</p>'); } if (!$disabled) { $form['data_entry_area1']['action_buttons']['schedule'] = array('#type' => 'submit', '#attributes' => array('class' => array('simple-action-button')), '#value' => t('Save Settings'), '#disabled' => $disabled); $form['data_entry_area1']['action_buttons']['addnewschedule'] = array('#type' => 'submit', '#attributes' => array('class' => array('simple-action-button')), '#value' => t('Save these Settings and Add Another Schedule Event for Same Ticket'), '#disabled' => $disabled); } $form['data_entry_area1']['action_buttons']['cancel'] = array('#type' => 'item', '#markup' => '<input class="raptor-dialog-cancel" type="button" value="Cancel">'); return $form; }
/** * Write all the RAPTOR data of curent ticket into VISTA. * - Safety Checklist information * - General notes * @return boolean TRUE if success, else FALSE */ function commitDataToVista($nSiteID, $nIEN, $nUID, $sCWFS, $myvalues, $encounterString = NULL) { $bSuccess = TRUE; $errormsg = NULL; error_log('Starting commitDataToVista(' . $nSiteID . ',' . $nIEN . ') at ' . microtime()); $commit_dt = date("Y-m-d H:i:s", time()); $prev_commit_dt = $this->getDateMostRecentVistaCommitDate($nSiteID, $nIEN); //Verify the electronic sigature $eSig = $myvalues['commit_esig']; $oMdwsDao = $this->m_oContext->getMdwsClient(); //$bValidESig = MdwsUtils::validateEsig($oMdwsDao, $eSig); $bValidESig = $this->isValidEsig($eSig, $oMdwsDao); if (!$bValidESig) { $errormsg = 'Trouble committing ticket ' . $nSiteID . '-' . $nIEN . ' Safety Checklist note to Vista because invalid electronic signature'; $bSuccess = FALSE; } if ($bSuccess) { module_load_include('php', 'raptor_datalayer', 'core/AllUsers'); $oAllUsers = new \raptor\AllUsers(); try { $oMdwsDao = $this->m_oContext->getMdwsClient(); if ($encounterString == NULL) { $aVisits = \raptor\MdwsUtils::getVisits($oMdwsDao); if (is_array($aVisits) && count($aVisits) > 0) { if (isset($myvalues['selected_vid']) && $myvalues['selected_vid'] != '') { $selected_vid = $myvalues['selected_vid']; //vid_<LOCATIONID>_<TIMESTAMP> $vidparts = explode('_', $selected_vid); $locationId = $vidparts[1]; $visitTimestamp = $vidparts[2]; foreach ($aVisits as $aVisit) { if ($aVisit['locationId'] == $locationId && $aVisit['visitTimestamp'] == $visitTimestamp) { $encounterString = \raptor\MdwsUtils::getEncounterStringFromVisit($aVisit['visitTO']); //TODO ask the user to pick one!!! } } if ($encounterString == NULL) { die('Did NOT find an encounter string for $selected_vid=[' . $selected_vid . '] in ' . print_r($aVisits, TRUE)); } } else { throw new \Exception('Did not find any selected visit for the VISTA writeback!'); //drupal_set_message('TODO remove automatic selection of first visit for writeback. Used for writing this record!','warning'); //error_log('commitChecklistToVista got visits='.print_r($aVisits,TRUE).''); //$encounterString = \raptor\MdwsUtils::getEncounterStringFromVisit($aVisits[0]['visitTO']); //TODO ask the user to pick one!!! //error_log('commitChecklistToVista got most recent visit on ticket '.$nSiteID.'-'.$nIEN.' as encounterString=['.$encounterString.']'); } } else { drupal_set_message('Did NOT find any visits to which we can commit a note!', 'error'); $bSuccess = FALSE; } } //Write the note(s). $newNoteIen = NULL; try { $userDuz = $oMdwsDao->getDUZ(); //Pull values from database that have not yet been committed to VISTA $aChecklistData = array(); $this->addUncommittedChecklistDetailsToNotesArray($nSiteID, $nIEN, $oAllUsers, $prev_commit_dt, $aChecklistData); if (count($aChecklistData) > 0) { //Write the checklist note $newNoteIen = \raptor\MdwsUtils::writeRaptorSafetyChecklist($oMdwsDao, $aChecklistData, $encounterString, NULL); MdwsUtils::signNote($oMdwsDao, $newNoteIen, $userDuz, $eSig); } //Pull values from database that have not yet been committed to VISTA $noteTextArray = array(); $this->addUncommittedDetailsToNotesArray($nSiteID, $nIEN, $oAllUsers, $prev_commit_dt, $noteTextArray); if (count($noteTextArray) > 0) { //Yes, write the general note. $newGeneralNoteIen = \raptor\MdwsUtils::writeRaptorGeneralNote($oMdwsDao, $noteTextArray, $encounterString, NULL); MdwsUtils::signNote($oMdwsDao, $newGeneralNoteIen, $userDuz, $eSig); } } catch (\Exception $ex) { drupal_set_message('Trouble in commit because ' . $ex->getMessage(), 'error'); throw $ex; } if ($newNoteIen != NULL) { error_log('commitDataToVista got newNoteIen=[' . $newNoteIen . '] for encounter string=' . $encounterString); } } catch (\Exception $ex) { $errormsg = 'Trouble committing ticket ' . $nSiteID . '-' . $nIEN . ' Safety Checklist note to Vista because ' . $ex->getMessage(); throw $ex; } } if ($bSuccess) { //Okay, record that we successfully committed. try { db_insert('raptor_ticket_commit_tracking')->fields(array('siteid' => $nSiteID, 'IEN' => $nIEN, 'workflow_state' => $sCWFS, 'author_uid' => $nUID, 'commit_dt' => $commit_dt))->execute(); } catch (\Exception $ex) { $errormsg = 'Trouble committing ticket ' . $nSiteID . '-' . $nIEN . ' to raptor_ticket_commit_tracking because ' . $ex->getMessage(); throw $ex; } } if ($bSuccess) { drupal_set_message('Committed patient data to Vista'); } else { if ($errormsg != NULL) { error_log('failed commit to vista>>> ' . $errormsg); drupal_set_message($errormsg, 'error'); } else { drupal_set_message('Trouble committing patient data to Vista', 'error'); } } error_log('Finished commitDataToVista on ticket ' . $nSiteID . '-' . $nIEN . ' at ' . microtime()); return $bSuccess; }