185 lines
6.4 KiB
PHP
185 lines
6.4 KiB
PHP
<?php
|
|
include('../../Connections/repnew.php');
|
|
header('Content-Type: application/json');
|
|
// Database connection
|
|
$host = $servername;
|
|
$db = $database;
|
|
$user = $username;
|
|
$pass = $password;
|
|
|
|
try {
|
|
$pdo = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch (PDOException $e) {
|
|
die("Connection failed: " . $e->getMessage());
|
|
}
|
|
|
|
$temp_json_queue_id = $_POST['id'];
|
|
|
|
// Get the JSON data from the temp_json_queue table
|
|
$json_data = getInterventionedJson($temp_json_queue_id, $pdo);
|
|
|
|
// Decode the JSON data
|
|
$decoded_json_data = json_decode($json_data, true);
|
|
|
|
// Check for unattached analysis
|
|
$unattached_analysis = checkForUnAttachedAnalysis($decoded_json_data,$pdo);
|
|
|
|
// Check for unattached compounds
|
|
$unattached_compounds = checkForUnAttachedCompounds($decoded_json_data, $pdo);
|
|
|
|
// Get all analysis and compounds
|
|
$analysisArr = getAllAnalysis($pdo);
|
|
$compoundsArr = getAllCompounds($pdo);
|
|
|
|
die(json_encode(array(
|
|
'code' => "success",
|
|
'arr_analysis_data' => $unattached_analysis,
|
|
'arr_compunds_data' => $unattached_compounds
|
|
)));
|
|
|
|
// Functions
|
|
function getInterventionedJson($id, $pdo){
|
|
$sql = "SELECT json_data FROM temp_json_queue WHERE id = :id";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute(['id' => $id]);
|
|
$json_data = $stmt->fetchColumn();
|
|
return $json_data;
|
|
}
|
|
|
|
function getAllAnalysis($pdo){
|
|
$sql = "SELECT * FROM analysisvocabulary";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$analysisArr = $stmt->fetchAll();
|
|
return $analysisArr;
|
|
}
|
|
|
|
function getAllCompounds($pdo){
|
|
$sql = "SELECT * FROM compundsvocabulary";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$compoundsArr = $stmt->fetchAll();
|
|
return $compoundsArr;
|
|
}
|
|
function checkForUnAttachedAnalysis($decoded_json_data,$pdo){
|
|
$unattached_analysis = [];
|
|
$data = $decoded_json_data;
|
|
foreach($data['product']['reports'] as $report){
|
|
foreach($report['parts'] as $part){
|
|
foreach($part['analyses'] as $analysis){
|
|
$result_TestName = $analysis['result_TestName'];
|
|
$analysisgroupcode = $analysis['analysisgroupcode'];
|
|
|
|
// validation for analysisgroupcode
|
|
if($analysisgroupcode == '' || $analysisgroupcode == null || $analysisgroupcode == 'N/A' || $analysisgroupcode == '-'){
|
|
$analysisgroupcode = 'NO_ANALYSIS_CODE_PROVIDED';
|
|
}
|
|
|
|
$analysis_id = checkForAnalysisId($analysisgroupcode, $result_TestName, $pdo);
|
|
if(!$analysis_id){
|
|
|
|
$arr_analysiskind_refdata = ("SELECT * FROM analysisvocabulary where preferred like 'Y'");
|
|
$arr_analysiskind_refdata = $pdo->prepare($arr_analysiskind_refdata);
|
|
$arr_analysiskind_refdata->execute();
|
|
$arr_analysiskind_ref = $arr_analysiskind_refdata->fetchAll();
|
|
|
|
array_push($unattached_analysis, [
|
|
'word' => $result_TestName,
|
|
'anaysisword' => $result_TestName,
|
|
'arr_similary' => $arr_analysiskind_ref,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $unattached_analysis;
|
|
}
|
|
|
|
function checkForUnAttachedCompounds($decoded_json_data, $pdo){
|
|
$unattached_compounds = [];
|
|
$data = $decoded_json_data;
|
|
foreach($data['product']['reports'] as $report){
|
|
foreach($report['parts'] as $part){
|
|
foreach($part['analyses'] as $analysis){
|
|
foreach($analysis['results'] as $result){
|
|
$cas = $result['cas'];
|
|
$result_AnalytsName = $result['result_AnalytsName'];
|
|
|
|
// validation for cas
|
|
if($cas == '' || $cas == null || $cas == 'N/A' || $cas == '-'){
|
|
$cas = 'NO_CAS_PROVIDED';
|
|
}
|
|
|
|
$compound_id = checkForCompoundId($cas, $result_AnalytsName, $pdo);
|
|
if(!$compound_id){
|
|
$arr_compoundkind_refdata = ("SELECT * FROM compundsvocabulary where preferred like 'Y'");
|
|
$arr_compoundkind_refdata = $pdo->prepare($arr_compoundkind_refdata);
|
|
$arr_compoundkind_refdata->execute();
|
|
$arr_compoundkind_ref = $arr_compoundkind_refdata->fetchAll();
|
|
|
|
array_push($unattached_compounds, [
|
|
'word' => $result_AnalytsName,
|
|
'anaysisword' => $analysis['result_TestName'],
|
|
'arr_similary' => $arr_compoundkind_ref,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $unattached_compounds;
|
|
}
|
|
|
|
function checkForAnalysisId($analysisgroupcode, $result_TestName, $pdo){
|
|
|
|
// analysisgroupcode check
|
|
if($analysisgroupcode == '' || $analysisgroupcode == null || $analysisgroupcode == 'N/A' || $analysisgroupcode == '-'){
|
|
$analysisgroupcode = 'NO_ANALYSIS_CODE_PROVIDED';
|
|
}
|
|
|
|
$sql = "SELECT idanalysisvocabulary FROM analysisvocabulary WHERE analysiscode LIKE '$analysisgroupcode'";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$analysis_id = $stmt->fetchColumn();
|
|
if(!$analysis_id){
|
|
$sql = "SELECT idanalysisvocabulary FROM analysisvocabulary WHERE nameanalysisvoc LIKE '$result_TestName'";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$analysis_id = $stmt->fetchColumn();
|
|
if(!$analysis_id){
|
|
return false;
|
|
}else{
|
|
return $analysis_id;
|
|
}
|
|
}else{
|
|
return $analysis_id;
|
|
}
|
|
}
|
|
|
|
function checkForCompoundId($cas, $result_AnalytsName, $pdo){
|
|
// cas check
|
|
if($cas == '' || $cas == null || $cas == 'N/A' || $cas == '-'){
|
|
$cas = 'NO_CAS_PROVIDED';
|
|
}
|
|
|
|
$sql = "SELECT idcompoundsvocabulary FROM compundsvocabulary WHERE cascompoundvocabulary LIKE '%$cas%'";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$compound_id = $stmt->fetchColumn();
|
|
if(!$compound_id){
|
|
$sql = "SELECT idcompoundsvocabulary FROM compundsvocabulary WHERE namecompoundsvocabulary LIKE '$result_AnalytsName'";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
$compound_id = $stmt->fetchColumn();
|
|
if(!$compound_id){
|
|
return false;
|
|
}else{
|
|
return $compound_id;
|
|
}
|
|
}else{
|
|
return $compound_id;
|
|
}
|
|
}
|
|
|
|
?>
|