| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820 |
- <?php
- namespace Models {
- require_once 'Models/User.class.php';
-
- require_once 'Tools/Crypto.class.php';
-
- class AdminInterface {
- //
- protected $DataInterface;
- /**
- *
- */
- public function __construct($DataInterface) {
- $this->DataInterface = $DataInterface;
- }
- /**
- * Check login/password and create JWT token.
- */
- public function adminLogin(&$User, $email, $clearPassword) {
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT
- ID, password, firstname, lastname
- FROM
- user
- WHERE
- active = 1 AND
- email = '$email' AND
- type = 'imt-master'"
- );
- if(!$statement->execute()) {
- $results = Array('result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo());
- }
- else {
- $results = $statement->fetchAll(\PDO::FETCH_ASSOC);
- if(count($results)){
- if(\Tools\Crypto::verify($clearPassword, $results[0]['password'])) {
- // Generate JWT token
- $issuer_claim = \Config\Settings::getTokenIssuer();
- $audience_claim = \Config\Settings::getAdminTokenAudience();
- $issuedat_claim = time(); // issued at
- $notbefore_claim = $issuedat_claim + \Config\Settings::getTokenNotBefore();
- $expire_claim = $issuedat_claim + \Config\Settings::getTokenExpiration();
- $token = array(
- "iss" => $issuer_claim,
- "aud" => $audience_claim,
- "iat" => $issuedat_claim,
- "nbf" => $notbefore_claim,
- "exp" => $expire_claim,
- "data" => array(
- "ID" => $results[0]['ID'],
- "firstname" => $results[0]['firstname'],
- "lastname" => $results[0]['lastname'],
- "email" => $email
- )
- );
- $jwt = \Firebase\JWT\JWT::encode($token, \Config\Settings::getTokenPrivateKey());
- // OK
- $results = Array(
- "result" => "OK",
- "token" => $jwt,
- "email" => $email,
- "expireAt" => $expire_claim
- );
- }
- else {
- $results = Array('result' => 'ERROR', 'reason' => 'bad_password', 'message' => 'Invalid password');
- }
- }
- else {
- $results = Array('result' => 'ERROR', 'reason' => 'unknown', 'message' => 'No such user');
- }
- }
- return $results;
- }
- /**
- * Logout.
- */
- public function adminLogout(&$User) {
- $User->logout();
- return Array('result' => 'OK');
- }
- /**
- * Get profile data.
- */
- public function adminProfileGet($User) {
- $userID = $User->ID;
-
- // OK
- return array(
- 'result' => 'OK',
- 'ID' => $User->ID,
- 'firstname' => $User->firstname,
- 'lastname' => $User->lastname,
- 'email' => $User->email
- );
- }
- /**
- * Get common data.
- */
- public function adminCommonGet($User) {
- $userID = $User->ID;
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT data FROM settings"
- );
- if(!$statement->execute()) {
- $results = Array('result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo());
- }
- $settings = json_decode($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['data'], JSON_NUMERIC_CHECK);
-
- // OK
- return array(
- 'result' => 'OK',
- 'ID' => $User->ID,
- 'firstname' => $User->firstname,
- 'lastname' => $User->lastname,
- 'email' => $User->email,
- 'settings' => $settings
- );
- }
- /**
- * Get export data.
- */
- public function adminExportGet($User) {
- $userID = $User->ID;
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM user WHERE type = 'physician'"
- );
- if(!$statement->execute()) {
- $results = Array('result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo());
- }
- $users = $statement->fetchAll(\PDO::FETCH_ASSOC);
-
- // OK
- return array(
- 'result' => 'OK',
- 'users' => $users,
- );
- }
- /**
- * Post export data.
- */
- public function adminExportPost($User, $data) {
- $userID = $User->ID;
- return $this->exportByID($data['ID']);
- }
- public function exportByID($ID) {
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM user WHERE ID = $ID"
- );
- if(!$statement->execute()) {
- $results = Array('result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo());
- }
- $user = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- $prefix = date('Y-m-d').'_'.str_replace([' ','\''], '_', $user['firstname'].'_'.$user['lastname']);
- $od = '../../storage/tmp/'.$prefix.'_'.$ID.'/';
- \Tools\FS::mkpath($od);
- $data = [];
- // header
- $data[] =
- 'Visit_PatientID,Visit_Date,Visit_Created,Visit_Area,'.
- 'Media_Location,Media_Incidence,Media_Filename,Media_Width,Media_Height,Media_PixelWidth,Media_PixelHeight,Media_FrameCount,Media_FramePerSecond,'.
- 'Measure_Created,Measure_Frame,Measure_Distance,Measure_ImtMean,Measure_ImtMax,Measure_ImtStddev,Measure_IntimaMean,Measure_MediaMean,Measure_NearWall,Measure_QualityIndex,Measure_NumberOfPoints';
- // visit
- $statement = $this->DataInterface->DatabaseConnection->prepare("
- SELECT patient.patientID, visit.*
- FROM patient, visit
- WHERE patient.ID = visit.fk_patient
- AND visit.area = 'carotid'
- AND patient.fk_user = $ID
- ");
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $visits = $statement->fetchAll(\PDO::FETCH_ASSOC);
- foreach($visits as $visit) {
- $fk_visit = $visit['ID'];
- // media
- $statement = $this->DataInterface->DatabaseConnection->prepare("
- SELECT media.*
- FROM media
- WHERE fk_visit = $fk_visit
- ");
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $medias = $statement->fetchAll(\PDO::FETCH_ASSOC);
- foreach($medias as $media) {
- $fk_media = $media['ID'];
- // measure
- $statement = $this->DataInterface->DatabaseConnection->prepare("
- SELECT measure.*
- FROM measure
- WHERE fk_media = $fk_media
- AND type = 'imt'
- ");
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $measures = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // save file
- if(count($measures)) {
- copy('../../storage/media/'.$visit['ID'].'/'.$media['filename'], $od.'/'.$media['filename']);
- }
-
- foreach($measures as $measure) {
- $V['Visit_PatientID'] = $visit['patientID'];
- $V['Visit_Date'] = $visit['visitDate'];
- $V['Visit_Created'] = $visit['created'];
- $V['Visit_Area'] = $visit['area'];
- $V['Media_Location'] = $media['location'];
- $V['Media_Incidence'] = $media['incidence'];
- $V['Media_Filename'] = $media['filename'];
- $metrics = json_decode($media['metrics']);
- $V['Media_Width'] = $metrics->width;
- $V['Media_Height'] = $metrics->height;
- $V['Media_PixelWidth'] = $metrics->pxwidth;
- $V['Media_PixelHeight'] = $metrics->pxheight;
- $V['Media_FrameCount'] = $metrics->frameCount;
- $V['Media_FramePerSecond'] = $metrics->fps;
- $V['Measure_Created'] = $measure['created'];
- $V['Measure_Frame'] = $measure['frame'];
- $computation = json_decode($measure['computation']);
- $V['Measure_Distance'] = $computation->distance;
- $V['Measure_ImtMean'] = $computation->imt_mean;
- $V['Measure_ImtMax'] = $computation->imt_max;
- $V['Measure_ImtStddev'] = $computation->imt_stddev;
- $V['Measure_IntimaMean'] = $computation->intima_mean;
- $V['Measure_MediaMean'] = $computation->media_mean;
- $V['Measure_Location'] = $computation->nearWall?'Proximal':'Distal';
- $V['Measure_QualityIndex'] = $computation->qualityIndex;
- $V['Measure_NumberOfPoints'] = $computation->numberOfPoints;
-
- //$data[] = $V;
- $data[] = implode(",", $V);
- }
- }
- }
- unlink('../../storage/tmp/'.$prefix.'_'.$ID);
- // make archive
- $dst = '../../storage/tmp/'.$prefix.'_'.$ID.'.zip';
- unlink($dst);
- $cmdLine = 'cd ../../storage/tmp && zip -r '.$prefix.'_'.$ID.'.zip '.$prefix.'_'.$ID.'/ 2>&1';
- $output=null;
- $retval=null;
- exec($cmdLine, $output, $retval);
- // error
- if($retval !== 0 || count($output)<1) {
- return [
- 'result' => 'ERROR',
- 'cmdLine' => $cmdLine,
- 'output' => $output,
- 'retval' => $retval
- ];
- }
- // make csv
- unlink('../../storage/tmp/'.$prefix.'_'.$ID.'.csv');
- file_put_contents('../../storage/tmp/'.$prefix.'_'.$ID.'.csv', implode("\n", $data));
- // OK
- return array(
- 'result' => 'OK',
- 'ID' => $ID,
- 'data' => $data,
- 'csv' => 'tmp/'.$prefix.'_'.$ID.'.csv',
- 'zip' => 'tmp/'.$prefix.'_'.$ID.'.zip'
- );
- }
- /**
- * Post common data.
- */
- public function adminCommonPost($User, $data) {
- $userID = $User->ID;
- // update settings
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "UPDATE settings SET data = :data"
- );
- $data = json_encode($data['data'], JSON_NUMERIC_CHECK);
- $statement->bindParam(':data', $data);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- // OK
- return array(
- 'result' => 'OK',
- 'data' => $data
- );
- }
- /**
- *
- */
- public function adminCtParamsGet($User) {
- $userID = $User->ID;
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM clinical_trial"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $settings = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- $settings['comment'] = stripslashes($settings['comment']);
- // OK
- return array(
- 'result' => 'OK',
- 'settings' => $settings
- );
- }
- /**
- *
- */
- public function adminCtStatsGet($User) {
- $userID = $User->ID;
- // patients
- $statement = $this->DataInterface->DatabaseConnection->prepare("
- SELECT DATE_FORMAT(visit.created, '%Y-%m') AS m, COUNT(visit.ID) AS patients
- FROM visit, patient, user
- WHERE visit.fk_patient = patient.ID AND patient.fk_user = user.ID AND user.type = 'investigator'
- GROUP BY DATE_FORMAT(visit.created, '%Y-%m')
- ");
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $resPatients = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // measures
- $statement = $this->DataInterface->DatabaseConnection->prepare("
- SELECT DATE_FORMAT(measure.created, '%Y-%m') AS m, COUNT(measure.ID) AS measures
- FROM measure, user
- WHERE measure.fk_user = user.ID AND user.type = 'reader'
- GROUP BY DATE_FORMAT(measure.created, '%Y-%m')
- ");
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $resMeasures = $statement->fetchAll(\PDO::FETCH_ASSOC);
-
- $patients = [];
- $start = (new \DateTime($resPatients[0]['m'].'-01'))->modify('first day of this month');
- $end = (new \DateTime(date('Y-m-d')))->modify('first day of next month');
- $interval = \DateInterval::createFromDateString('1 month');
- $period = new \DatePeriod($start, $interval, $end);
- foreach($period as $dt) {
- $patients[] = array('m' => $dt->format("Y-m"), 'patients' => 0, 'measures' => 0);
- }
- foreach($resPatients as $R) {
- foreach($patients as &$P) {
- if($P['m'] == $R['m']) {
- $P['patients'] = intval($R['patients']);
- }
- }
- }
- foreach($resMeasures as $R) {
- foreach($patients as &$P) {
- if($P['m'] == $R['m']) {
- $P['measures'] = intval($R['measures']);
- }
- }
- }
- // OK
- return array(
- 'result' => 'OK',
- 'patients' => $patients
- );
- }
- /**
- *
- */
- public function adminPhyStatsGet($User) {
- $userID = $User->ID;
- // patients
- $statement = $this->DataInterface->DatabaseConnection->prepare("
- SELECT DATE_FORMAT(visit.created, '%Y-%m') AS m, COUNT(visit.ID) AS patients
- FROM visit, patient, user
- WHERE visit.fk_patient = patient.ID AND patient.fk_user = user.ID AND user.type = 'physician'
- GROUP BY DATE_FORMAT(visit.created, '%Y-%m')
- ");
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $resPatients = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // measures
- $statement = $this->DataInterface->DatabaseConnection->prepare("
- SELECT DATE_FORMAT(measure.created, '%Y-%m') AS m, COUNT(measure.ID) AS measures
- FROM measure, user
- WHERE measure.fk_user = user.ID AND user.type = 'physician'
- GROUP BY DATE_FORMAT(measure.created, '%Y-%m')
- ");
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $resMeasures = $statement->fetchAll(\PDO::FETCH_ASSOC);
-
- $patients = [];
- $start = (new \DateTime($resPatients[0]['m'].'-01'))->modify('first day of this month');
- $end = (new \DateTime(date('Y-m-d')))->modify('first day of next month');
- $interval = \DateInterval::createFromDateString('1 month');
- $period = new \DatePeriod($start, $interval, $end);
- foreach($period as $dt) {
- $patients[] = array('m' => $dt->format("Y-m"), 'patients' => 0, 'measures' => 0);
- }
- foreach($resPatients as $R) {
- foreach($patients as &$P) {
- if($P['m'] == $R['m']) {
- $P['patients'] = intval($R['patients']);
- }
- }
- }
- foreach($resMeasures as $R) {
- foreach($patients as &$P) {
- if($P['m'] == $R['m']) {
- $P['measures'] = intval($R['measures']);
- }
- }
- }
- // OK
- return array(
- 'result' => 'OK',
- 'patients' => $patients
- );
- }
- /**
- *
- */
- public function adminCtUsersGet($User) {
- $userID = $User->ID;
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT COUNT(ID) AS cnt FROM user WHERE type = 'cro'"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $admin = $statement->fetchAll(\PDO::FETCH_ASSOC)[0]['cnt'];
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT COUNT(ID) AS cnt FROM user WHERE type = 'investigator'"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $investigator = $statement->fetchAll(\PDO::FETCH_ASSOC)[0]['cnt'];
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT COUNT(ID) AS cnt FROM user WHERE type = 'reader'"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $reader = $statement->fetchAll(\PDO::FETCH_ASSOC)[0]['cnt'];
- // OK
- return array(
- 'result' => 'OK',
- 'data' => [
- 'admin' => $admin,
- 'investigator' => $investigator,
- 'reader' => $reader
- ]
- );
- }
- /**
- *
- */
- public function adminCreditGet($User, $ID) {
- $userID = $User->ID;
- // total purchased credits
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT SUM(count) AS purchased FROM credit WHERE ID_user = :fk_user"
- );
- $statement->bindParam(':fk_user', $ID);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $purchased = intval($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['purchased']);
- // total used credits
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT COUNT(ID) AS used FROM credit_usage WHERE fk_user = :fk_user"
- );
- $statement->bindParam(':fk_user', $ID);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $used = intval($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['used']);
- // credit
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM credit WHERE ID_user = $ID ORDER BY stamp DESC"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $credit = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // OK
- return array(
- 'result' => 'OK',
- 'credit' => $credit,
- 'purchased' => $purchased,
- 'used' => $used
- );
- }
- /**
- *
- */
- public function adminCreditPost($User, $data) {
- $userID = $User->ID;
- $customerID = $data['ID'];
- $count = $data['count'];
- // credit
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "INSERT INTO credit(ID_user, count) VALUES($customerID, $count)"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- // OK
- return array(
- 'result' => 'OK',
- 'credit' => $credit
- );
- }
- /**
- *
- */
- public function adminCustomerGet($User, $who) {
- $userID = $User->ID;
- if($who=='physician') {
- // customers
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT ID, firstname, lastname, email FROM user WHERE type = 'physician' ORDER BY lastname, firstname"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $customer = $statement->fetchAll(\PDO::FETCH_ASSOC);
- }
- else {
- // customers
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM user WHERE type = 'cro' ORDER BY ID LIMIT 0,1"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $customer = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // clinical trial
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT max_readers, max_investigators FROM clinical_trial"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $res = $statement->fetchAll(\PDO::FETCH_ASSOC);
- if(count($res)) {
- $customer[0]['max_readers'] = $res[0]['max_readers'];
- $customer[0]['max_investigators'] = $res[0]['max_investigators'];
- }
- else {
- $customer[0]['max_readers'] = 1;
- $customer[0]['max_investigators'] = 1;
- }
- $credits = $this->adminCreditGet($User, $customer[0]['ID']);
- if($credits['result'] == 'ERROR') {
- return $credits;
- }
- $customer[0]['credits'] = $credits;
- }
- // OK
- return array(
- 'result' => 'OK',
- 'who' => $who,
- 'customer' => $customer
- );
- }
- /**
- * Get pacs data.
- */
- public function adminPacsGet($User) {
- $userID = $User->ID;
- // customers
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT ID AS physicianID, firstname, lastname, email FROM user WHERE type = 'physician' ORDER BY lastname, firstname"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $customer = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // pacs
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM settings_pacs WHERE fk_physician IS NOT NULL AND fk_center IS NULL ORDER BY fk_physician"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $pacs = $statement->fetchAll(\PDO::FETCH_ASSOC);
- foreach($pacs as &$p) {
- $p['data'] = json_decode($p['data']);
- }
- // OK
- return array(
- 'result' => 'OK',
- 'ourAET' => 'IIMT',
- 'customer' => $customer,
- 'pacs' => $pacs
- );
- }
-
- /**
- * Post pacs data.
- */
- public function adminPacsPost($User, $data) {
- $userID = $User->ID;
- $fk_physician = $data['data']['physicianID'];
- // insert
- if(intval($data['data']['PACSID'])==0) {
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "INSERT INTO settings_pacs VALUES(0, :data, :fk_physician, NULL)"
- );
- unset($data['data']['PACSID']);
- $data = json_encode($data['data'], JSON_NUMERIC_CHECK);
- $statement->bindParam(':data', $data);
- $statement->bindParam(':fk_physician', $fk_physician);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- }
- // update
- else {
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "UPDATE settings_pacs SET data=:data, fk_physician=:fk_physician WHERE ID = ".$data['data']['PACSID']
- );
- unset($data['data']['PACSID']);
- $data = json_encode($data['data'], JSON_NUMERIC_CHECK);
- $statement->bindParam(':data', $data);
- $statement->bindParam(':fk_physician', $fk_physician);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- }
- // OK
- return array(
- 'result' => 'OK',
- 'data' => $data
- );
- }
- /**
- *
- */
- public function adminEchoPost($User, $data) {
- $cmdLine = 'echoscu '.$data['serverAddress'].' '.$data['queryPort'].' -v 2>&1';
- $output=null;
- $retval=null;
- exec($cmdLine, $output, $retval);
- if($retval !== 0 || count($output)<1) {
- return [
- 'result' => 'ERROR',
- 'cmdLine' => $cmdLine,
- 'output' => $output,
- 'retval' => $retval
- ];
- }
- return [
- 'result' => 'OK',
- 'output' => $output
- ];
- }
- /**
- * Post customer data : ct only
- */
- public function adminCustomerPost($User, $data) {
- $userID = $User->ID;
- // Select
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT ID, email, password FROM user WHERE type = 'cro' ORDER BY ID LIMIT 0, 1"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $knownData = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- $fk_user = $knownData['ID'];
- $password = $knownData['password'];
- $newUser = 0;
- if($knownData['email']!=$data['user']['email']) {
- $password = \Tools\UUID::v4();
- $newUser = 1;
- }
- // Update
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "UPDATE user SET firstname = :firstname, lastname = :lastname, password = :password, email = :email, phone = :phone WHERE ID = :ID"
- );
- $statement->bindParam(':firstname', $data['user']['firstname']);
- $statement->bindParam(':lastname', $data['user']['lastname']);
- $statement->bindParam(':password', $password);
- $statement->bindParam(':email', $data['user']['email']);
- $statement->bindParam(':phone', $data['user']['phone']);
- $statement->bindParam(':ID', $fk_user);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- /*
- // Insert user
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "INSERT INTO user(activation_token, activation_expire, password, firstname, lastname, email, phone, type) VALUES(:activation_token, :activation_expire, :password, :firstname, :lastname, :email, :phone, 'cro')"
- );
- $activation_token = \Tools\UUID::v4();
- $activation_expire = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s'). ' + 1 days'));
- $statement->bindParam(':activation_token', $activation_token);
- $statement->bindParam(':activation_expire', $activation_expire);
- $password = \Tools\Crypto::getHashPassword('SUPER_SECURE_DEFAULT_PASSWORD');
- $statement->bindParam(':password', $password);
- $statement->bindParam(':firstname', $data['user']['firstname']);
- $statement->bindParam(':lastname', $data['user']['lastname']);
- $statement->bindParam(':email', $data['user']['email']);
- $statement->bindParam(':phone', $data['user']['phone']);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $fk_user = $this->DataInterface->DatabaseConnection->lastInsertId();
- */
- // OK
- return [
- 'result' => 'OK',
- 'data' => $data,
- 'emailTo' => $data['user']['email'],
- 'emailFrom' => $User->email,
- 'password_token' => $password,
- 'newUser' => $newUser
- ];
- }
- }
- }
|