checking vocabularies
This commit is contained in:
parent
01b543dd74
commit
fae8d17316
@ -22,6 +22,85 @@ $jsonEntries = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
foreach ($jsonEntries as $entry) {
|
foreach ($jsonEntries as $entry) {
|
||||||
$data = json_decode($entry['json_data'], true);
|
$data = json_decode($entry['json_data'], true);
|
||||||
$uuid = $entry['uuid'];
|
$uuid = $entry['uuid'];
|
||||||
|
$analysis = array();
|
||||||
|
$compounds = array();
|
||||||
|
|
||||||
|
// check for result_TestName
|
||||||
|
foreach ($data['product']['reports'] as $report) {
|
||||||
|
foreach ($report['parts'] as $part) {
|
||||||
|
foreach ($part['analyses'] as $analysis) {
|
||||||
|
$analysisgroupcode = $analysis['analysisgroupcode'];
|
||||||
|
$result_TestName = $analysis['result_TestName'];
|
||||||
|
// groupcode validation
|
||||||
|
if($analysisgroupcode == '-' || $analysisgroupcode == '' || $analysisgroupcode == ' '){
|
||||||
|
$analysisgroupcode = 'NO_GROUPCODE';
|
||||||
|
}
|
||||||
|
// check in vocabulary
|
||||||
|
$query = "SELECT idanalysisvocabulary FROM analysisvocabulary WHERE analysiscode LIKE '$analysisgroupcode'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$result = $stmt->execute();
|
||||||
|
$result = $stmt->fetchColumn();
|
||||||
|
if(!$result){
|
||||||
|
// check for result_TestName
|
||||||
|
$query = "SELECT idanalysisvocabulary FROM analysisvocabulary WHERE nameanalysisvoc LIKE '$result_TestName'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$result = $stmt->execute();
|
||||||
|
$result = $stmt->fetchColumn();
|
||||||
|
if(!$result){
|
||||||
|
// add 0 to analysis array
|
||||||
|
array_push($analysis, 0);
|
||||||
|
}else{
|
||||||
|
// add 1 to analysis array
|
||||||
|
array_push($analysis, 1);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// add 1 to analysis array
|
||||||
|
array_push($analysis, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for result_AnalytsName
|
||||||
|
foreach ($data['product']['reports'] as $report) {
|
||||||
|
foreach ($report['parts'] as $part) {
|
||||||
|
foreach ($part['analyses'] as $analysis) {
|
||||||
|
foreach ($analysis['results'] as $result) {
|
||||||
|
$result_AnalytsName = $result['result_AnalytsName'];
|
||||||
|
$cas = $result['cas'];
|
||||||
|
|
||||||
|
// cas validation
|
||||||
|
if($cas == '-' || $cas == '' || $cas == ' '){
|
||||||
|
$cas = 'NO_CAS';
|
||||||
|
}
|
||||||
|
|
||||||
|
// check in vocabulary
|
||||||
|
$query = "SELECT idcompoundsvocabulary FROM compundsvocabulary WHERE cascompoundvocabulary LIKE '%$cas%'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$result = $stmt->execute();
|
||||||
|
$result = $stmt->fetchColumn();
|
||||||
|
if(!$result){
|
||||||
|
// check for result_AnalytsName
|
||||||
|
$query = "SELECT idcompoundsvocabulary FROM compundsvocabulary WHERE namecompoundsvocabulary LIKE '$result_AnalytsName'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$result = $stmt->execute();
|
||||||
|
$result = $stmt->fetchColumn();
|
||||||
|
if(!$result){
|
||||||
|
// add 0 to compounds array
|
||||||
|
array_push($compounds, 0);
|
||||||
|
}else{
|
||||||
|
// add 1 to compounds array
|
||||||
|
array_push($compounds, 1);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// add 1 to compounds array
|
||||||
|
array_push($compounds, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate lab reference
|
// Validate lab reference
|
||||||
$labId = getLaboratoryId($data['reflab'], $pdo);
|
$labId = getLaboratoryId($data['reflab'], $pdo);
|
||||||
@ -30,31 +109,77 @@ foreach ($jsonEntries as $entry) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate and insert product
|
if(validateJson($data) && !in_array(0, $analysis) && !in_array(0, $compounds)){
|
||||||
$productId = insertProduct($data['product'], $pdo, $uuid);
|
// Validate and insert product
|
||||||
|
$productId = insertProduct($data['product'], $pdo, $uuid);
|
||||||
if ($productId && validateJson($data)) {
|
|
||||||
// Insert reports, parts, analyses, and results
|
if ($productId) {
|
||||||
foreach ($data['product']['reports'] as $report) {
|
// Insert reports, parts, analyses, and results
|
||||||
$reportId = insertReport($report, $productId, $labId, $pdo, $uuid);
|
foreach ($data['product']['reports'] as $report) {
|
||||||
|
$reportId = insertReport($report, $productId, $labId, $pdo, $uuid);
|
||||||
foreach ($report['parts'] as $part) {
|
|
||||||
$partId = insertPart($part, $reportId, $productId, $pdo, $uuid);
|
foreach ($report['parts'] as $part) {
|
||||||
|
$partId = insertPart($part, $reportId, $productId, $pdo, $uuid);
|
||||||
foreach ($part['analyses'] as $analysis) {
|
|
||||||
$analysisId = insertAnalysis($analysis, $partId, $productId, $reportId, $pdo, $uuid);
|
foreach ($part['analyses'] as $analysis) {
|
||||||
|
$result_TestName = $analysis['result_TestName'];
|
||||||
foreach ($analysis['results'] as $result) {
|
$groupcode = $analysis['analysisgroupcode'];
|
||||||
insertResult($result, $analysisId, $partId, $productId, $reportId, $pdo, $uuid);
|
|
||||||
|
$query = "SELECT idanalysisvocabulary FROM analysisvocabulary WHERE analysiscode LIKE '$groupcode'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$res = $stmt->execute();
|
||||||
|
$res = $stmt->fetchColumn();
|
||||||
|
if($res){
|
||||||
|
$analysisCodeId = $res;
|
||||||
|
}else{
|
||||||
|
$query = "SELECT idanalysisvocabulary FROM analysisvocabulary WHERE nameanalysisvoc LIKE '$result_TestName'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$res = $stmt->execute();
|
||||||
|
$res = $stmt->fetchColumn();
|
||||||
|
if($res){
|
||||||
|
$analysisCodeId = $res;
|
||||||
|
}else{
|
||||||
|
$analysisCodeId = 'NO ANALYSIS ID FOUND';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$analysisId = insertAnalysis($analysis, $partId, $productId, $reportId, $pdo, $uuid, $analysisCodeId);
|
||||||
|
|
||||||
|
foreach ($analysis['results'] as $result) {
|
||||||
|
$result_AnalytsName = $result['result_AnalytsName'];
|
||||||
|
$cas = $result['cas'];
|
||||||
|
|
||||||
|
$query = "SELECT idcompoundsvocabulary FROM compundsvocabulary WHERE cascompoundvocabulary LIKE '%$cas%'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$res = $stmt->execute();
|
||||||
|
$res = $stmt->fetchColumn();
|
||||||
|
if($res){
|
||||||
|
$compoundId = $res;
|
||||||
|
}else{
|
||||||
|
$query = "SELECT idcompoundsvocabulary FROM compundsvocabulary WHERE namecompoundsvocabulary LIKE '$result_AnalytsName'";
|
||||||
|
$stmt = $pdo->prepare($query);
|
||||||
|
$res = $stmt->execute();
|
||||||
|
$res = $stmt->fetchColumn();
|
||||||
|
if($res){
|
||||||
|
$compoundId = $res;
|
||||||
|
}else{
|
||||||
|
$compoundId = 'NO COMPOUND ID FOUND';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insertResult($result, $analysisId, $partId, $productId, $reportId, $pdo, $uuid, $compoundId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markAsProcessed($entry['id'], $pdo);
|
||||||
|
} else {
|
||||||
|
markForIntervention($entry['id'], $pdo);
|
||||||
}
|
}
|
||||||
|
|
||||||
markAsProcessed($entry['id'], $pdo);
|
|
||||||
} else {
|
} else {
|
||||||
markForIntervention($entry['id'], $pdo);
|
markForIntervention($entry['id'], $pdo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function definitions
|
// Function definitions
|
||||||
@ -187,7 +312,7 @@ function insertPart($part, $reportId,$productId, $pdo, $uuid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function insertAnalysis($analysis, $partId, $productId, $reportId, $pdo, $uuid) {
|
function insertAnalysis($analysis, $partId, $productId, $reportId, $pdo, $uuid, $analysisCodeId) {
|
||||||
$query = "INSERT INTO analysis_project (result_TestName, test_Rating, test_Rating2, requirements, reference, analysisgroupcode, idpart, idproducts, idreports, importcode)
|
$query = "INSERT INTO analysis_project (result_TestName, test_Rating, test_Rating2, requirements, reference, analysisgroupcode, idpart, idproducts, idreports, importcode)
|
||||||
VALUES (:result_TestName, :test_Rating, :test_Rating2, :requirements, :reference, :analysisgroupcode, :idpart , :idproducts, :idreports, :importcode)";
|
VALUES (:result_TestName, :test_Rating, :test_Rating2, :requirements, :reference, :analysisgroupcode, :idpart , :idproducts, :idreports, :importcode)";
|
||||||
|
|
||||||
@ -195,7 +320,7 @@ function insertAnalysis($analysis, $partId, $productId, $reportId, $pdo, $uuid)
|
|||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
'idproducts' => $productId,
|
'idproducts' => $productId,
|
||||||
'idreports' => $reportId,
|
'idreports' => $reportId,
|
||||||
'result_TestName' => $analysis['result_TestName'],
|
'result_TestName' => $analysisCodeId,
|
||||||
'test_Rating' => $analysis['test_Rating'],
|
'test_Rating' => $analysis['test_Rating'],
|
||||||
'test_Rating2' => $analysis['test_Rating2'],
|
'test_Rating2' => $analysis['test_Rating2'],
|
||||||
'requirements' => $analysis['requirements'],
|
'requirements' => $analysis['requirements'],
|
||||||
@ -207,13 +332,13 @@ function insertAnalysis($analysis, $partId, $productId, $reportId, $pdo, $uuid)
|
|||||||
return $pdo->lastInsertId();
|
return $pdo->lastInsertId();
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertResult($result, $analysisId, $partId, $productId, $reportId, $pdo, $uuid) {
|
function insertResult($result, $analysisId, $partId, $productId, $reportId, $pdo, $uuid, $compoundId) {
|
||||||
$query = "INSERT INTO result_project (result_AnalytsName, result_AnalytsRating, result_Value, result_Comment, test_Rating, test_Rating2, result_UnitofMeasure, cas, requirements, reference, idanalysis_project, idpart, idproducts, idreports, importcode)
|
$query = "INSERT INTO result_project (result_AnalytsName, result_AnalytsRating, result_Value, result_Comment, test_Rating, test_Rating2, result_UnitofMeasure, cas, requirements, reference, idanalysis_project, idpart, idproducts, idreports, importcode)
|
||||||
VALUES (:result_AnalytsName, :result_AnalytsRating, :result_Value, :result_Comment, :test_Rating, :test_Rating2, :result_UnitofMeasure, :cas, :requirements, :reference, :idanalysis_project, :idpart, :idproducts, :idreports, :importcode)";
|
VALUES (:result_AnalytsName, :result_AnalytsRating, :result_Value, :result_Comment, :test_Rating, :test_Rating2, :result_UnitofMeasure, :cas, :requirements, :reference, :idanalysis_project, :idpart, :idproducts, :idreports, :importcode)";
|
||||||
|
|
||||||
$stmt = $pdo->prepare($query);
|
$stmt = $pdo->prepare($query);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
'result_AnalytsName' => $result['result_AnalytsName'],
|
'result_AnalytsName' => $compoundId,
|
||||||
'result_AnalytsRating' => $result['result_AnalytsRating'],
|
'result_AnalytsRating' => $result['result_AnalytsRating'],
|
||||||
'result_Value' => $result['result_Value'],
|
'result_Value' => $result['result_Value'],
|
||||||
'result_Comment' => $result['result_Comment'],
|
'result_Comment' => $result['result_Comment'],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user