Skip to content
Snippets Groups Projects
GenObservations.php 3.31 KiB
Newer Older
aly2191's avatar
aly2191 committed
<?php

use CRM_Generalobservation_ExtensionUtil as E;
aly2191's avatar
aly2191 committed

class CRM_Generalobservation_Page_GenObservations extends CRM_Core_Page {
  private $_currentData = [];
aly2191's avatar
aly2191 committed

  public function run() {
    CRM_Utils_System::setTitle(E::ts('GenObservations'));
    CRM_Core_Session::singleton()
      ->pushUserContext(CRM_Utils_System::url("civicrm/nbrbarcodeprint/form/general", "reset=1", TRUE));
    $entityId = (int) CRM_Utils_Request::retrieveValue('cid', 'Integer');
    $this->assign('entityId', $entityId);
    $this->assign('editButton', $this->createEditButton($entityId));
    $this->assign('deleteButton', $this->createDeleteButton($entityId));
    $this->assign('contactObservations', $this->getUserGenObs($entityId));
aly2191's avatar
aly2191 committed
    parent::run();
  }

  private function getUserGenObs($entityId) {
aly2191's avatar
aly2191 committed
    $userObservation = [];
    $observationData = CRM_Generalobservation_BAO_GenObservations::getWithId($entityId);
    $userObservation[] = $this->assembleObsRow($observationData);
aly2191's avatar
aly2191 committed
    return $userObservation;
  }
  public static function yesOrNo($value) {
    if ($value !== NULL) {
      $value = ($value) ? "Yes" : "No";
    }
    return $value;
  }
aly2191's avatar
aly2191 committed

  // Convert to readable format, might not even need to change most
aly2191's avatar
aly2191 committed
  private function assembleObsRow($dao) {
    $observationTemplate = [];
    $observationTemplate['id'] = ($dao->id) ? $dao->id : "N/A";
    $observationTemplate['entity_id'] = $dao->entity_id;
    $observationTemplate['nvgo_weight_kg'] = ($dao->nvgo_weight_kg);
    $observationTemplate['nvgo_height_m'] = $dao->nvgo_height_m;
    $observationTemplate['nvgo_bmi'] = $dao->nvgo_bmi;
    // Convert database values to be more readable
aly2191's avatar
aly2191 committed
    $observationTemplate['nvgo_hand_preference'] = CRM_Nihrbackbone_Utils::getOptionValueLabel($dao->nvgo_hand_preference, 'nbr_hand_preference');
    $observationTemplate['nvgo_ethnicity_id'] = CRM_Nihrbackbone_Utils::getOptionValueLabel($dao->nvgo_ethnicity_id, 'nihr_ethnicity');
    $observationTemplate['nvgo_abo_group'] = CRM_Nihrbackbone_Utils::getOptionValueLabel($dao->nvgo_abo_group, 'nbr_abo_group');
    $observationTemplate['nvgo_rhesus_factor'] = CRM_Nihrbackbone_Utils::getOptionValueLabel($dao->nvgo_rhesus_factor, 'nbr_rhesus_factor');
    $observationTemplate['nvgo_probably_consanguineous'] = $this->yesOrNo($dao->nvgo_probably_consanguineous);
    $observationTemplate['nvgo_proband'] = ($dao->nvgo_proband) ? "Proband" : NULL;
    $observationTemplate['nvgo_family_history'] = $this->yesOrNo($dao->nvgo_family_history);
    $observationTemplate['show_on_portal_1015'] = $this->yesOrNo($dao->show_on_portal_1015);
aly2191's avatar
aly2191 committed

    return ($observationTemplate);
  }

  protected function createEditButton($entityId) {
    $updateUrl = CRM_Utils_System::url('civicrm/generalobservation/form/genobservations', 'reset=1&action=update&cid=' . $entityId, TRUE);
    $editButton = '<a class="action-item button" title="Update" href="' . $updateUrl . '">' . E::ts('Edit general observations') . '</a>';
aly2191's avatar
aly2191 committed
    return $editButton;
  }
  protected function createDeleteButton($entityId) {
    $deleteUrl = CRM_Utils_System::url('civicrm/generalobservation/form/genobservations', 'reset=1&action=delete&cid=' . $entityId, TRUE);
    $deleteButton = '<a class="action-item button" id="deleteBtn" entity_id="' . $entityId . '" title="Delete"">' . E::ts('Delete general observations') . '</a>';
aly2191's avatar
aly2191 committed

}