Ejemplo n.º 1
0
Archivo: LookUp.php Proyecto: bciv/COMS
 function selectByNameDescId($id)
 {
     $source = null;
     if (null != $id) {
         $query = "SELECT Name FROM LookUp WHERE Lookup_ID = '" . $id . "'";
         $source = $this->query($query);
         if (null != $source && array_key_exists('error', $source)) {
             return $source;
         }
         $source = $source[0];
     }
     $query = "SELECT lu.Lookup_ID as id, lu.Lookup_Type as type, lu.Name, lu.Description " . "FROM Template_Availability ta " . "INNER JOIN Master_Template mt ON mt.Template_ID = ta.TemplateID " . "INNER JOIN LookUp lu ON lu.Lookup_ID = mt.Cancer_ID ";
     if (null != $source && 'National Templates' === $source['Name']) {
         $query .= "WHERE ta.NationalLevel = 'Yes'";
     } else {
         if (null != $source && 'Local Templates' === $source['Name']) {
             $query .= "WHERE ta.NationalLevel = 'No'";
         } else {
             if (null != $source && 'My Templates' === $source['Name']) {
                 $username = get_current_user();
                 $mdws = new Mymdws();
                 $roles = $mdws->getRoleInfo($username);
                 $rid = $_SESSION['rid'];
                 $query .= "WHERE ta.TemplateOwner = '" . $rid . "'";
             }
         }
     }
     $query .= " ORDER BY lu.Name";
     return $this->query($query);
 }
Ejemplo n.º 2
0
 function saveTemplate()
 {
     error_log("Lookup Controller - saveTemplate() - Entry Point...");
     $form_data = json_decode(file_get_contents('php://input'));
     $temp = json_encode($form_data);
     // Note: $temp['RegimenName'] is the User Optional Name (sometimes referred to as the Description)
     $regimens = $form_data->{'Meds'};
     $usersuppliedname = $form_data->{'RegimenName'};
     $regimenName = $this->BuildRegimenName($regimens);
     error_log("Lookup Controller - saveTemplate() - Got Regimens");
     $this->LookUp->beginTransaction();
     /*****************************************
      *
      *
      **/
     // Get list of Templates with this Regimen Name (if any).
     // This will give us the count of regimens using the same therapies so we can create a new version #
     $lookupinfo = $this->LookUp->getLookupIdByNameAndType($regimenName, 4);
     $templateNum = count($lookupinfo) + 1;
     // Builds new Chemotherapy Regimen Name based on versioning scheme
     $templateName = date("Y") . '-' . $templateNum . '-0001-ABCD-' . $regimenName . '-' . date("Ymd");
     error_log("Lookup Controller - saveTemplate() - Got TemplateName - {$templateName}");
     // Save Template and Regimen name in the Lookup Table
     $templatelookupid = $this->LookUp->save(4, $regimenName, $templateName);
     while (null == $templatelookupid[0]["lookupid"]) {
         $templateNum++;
         $templateName = date("Y") . '-' . $templateNum . '-0001-ABCD-' . $regimenName . '-' . date("Ymd");
         $templatelookupid = $this->LookUp->save(4, $regimenName, $templateName);
     }
     // Save User Supplied Name in the Lookup Table
     if ($usersuppliedname) {
         $this->LookUp->save(25, $templatelookupid[0]["lookupid"], $usersuppliedname);
     }
     error_log("Lookup Controller - saveTemplate() - Name and Alias saved");
     /*****************************************
      *
      *
      **/
     $cyclelength = $form_data->{'CycleLength'};
     $this->LookUp->saveExtraFields($regimenName, $cyclelength);
     error_log("Lookup Controller - saveTemplate() - Extra Fields saved");
     /**
      * This is just a bandaid because some calls to "/Lookup/saveTemplate" give actual
      * cycle length units and emotegenic levels instead of their GUIDs
      */
     $cycleLengthUnit = $this->LookUp->getIdByNameAndType($form_data->CycleLengthUnit, LookUp::TYPE_TIMEFRAMEUNIT);
     $eLevel = $this->LookUp->getIdByNameAndType($form_data->ELevel, LookUp::TYPE_ELEVEL);
     $form_data->CycleLengthUnit = !empty($cycleLengthUnit) ? $cycleLengthUnit : $form_data->CycleLengthUnit;
     $form_data->ELevel = !empty($eLevel) ? $eLevel : $form_data->ELevel;
     /*
      * END of Bandaid
      */
     $templateid = $this->LookUp->saveTemplate($form_data, $templatelookupid[0]["lookupid"]);
     if ($this->checkForErrors("Insert Master Template (in Lookup Controller) Failed. (id={$templateid})", $templateid)) {
         error_log("Lookup Controller - saveTemplate() - Insert Master Template Failed");
         $this->LookUp->rollbackTransaction();
         return;
     }
     error_log("Lookup Controller - saveTemplate() - Insert Master Template Passed");
     if ($templateid) {
         $templateid = $templateid[0]['lookupid'];
         $references = $form_data->{'References'};
         $this->LookUp->saveTemplateReferences($references, $templateid);
         error_log("Lookup Controller - saveTemplate() - Save Pre Therapy");
         $Order_IDR = $form_data->{'Order_IDR'};
         $prehydrations = $form_data->{'PreMHMeds'};
         if ($prehydrations) {
             //$this->LookUp->OrderX();
             $retVal = $this->LookUp->saveHydrations($prehydrations, 'Pre', $templateid, $Order_IDR);
             if ($this->checkForErrors('Insert Pre Therapy Failed. ', $retVal)) {
                 $this->LookUp->rollbackTransaction();
                 return;
             }
         }
         error_log("Lookup Controller - saveTemplate() - Pre Therapy Save Complete... ");
         error_log("Lookup Controller - saveTemplate() - Save Post Therapy");
         $posthydrations = $form_data->{'PostMHMeds'};
         if ($posthydrations) {
             $retVal = $this->LookUp->saveHydrations($posthydrations, 'Post', $templateid, $Order_IDR);
             if ($this->checkForErrors('Insert Post Therapy Failed. ', $retVal)) {
                 $this->LookUp->rollbackTransaction();
                 return;
             }
         }
         error_log("Lookup Controller - saveTemplate() - Save Therapy");
         if ($regimens) {
             if ($Order_IDR == '') {
                 $Order_IDR = '00000000-0000-0000-0000-000000000000';
             }
             $retVal = $this->LookUp->saveRegimen($regimens, $templateid, $Order_IDR);
             if ($this->checkForErrors('Insert Template Regimens Failed.', $retVal)) {
                 $this->LookUp->rollbackTransaction();
                 error_log("Lookup Controller - saveTemplate() - Save Therapy FAILED");
                 return;
             }
         }
         error_log("Lookup Controller - saveTemplate() - Save Therapy Complete");
     } else {
         $this->set('templateid', $templateid);
         $this->set('frameworkErr', 'Template Id was not generated');
         $this->LookUp->rollbackTransaction();
         return;
     }
     $this->set('templateid', $templateid);
     $this->set('frameworkErr', null);
     if ($usersuppliedname) {
         $this->set('templatename', $usersuppliedname);
     } else {
         $this->set('templatename', $templateName);
     }
     $this->LookUp->endTransaction();
     $NationalLevel = 'No';
     $username = get_current_user();
     $mdws = new Mymdws();
     $roles = $mdws->getRoleInfo($username);
     $rid = $_SESSION['rid'];
     $sitelist = $_SESSION['sitelist'];
     $this->LookUp->saveTemplateLevel($templateid, $sitelist, $NationalLevel, $rid);
 }