Skip to content

Commit

Permalink
Merge pull request #2620 from department-of-veterans-affairs/revert_d…
Browse files Browse the repository at this point in the history
…ev_leaf_4455

Revert - Merge pull request #2615 (leaf-4455)
  • Loading branch information
Pelentan authored Dec 12, 2024
2 parents ab2d96e + 53146f4 commit 1a15579
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 89 deletions.
121 changes: 57 additions & 64 deletions LEAF_Request_Portal/sources/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,16 +573,15 @@ public function getIndicator($indicatorID, $series, $recordID = null, $parseTemp
$form[$idx]['value'] = $this->fileToArray($data[0]['data']);
$form[$idx]['raw'] = $data[0]['data'];
}
// special handling for org chart data types (request header questions, edited report builder cells)
// special handling for org chart data types
else if ($data[0]['format'] == 'orgchart_employee'
&& !empty($data[0]['data']))
{
$form[$idx]['displayedValue'] = '';
if (isset($data[0]['metadata'])) {
$orgchartInfo = json_decode($data[0]['metadata'], true);
if(!empty(trim($orgchartInfo['lastName']))) {
$form[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}";
}
$empRes = $this->employee->lookupEmpUID($data[0]['data']);
if (!empty($empRes)) {
$form[$idx]['displayedValue'] = "{$empRes[0]['firstName']} {$empRes[0]['lastName']}";
} else {
$form[$idx]['displayedValue'] = '';
}
}
else if ($data[0]['format'] == 'orgchart_position'
Expand Down Expand Up @@ -1009,9 +1008,9 @@ public function getRecordInfo($recordID)
);
}

$userMetadata = json_decode($res[0]['userMetadata'], true);
$name = isset($userMetadata) && !empty(trim($userMetadata['lastName'])) ?
"{$userMetadata['firstName']} {$userMetadata['lastName']}" : $res[0]['userID'];
$dir = new VAMC_Directory;
$user = $dir->lookupLogin($res[0]['userID']);
$name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $res[0]['userID'];

$data = array('name' => $name,
'service' => $res[0]['service'],
Expand Down Expand Up @@ -2659,14 +2658,16 @@ public function getCustomData(array $recordID_list, string|null $indicatorID_lis
}
}
break;
case 'orgchart_employee': //report builder cells
$item['data'] = '';
if (isset($item['metadata'])) {
$orgchartInfo = json_decode($item['metadata'], true);
if(!empty(trim($orgchartInfo['lastName']))) {
$item['data'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}";
$item['dataOrgchart'] = $orgchartInfo;
}
case 'orgchart_employee':
$empRes = $this->employee->lookupEmpUID($item['data']);
if (isset($empRes[0]))
{
$item['data'] = "{$empRes[0]['firstName']} {$empRes[0]['lastName']}";
$item['dataOrgchart'] = $empRes[0];
}
else
{
$item['data'] = '';
}
break;
case 'orgchart_position':
Expand Down Expand Up @@ -2784,27 +2785,28 @@ public function getActionComments(int $recordID): array
} else {
$vars = array(':recordID' => $recordID);

$sql = 'SELECT actionTextPasttense, comment, time, userID, userMetadata
$sql = 'SELECT actionTextPasttense, comment, time, userID
FROM action_history
LEFT JOIN dependencies USING (dependencyID)
LEFT JOIN actions USING (actionType)
WHERE recordID = :recordID
AND comment != ""
UNION
SELECT "Note Added", note, timestamp, userID, userMetadata
SELECT "Note Added", note, timestamp, userID
FROM notes
WHERE recordID = :recordID
AND deleted IS NULL
ORDER BY time DESC';

$res = $this->db->prepared_query($sql, $vars);

$dir = new VAMC_Directory;

$total = count($res);
for ($i = 0; $i < $total; $i++) {
$userMetadata = json_decode($res[$i]['userMetadata'], true);
$name = isset($userMetadata) && !empty(trim($userMetadata['lastName'])) ?
"{$userMetadata['firstName']} {$userMetadata['lastName']}" : $res[$i]['userID'];

for ($i = 0; $i < $total; $i++) {
$user = $dir->lookupLogin($res[$i]['userID']);
$name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $res[$i]['userID'];
$res[$i]['name'] = $name;
}

Expand Down Expand Up @@ -2956,9 +2958,11 @@ public function setInitiator($recordID, $userID)
userID=:userID, userMetadata=:userMetadata
WHERE recordID=:recordID', $vars);

// write log entry
$dir = new VAMC_Directory;

$newInitiatorInfo = json_decode($newInitiatorMetadata, true);
$name = "{$newInitiatorInfo['firstName']} {$newInitiatorInfo['lastName']}";
$user = $dir->lookupLogin($userID);
$name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $userID;

$actionUserID = $this->login->getUserID();
$actionUserMetadata = $this->employee->getInfoForUserMetadata($actionUserID, false);
Expand Down Expand Up @@ -3761,27 +3765,14 @@ public function query(string $inQuery): mixed
WHERE format = 'orgchart_employee') rj_OCEmployeeData ON (lj_data.indicatorID = rj_OCEmployeeData.indicatorID) ";
}


//joinInitiatorNames backwards compat - additional SQL for records.userMetadata replaces previous join with orgchart.employee.
//userMetadata properties are empty for accounts that were inactive when prior metadata values were updated.
//Alternatives here display 'userID (inactive account)' instead of 'null, null' if metadata is empty.
$initiatorNamesSQL = '';
if ($joinInitiatorNames) {
$initiatorNamesSQL = ',
IF(
JSON_EXTRACT(`userMetadata`, "$.userName") != "",
TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.firstName")), "(inactive account)"
) AS `firstName`,
IF(
JSON_EXTRACT(`userMetadata`, "$.userName") != "",
TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.lastName")), `userID`
) AS `lastName`';
if ($joinInitiatorNames)
{
$joins .= "LEFT JOIN (SELECT userName, lastName, firstName FROM {$this->oc_dbName}.employee) lj_OCinitiatorNames ON records.userID = lj_OCinitiatorNames.userName ";
}
$resSQL = 'SELECT * ' . $initiatorNamesSQL . ' FROM `records` ' . $joins . ' WHERE ' . $conditions . $sort . $limit;

if(isset($_GET['debugQuery'])) {
if($this->login->checkGroup(1)) {
$debugQuery = str_replace(["\r", "\n","\t", "%0d","%0a","%09","%20", ";"], ' ', $resSQL);
$debugQuery = str_replace(["\r", "\n","\t", "%0d","%0a","%09","%20", ";"], ' ', 'SELECT * FROM records ' . $joins . 'WHERE ' . $conditions . $sort . $limit);
$debugVars = [];
foreach($vars as $key => $value) {
if(strpos($key, ':data') !== false
Expand All @@ -3795,14 +3786,17 @@ public function query(string $inQuery): mixed

header('X-LEAF-Query: '. str_replace(array_keys($debugVars), $debugVars, $debugQuery));

return $res = $this->db->prepared_query('EXPLAIN ' . $resSQL, $vars);
return $res = $this->db->prepared_query('EXPLAIN SELECT * FROM records
' . $joins . '
WHERE ' . $conditions . $sort . $limit, $vars);
}
else {
return XSSHelpers::scrubObjectOrArray(json_decode(html_entity_decode(html_entity_decode($_GET['q'])), true));
}
}

$res = $this->db->prepared_query($resSQL, $vars);
$res = $this->db->prepared_query('SELECT * FROM records
' . $joins . '
WHERE ' . $conditions . $sort . $limit, $vars);

$data = array();
$recordIDs = '';
Expand Down Expand Up @@ -3878,15 +3872,17 @@ public function query(string $inQuery): mixed

if ($joinActionHistory)
{
$dir = new VAMC_Directory;

$actionHistorySQL =
'SELECT recordID, stepID, userID, userMetadata, time, description,
'SELECT recordID, stepID, userID, time, description,
actionTextPasttense, actionType, comment
FROM action_history
LEFT JOIN dependencies USING (dependencyID)
LEFT JOIN actions USING (actionType)
WHERE recordID IN (' . $recordIDs . ')
UNION
SELECT recordID, "-5", userID, userMetadata, timestamp, "Note Added",
SELECT recordID, "-5", userID, timestamp, "Note Added",
"Note Added", "LEAF_note", note
FROM notes
WHERE recordID IN (' . $recordIDs . ')
Expand All @@ -3896,10 +3892,8 @@ public function query(string $inQuery): mixed
$res2 = $this->db->prepared_query($actionHistorySQL, array());
foreach ($res2 as $item)
{
$userMetadata = json_decode($item['userMetadata'], true);
$name = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ?
"{$userMetadata['firstName']} {$userMetadata['lastName']}" : $item['userID'];

$user = $dir->lookupLogin($item['userID'], true);
$name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $res[0]['userID'];
$item['approverName'] = $name;

$data[$item['recordID']]['action_history'][] = $item;
Expand Down Expand Up @@ -3937,7 +3931,9 @@ public function query(string $inQuery): mixed
}

if ($joinRecordResolutionBy === true) {
$recordResolutionBySQL = "SELECT recordID, action_history.userID as resolvedBy, action_history.userMetadata, action_history.stepID, action_history.actionType
$dir = new VAMC_Directory;

$recordResolutionBySQL = "SELECT recordID, action_history.userID as resolvedBy, action_history.stepID, action_history.actionType
FROM action_history
LEFT JOIN records USING (recordID)
INNER JOIN workflow_routes USING (stepID)
Expand All @@ -3952,9 +3948,8 @@ public function query(string $inQuery): mixed
$res2 = $this->db->prepared_query($recordResolutionBySQL, array());

foreach ($res2 as $item) {
$userMetadata = json_decode($item['userMetadata'], true);
$nameResolved = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ?
"{$userMetadata['firstName']} {$userMetadata['lastName']} " : $item['resolvedBy'];
$user = $dir->lookupLogin($item['resolvedBy'], true);
$nameResolved = isset($user[0]) ? "{$user[0]['Lname']}, {$user[0]['Fname']} " : $item['resolvedBy'];
$data[$item['recordID']]['recordResolutionBy']['resolvedBy'] = $nameResolved;
}
}
Expand Down Expand Up @@ -4366,15 +4361,14 @@ private function buildFormTree($id, $series = null, $recordID = null, $parseTemp
{
$var = array(':series' => (int)$series,
':recordID' => (int)$recordID, );
$res2 = $this->db->prepared_query('SELECT data, metadata, timestamp, indicatorID, groupID, userID FROM data
$res2 = $this->db->prepared_query('SELECT data, timestamp, indicatorID, groupID, userID FROM data
LEFT JOIN indicator_mask USING (indicatorID)
WHERE indicatorID IN (' . $indicatorList . ') AND series=:series AND recordID=:recordID', $var);

foreach ($res2 as $resIn)
{
$idx = $resIn['indicatorID'];
$data[$idx]['data'] = isset($resIn['data']) ? $resIn['data'] : '';
$data[$idx]['metadata'] = isset($resIn['metadata']) ? $resIn['metadata'] : null;
$data[$idx]['timestamp'] = isset($resIn['timestamp']) ? $resIn['timestamp'] : 0;
$data[$idx]['groupID'] = isset($resIn['groupID']) ? $resIn['groupID'] : null;
$data[$idx]['userID'] = isset($resIn['userID']) ? $resIn['userID'] : '';
Expand Down Expand Up @@ -4441,15 +4435,14 @@ private function buildFormTree($id, $series = null, $recordID = null, $parseTemp
$child[$idx]['value'] = $this->fileToArray($data[$idx]['data']);
}

// special handling for org chart data types (request subquestions / child)
// special handling for org chart data types
if ($field['format'] == 'orgchart_employee')
{
$empRes = $this->employee->lookupEmpUID($data[$idx]['data']);
$child[$idx]['displayedValue'] = '';
if (isset($data[$idx]['metadata'])) {
$orgchartInfo = json_decode($data[$idx]['metadata'], true);
if(!empty(trim($orgchartInfo['lastName']))) {
$child[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}";
}
if (isset($empRes[0]))
{
$child[$idx]['displayedValue'] = ($child[$idx]['isMasked']) ? '[protected data]' : "{$empRes[0]['firstName']} {$empRes[0]['lastName']}";
}
}
if ($field['format'] == 'orgchart_position')
Expand Down
20 changes: 10 additions & 10 deletions LEAF_Request_Portal/sources/FormWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel
$strSQL = "";

if(!$selectUnfilled) {
$strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, userMetadata, requiresDigitalSignature FROM records_workflow_state
$strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, requiresDigitalSignature FROM records_workflow_state
LEFT JOIN records USING (recordID)
LEFT JOIN workflow_steps USING (stepID)
LEFT JOIN step_dependencies USING (stepID)
Expand All @@ -456,7 +456,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel
WHERE recordID IN ({$recordIDs})";
}
else {
$strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID, userMetadata FROM records_workflow_state
$strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID FROM records_workflow_state
LEFT JOIN records USING (recordID)
LEFT JOIN workflow_steps USING (stepID)
LEFT JOIN step_dependencies USING (stepID)
Expand Down Expand Up @@ -494,8 +494,8 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel
$approver = $dir->lookupLogin($res[$i]['userID']);

if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) {
$res[$i]['description'] = $res[$i]['stepTitle'] . ' (Inactive User)';
$res[$i]['approverName'] = '(Inactive User)';
$res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)';
$res[$i]['approverName'] = '(Requestor followup)';
$res[$i]['approverUID'] = $res[$i]['userID'];
}
else {
Expand Down Expand Up @@ -543,8 +543,8 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel
$dir = $this->getDirectory();
$approver = $dir->lookupLogin($res[$i]['userID']);
if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) {
$res[$i]['description'] = $res[$i]['stepTitle'] . ' (Inactive User)';
$res[$i]['approverName'] = '(Inactive User)';
$res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)';
$res[$i]['approverName'] = '(Requestor followup)';
$res[$i]['approverUID'] = $res[$i]['userID'];
}
else {
Expand Down Expand Up @@ -716,11 +716,11 @@ public function getLastAction(): array|null|int
if (isset($res[0])
&& $res[0]['dependencyID'] == -1)
{
$approverMetadata = json_decode($res[0]['userMetadata'], true);
$display = isset($approverMetadata) && trim($approverMetadata['firstName'] . " " . $approverMetadata['lastName'] ) !== '' ?
$approverMetadata['firstName'] . " " . $approverMetadata['lastName'] : $res[0]['userID'];
$dir = $this->getDirectory();

$approver = $dir->lookupLogin($res[0]['userID']);

$res[0]['description'] = $display;
$res[0]['description'] = "{$approver[0]['firstName']} {$approver[0]['lastName']}";
}
// dependencyID -3 is for a group designated by the requestor
if (isset($res[0])
Expand Down
Loading

0 comments on commit 1a15579

Please sign in to comment.