| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063 |
- <?php
- namespace Models {
- require_once 'Models/User.class.php';
- require_once 'Tools/Random.class.php';
- require_once 'Tools/FS.class.php';
- require_once 'Tools/UUID.class.php';
- require_once 'External/dompdf_0-8-6/autoload.inc.php';
- require_once 'External/ImageWorkshop/vendor/autoload.php';
- require_once 'External/ImageWorkshop/src/ImageWorkshop.php';
- use PHPImageWorkshop\ImageWorkshop;
-
- class ReportInterface {
- //
- protected $DataInterface;
- /**
- *
- */
- public function __construct($DataInterface) {
- $this->DataInterface = $DataInterface;
- }
-
- /**
- * Get media
- */
- public function reportGet($User, $patientID, $visitID) {
- $userID = $User->ID;
- // patient
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT patient.* FROM patient WHERE ID = :fk_patient"
- );
- $statement->bindParam(':fk_patient', $patientID);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $patient = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- // visit
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT area, markers FROM visit WHERE ID = :fk_visit"
- );
- $statement->bindParam(':fk_visit', $visitID);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $data = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- // media
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM media WHERE fk_visit = :fk_visit"
- );
- $statement->bindParam(':fk_visit', $visitID);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $media = $statement->fetchAll(\PDO::FETCH_ASSOC);
- foreach($media as &$m) {
- $m['metrics'] = json_decode($m['metrics']);
- // measures
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM measure WHERE fk_media = :fk_media"
- );
- $statement->bindParam(':fk_media', $m['ID']);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $m['measure'] = $statement->fetchAll(\PDO::FETCH_ASSOC);
- foreach($m['measure'] as &$measure) {
- $measure['points'] = json_decode($measure['points']);
- $measure['computation'] = json_decode($measure['computation']);
- }
- }
- // Abacus
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT DISTINCT name FROM abacus ORDER BY name"
- );
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $abacus = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // Recipient
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM recipient WHERE fk_user = :fk_user ORDER BY email"
- );
- $statement->bindParam(':fk_user', $userID);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $recipient = $statement->fetchAll(\PDO::FETCH_ASSOC);
- // PACS
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT data FROM settings_pacs WHERE fk_physician = $userID"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $pacs = json_decode($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['data']);
- return [
- 'result' => 'OK',
- 'patient' => $patient,
- 'area' => $data['area'],
- 'markers' => json_decode($data['markers']),
- 'media' => $media,
- 'recipient' => $recipient,
- 'pacs' => $pacs,
- 'abacus' => $abacus
- ];
- }
- /**
- *
- */
- public function reportMailAddPost($User, $data) {
- $userID = $User->ID;
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "INSERT INTO recipient(ID, email, fk_user) VALUES(0, :email, :fk_user)"
- );
- $statement->bindParam(':email', $data['email']);
- $statement->bindParam(':fk_user', $userID);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $emailID = $this->DataInterface->DatabaseConnection->lastInsertId();
- return [
- 'result' => 'OK',
- 'ID' => $emailID
- ];
- }
- /**
- *
- */
- public function reportMailDeletePost($User, $data) {
- $userID = $User->ID;
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "DELETE FROM recipient WHERE ID = :ID"
- );
- $statement->bindParam(':ID', $data['ID']);
- // Error check
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- return [
- 'result' => 'OK'
- ];
- }
- /**
- *
- */
- protected function generateMeasureText($lang, &$measureList, $M, &$imt_value, &$imt_count) {
- if($M['type']=='imt') {
- $measureList[] =
- ($this->tr($lang, 'imt_avg').': '.number_format($M['computation']->imt_mean, 3)).' mm, '.
- ($this->tr($lang, 'imt_max').': '.number_format($M['computation']->imt_max, 3)).' mm';
- $imt_value+=$M['computation']->imt_mean;
- $imt_count++;
- }
- else if($M['type']=='plaque') {
- $measureList[] =
- ($this->tr($lang, 'plaque').': '.round($M['computation']->plaque_area*100)/100).' mm², '.
- ($this->tr($lang, 'thk_max').': '.round($M['computation']->plaque_max_thickness*10)/10).' mm';
- }
- else if($M['type']=='area') {
- $measureList[] = ($this->tr($lang, 'surface').': '.round($M['computation']->surface*100)/100).' mm²';
- }
- else if($M['type']=='thickness') {
- $measureList[] = ($this->tr($lang, 'thk').': '.round($M['computation']->distance*10)/10).' mm';
- }
- else if($M['type']=='plaque_thickness') {
- $measureList[] = ($this->tr($lang, 'thk_plaque').': '.round($M['computation']->distance*10)/10).' mm';
- }
- else if($M['type']=='diameter') {
- $measureList[] = ($this->tr($lang, 'diameter').': '.round($M['computation']->distance*10)/10).' mm';
- }
- }
- /**
- *
- */
- protected function generateImageCell($lang, $side, $visit, $visitID, $markers, $media, $ID, &$imt_value, &$imt_count, $mode) {
- $M = null;
- for($i=0; $i<count($media); $i++) {
- if($media[$i]['ID'] == $ID) {
- $M = $media[$i];
- break;
- }
- }
- $span = count($media)==2?3:4;
- if(!$M) {
- return '<tr><td colspan="'.$span.'" style="height: 16px;">not found</td></tr>';
- }
- // segment
- $incidence = array_key_exists('incidence', $M)?(' ('.$this->tr($lang, $M['incidence']).')'):'';
- $segmentName = $this->tr($lang, $visit['area'].'_'.$side.'_'.$M['location']).' '.$incidence;
- $segmentImage = '../../storage/area/area_'.$visit['area'].'_'.($side=='right'?'R':'L').'_'.$M['location'].'.png';
- $segmentLayer = ImageWorkshop::initFromPath($segmentImage);
- for($mk=0; $mk<count($visit['markers']); $mk++) {
- if($visit['markers'][$mk]->location==$side) {
- $segmentLayer->addLayerOnTop($markers[$visit['markers'][$mk]->type], $visit['markers'][$mk]->x, $visit['markers'][$mk]->y);
- }
- }
- ob_start();
- imagejpeg($segmentLayer->getResult(), null, 100);
- $segmentBase64 = ob_get_contents();
- ob_end_clean();
- $segmentBase64 = 'data:image/jpeg;base64,'.base64_encode($segmentBase64);
- // image
- $frame = 0;
- for($measure=0; $measure<count($M['measure']); $measure++) {
- $mm = $M['measure'][$measure];
- if($mm['type'] != 'calibration') {
- $frame = $mm['frame'];
- break;
- }
- }
- $path = '../../storage/media/'.$visitID.'/'.$M['filename'];
- $path_parts = pathinfo($path);
- if(property_exists($M['metrics'], 'fps')) {
- $path = $path_parts['dirname'].'/'.$path_parts['filename'].'-'.$frame.'.jpeg';
- }
- else {
- $path = $path_parts['dirname'].'/'.$path_parts['filename'].'.jpeg';
- }
- // draw measures
- $mImage = imagecreatefromjpeg($path);
- $orange = imagecolorallocate($mImage, 255,165,0);
- $green = imagecolorallocate($mImage, 0, 255, 0);
- imagesetthickness($mImage, 2);
- foreach($M['measure'] as $Mm) {
- if($Mm['type']=='imt') {
- for($p=0; $p<count($Mm['computation']->vect_adventitia); $p++) {
- imageline($mImage, $Mm['computation']->vect_adventitia[$p]->x, $Mm['computation']->vect_adventitia[$p]->y, $Mm['computation']->vect_adventitia[$p]->x+1, $Mm['computation']->vect_adventitia[$p]->y, $green);
- }
- for($p=0; $p<count($Mm['computation']->vect_intima); $p++) {
- imageline($mImage, $Mm['computation']->vect_intima[$p]->x, $Mm['computation']->vect_intima[$p]->y, $Mm['computation']->vect_intima[$p]->x+1, $Mm['computation']->vect_intima[$p]->y, $orange);
- }
- }
- else if($Mm['type']=='plaque') {
- for($p=0; $p<count($Mm['computation']->longeantPlaque)-1; $p++) {
- imageline($mImage, $Mm['computation']->longeantPlaque[$p]->x, $Mm['computation']->longeantPlaque[$p]->y, $Mm['computation']->longeantPlaque[$p+1]->x, $Mm['computation']->longeantPlaque[$p+1]->y, $orange);
- }
- for($p=0; $p<count($Mm['computation']->ptsTrouvesFin)-1; $p++) {
- imageline($mImage, $Mm['computation']->ptsTrouvesFin[$p]->x, $Mm['computation']->ptsTrouvesFin[$p]->y, $Mm['computation']->ptsTrouvesFin[$p+1]->x, $Mm['computation']->ptsTrouvesFin[$p+1]->y, $green);
- }
- imageline($mImage, $Mm['computation']->longeantPlaque[0]->x, $Mm['computation']->longeantPlaque[0]->y, $Mm['computation']->ptsTrouvesFin[0]->x, $Mm['computation']->ptsTrouvesFin[0]->y, $green);
- imageline($mImage, $Mm['computation']->longeantPlaque[count($Mm['computation']->longeantPlaque)-1]->x, $Mm['computation']->longeantPlaque[count($Mm['computation']->longeantPlaque)-1]->y, $Mm['computation']->ptsTrouvesFin[count($Mm['computation']->ptsTrouvesFin)-1]->x, $Mm['computation']->ptsTrouvesFin[count($Mm['computation']->ptsTrouvesFin)-1]->y, $green);
- }
- else if($Mm['type']=='area') {
- for($p=0; $p<count($Mm['points'])-1; $p++) {
- imageline($mImage, $Mm['points'][$p]->x, $Mm['points'][$p]->y, $Mm['points'][$p+1]->x, $Mm['points'][$p+1]->y, $green);
- }
- imageline($mImage, $Mm['points'][0]->x, $Mm['points'][0]->y, $Mm['points'][count($Mm['points'])-1]->x, $Mm['points'][count($Mm['points'])-1]->y, $green);
- for($p=0; $p<count($Mm['points'])-1; $p++) {
- imagefilledellipse($mImage, $Mm['points'][$p]->x, $Mm['points'][$p]->y, 10, 10, $orange);
- }
- }
- else if($Mm['type']=='diameter' || $Mm['type']=='thickness' || $Mm['type']=='plaque_thickness') {
- imageline($mImage, $Mm['points'][0]->x, $Mm['points'][0]->y, $Mm['points'][1]->x, $Mm['points'][1]->y, $green);
- imageline($mImage, $Mm['points'][0]->x, $Mm['points'][0]->y, $Mm['points'][1]->x, $Mm['points'][1]->y, $green);
- imagefilledellipse($mImage, $Mm['points'][0]->x, $Mm['points'][0]->y, 10, 10, $orange);
- imagefilledellipse($mImage, $Mm['points'][1]->x, $Mm['points'][1]->y, 10, 10, $orange);
- }
- }
- ob_start();
- imagejpeg($mImage);
- $imageData = ob_get_contents();
- ob_end_clean();
- $imageBase64 = 'data:image/jpeg;base64,'.base64_encode($imageData);
- imagedestroy($mImage);
- //$imageBase64 = 'data:image/' . pathinfo(parse_url($path, PHP_URL_PATH), PATHINFO_EXTENSION) . ';base64,' . base64_encode(file_get_contents($path));
- // measures
- $measureList = [];
- foreach($M['measure'] as $Mm) {
- if($frame==intval($Mm['frame']) && $Mm['type']!='calibration') {
- $this->generateMeasureText($lang, $measureList, $Mm, $imt_value, $imt_count);
- }
- }
- // layout
- if($mode == '2R') {
- return '<tr><td colspan="'.$span.'" style="height: 16px;"></td></tr>'.
- '<tr>'.
- '<td style="width: 20%" valign="top"><img src="'.$segmentBase64.'" style="width: 100%;" /></td>'.
- '<td style="width: 60%" align="center">'.
- '<img src="'.$imageBase64.'" style="width: 90%;" /><div style="width: 100%; text-align: center;"><b>'.$segmentName.'</b><br/>'.implode('<br/>',$measureList).'</div>'.
- '</td>'.
- '<td style="width: 20%; text-align: center;"><h3>'.$this->tr($lang, $side).'</h3></td>'.
- '</tr>';
- }
- if($mode == '2L') {
- return '<tr><td colspan="'.$span.'" style="height: 16px;"></td></tr>'.
- '<tr>'.
- '<td style="width: 20%; text-align: center;"><h3>'.$this->tr($lang, $side).'</h3></td>'.
- '<td style="width: 60%" align="center">'.
- '<img src="'.$imageBase64.'" style="width: 90%;" /><div style="width: 100%; text-align: center;"><b>'.$segmentName.'</b><br/>'.implode('<br/>',$measureList).'</div>'.
- '</td>'.
- '<td style="width: 20%" valign="top"><img src="'.$segmentBase64.'" style="width: 100%;" /></td>'.
- '</tr>';
- }
- if($mode == '6R') {
- return '<td style="width: 15%" valign="top"><img src="'.$segmentBase64.'" style="width: 100%;" /></td>'.
- '<td style="width: 35%" valign="top">'.
- '<img src="'.$imageBase64.'" style="width: 100%;" /><div style="width: 100%; text-align: center;"><b>'.$segmentName.'</b><br/>'.implode('<br/>',$measureList).'</div>'.
- '</td>';
- }
- if($mode == '6L') {
- return '<td style="width: 35%" valign="top">'.
- '<img src="'.$imageBase64.'" style="width: 100%;" /><div style="width: 100%; text-align: center;"><b>'.$segmentName.'</b><br/>'.implode('<br/>',$measureList).'</div>'.
- '</td>'.
- '<td style="width: 15%" valign="top"><img src="'.$segmentBase64.'" style="width: 100%;" /></td>';
- }
- }
- /**
- *
- */
- public function reportPdfMailPost($User, $data) {
- $userID = $User->ID;
- // report
- $res = $this->reportPdfDownloadPost($User, $data);
- if($res['result']=='ERROR') {
- return $res;
- }
- foreach($data['emails'] as $email) {
- $res = $this->DataInterface->sendMail($User->email, $email, $data['subject'], $data['message'], '../../storage/report/'.$res['filename']);
- if($res['result']=='ERROR') {
- return $res;
- }
- }
- return [
- 'result' => 'OK',
- 'report' => $res
- ];
- }
-
- /**
- *
- */
- public function reportPdfPACSPost($User, $data) {
- $userID = $User->ID;
- // report
- $res = $this->reportPdfDownloadPost($User, $data);
- if($res['result']=='ERROR') {
- return $res;
- }
- $reportPath = '../../storage/report/'.$res['filename'];
- $dicomPath = $reportPath.'.dcm';
- // PACS
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT data FROM settings_pacs WHERE fk_physician = $userID"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $pacs = json_decode($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['data']);
-
- // convert to dicom
- // if comming from a DICOM study, then use existing ID/UID from with this:
- // ' +st '.$aDicomFile.
- $patientName = $res['patient']['lastname'].'^'.$res['patient']['firstname'];
- $patientID = $res['patient']['patientID'];
- $patientBirth = str_replace('-','',$res['patient']['birthDate']);
- $patientSex = $res['patient']['gender'];
- $studyDate = str_replace('-','',$res['visit']['visitDate']);
- $cmdLine = 'pdf2dcm '.$reportPath.' '.$dicomPath.
- ' +pn "'.$patientName.'" +pi "'.$patientID.'" +pb '.$patientBirth.' +ps '.$patientSex.
- ' -k StudyDate="'.$studyDate.'" '.
- ' -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
- ];
- }
- // send
- $cmdLine = 'storescu '.$pacs->serverAddress.' '.$pacs->queryPort.' '.$dicomPath.' -aet '.$pacs->callingAET.' -aec '.$pacs->calledAET.
- ' -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
- ];
- }
- unlink($dicomPath);
-
- return [
- 'result' => 'OK',
- 'report' => $res,
- 'cmdLine' => $cmdLine
- ];
- }
-
- /**
- *
- */
- public function reportPdfDownloadPost($User, $data) {
- $userID = $User->ID;
- $visitID = $data['visitID'];
- $lang = $data['lang'];
- $reportType = $data['type'];
- $mediaList = $data['mediaList'];
- // style
- $style = '.page-break { page-break-after: always; } '.
- 'h1 { width: 100%; margin: 0 0 16px 0; padding: 0; text-align: center; } '.
- 'h3 { width: 100%; margin: 0 0 16px 0; padding: 0; text-align: center; } '.
- '.footer { position: fixed; bottom: 0; width: 100%; text-align: center; }'.
- '.blue { color: rgb(0,0,255); }'.
- '.grid { border-collapse: collapse; } .grid td { border: 1px solid black; text-align: center; }';
- // user
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM user, organization WHERE organization.fk_user = user.ID AND user.ID = $userID"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $user = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- // patient
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM patient, visit WHERE visit.fk_patient = patient.ID AND visit.ID = $visitID"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $patient = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- // visit
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT area, markers, visitDate FROM visit WHERE ID = :fk_visit"
- );
- $statement->bindParam(':fk_visit', $visitID);
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $visit = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- $visit['markers'] = json_decode($visit['markers']);
- // media
- $str = implode(',',$mediaList);
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT ID, side, location, filename, metrics FROM media WHERE ID IN ($str)"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $media = $statement->fetchAll(\PDO::FETCH_ASSOC);
- foreach($media as &$m) {
- $m['metrics'] = json_decode($m['metrics']);
- // measures
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM measure WHERE fk_media = :fk_media ORDER BY ID"
- );
- $statement->bindParam(':fk_media', $m['ID']);
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $m['measure'] = $statement->fetchAll(\PDO::FETCH_ASSOC);
- foreach($m['measure'] as &$_measure) {
- $_measure['points'] = json_decode($_measure['points']);
- $_measure['computation'] = json_decode($_measure['computation']);
- }
- }
- // organization
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT * FROM organization WHERE fk_user = $userID"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $organization = $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
- $org_name = $organization['name'];
- $org_address = $organization['address'].' '.$organization['zip'].' '.$organization['city'].' - '.$organization['phone'];
- // markers
- $markers = [
- "plaque" => ImageWorkshop::initFromPath('../../storage/marker/plaque.png'),
- "stenose" => ImageWorkshop::initFromPath('../../storage/marker/stenose.png'),
- "occlusion" => ImageWorkshop::initFromPath('../../storage/marker/occlusion.png')
- ];
- // IMT
- $imt_value_right = 0;
- $imt_count_right = 0;
- $imt_value_left = 0;
- $imt_count_left = 0;
- // 1st page
- $pics = '<table style="width: 100%;" border="0">';
- if($reportType==2) {
- $pics .= $this->generateImageCell($lang, 'right', $visit, $visitID, $markers, $media, $mediaList[0], $imt_value_right, $imt_count_right, '2R');
- $pics .= $this->generateImageCell($lang, 'left', $visit, $visitID, $markers, $media, $mediaList[1], $imt_value_left, $imt_count_left, '2L');
- }
- else {
- $pics .= '<tr><td colspan="4" style="height: 16px;"></td></tr>'.'<tr>';
- $pics .= $this->generateImageCell($lang, 'right', $visit, $visitID, $markers, $media, $mediaList[0], $imt_value_right, $imt_count_right, '6R');
- $pics .= $this->generateImageCell($lang, 'left', $visit, $visitID, $markers, $media, $mediaList[3], $imt_value_left, $imt_count_left, '6L');
- $pics .= '</tr>';
- $pics .= '<tr><td colspan="4" style="height: 16px;"></td></tr>'.'<tr>';
- $pics .= $this->generateImageCell($lang, 'right', $visit, $visitID, $markers, $media, $mediaList[1], $imt_value_right, $imt_count_right, '6R');
- $pics .= $this->generateImageCell($lang, 'left', $visit, $visitID, $markers, $media, $mediaList[4], $imt_value_left, $imt_count_left, '6L');
- $pics .= '</tr>';
- $pics .= '<tr><td colspan="4" style="height: 16px;"></td></tr>'.'<tr>';
- $pics .= $this->generateImageCell($lang, 'right', $visit, $visitID, $markers, $media, $mediaList[2], $imt_value_right, $imt_count_right, '6R');
- $pics .= $this->generateImageCell($lang, 'left', $visit, $visitID, $markers, $media, $mediaList[5], $imt_value_left, $imt_count_left, '6L');
- $pics .= '</tr>';
- }
- $pics .= '</table>';
- $brand = 'data:image/' . pathinfo(parse_url('../../storage/logo/logo-48.png', PHP_URL_PATH), PATHINFO_EXTENSION) . ';base64,' . base64_encode(file_get_contents('../../storage/logo/logo-48.png'));
- $page1 =
- '<div class="page-break">'.
- //'<h1>'.$this->tr($lang, $reportType==2?'title2':'title6').'</h1>'.
- '<h3 style="margin:4px 0;">'.$org_name.'</h3>'.
- '<h3 style="font-size:14px;">'.$org_address.'</h3>'.
- '<table style="width: 100%; border: 1px solid black;" border="0">'.
- '<tr><td>'.$this->tr($lang, 'patientID').':</td><td>'.$patient['patientID'].'</td><td>'.$this->tr($lang, 'patientName').':</td><td>'.$patient['lastname'].' '.$patient['firstname'].'</td></tr>'.
- '<tr><td>'.$this->tr($lang, 'patientBirth').':</td><td>'.$this->trDate($lang, $patient['birthDate']).'</td><td>'.$this->tr($lang, 'visitID').':</td><td>'.$patient['number'].'</td></tr>'.
- '<tr><td>'.$this->tr($lang, 'institution').':</td><td>'.$user['name'].'</td><td>'.$this->tr($lang, 'physician').':</td><td>'.$user['lastname'].' '.$user['firstname'].'</td></tr>'.
- '</table>'.
- $pics.
- '<div class="footer">'.
- '<div style="position:absolute; left:0;">'.$patient['lastname'].' '.$patient['firstname'].'</div>'.
- $this->trDate($lang, date('Y-m-d')).
- '<div style="position:absolute; right:0;"><img src="'.$brand.'" style="width:96px;"></div>'.
- '</div>'.
- '</div>';
- // 2nd page
- if($imt_count_left>0 && $imt_count_right>0) {
- $password = strtoupper(substr($patient['firstname'], 0, 1)).strtoupper(substr($patient['lastname'], 0, 1)).substr($patient['birthDate'],0,4);
- if($imt_count_left>0) {
- $imt_value_left /= $imt_count_left;
- }
- if($imt_count_right>0) {
- $imt_value_right /= $imt_count_right;
- }
- $abacus_name = '';
- $abacus_gender = $patient['gender'];
- if($data['abacus']=='PARC') {
- $abacus_name = 'Europe, France, 30-79 years, PARC 2009 (Mean)';
- }
- else if($data['abacus']=='ARIC_CAUCASIAN') {
- $abacus_name = 'USA, 35-85 years, Caucasian, ARIC 1993 (R+L). Extrapolated values below 45 and over 65';
- }
- else if($data['abacus']=='ARIC_AFRICAN') {
- $abacus_name = 'USA, 35-85 years, African American, ARIC 1993 (R+L). Extrapolated values below 45 and over 65';
- }
- // graph layout
- $graph_layout = '';
- $abacusTable = '';
- if($data['abacus']=='PARC') {
- // no matter the side
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT data FROM abacus WHERE name = '$abacus_name' AND sex = '$abacus_gender'"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $abacus_raw_data = json_decode($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['data']);
- $abacus_data = [];
- foreach($abacus_raw_data as $raw_data) {
- $abacus_data[$raw_data->age] = [$raw_data->min, $raw_data->mean, $raw_data->max];
- }
- // ref values
- $abacusTable .= '<tr style="background-color: lightgray;"><td>'.$this->tr($lang, 'age').'</td><td>'.$this->tr($lang, '25percent').'</td><td>'.$this->tr($lang, '50percent').'</td><td>'.$this->tr($lang, '75percent').'</td></tr>';
- foreach($abacus_data as $age => $values) {
- $abacusTable .= '<tr><td>'.$age.'</td>';
- foreach($values as $value) {
- $abacusTable .= '<td>'.$value.'</td>';
- }
- $abacusTable .= '</tr>';
- }
-
- // imt value
- $imt_value = $imt_value_left + $imt_value_right;
- if($imt_value_left>0 && $imt_value_right>0) {
- $imt_value /= 2.0;
- }
- // graph
- $graph_layout .= '<img src="'.$this->generateGraph2($abacus_data, 0, $lang, $imt_value, $patient['birthDate']).'">';
- }
- else if($data['abacus']=='ARIC_CAUCASIAN' || $data['abacus']=='ARIC_AFRICAN') {
- // right
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT data FROM abacus WHERE name = '$abacus_name' AND sex = '$abacus_gender' AND side = 'right'"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $abacus_raw_data = json_decode($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['data']);
- $abacus_data_right = [];
- foreach($abacus_raw_data as $raw_data) {
- $abacus_data_right[$raw_data->age] = [$raw_data->min, $raw_data->mean, $raw_data->max];
- }
- // left
- $statement = $this->DataInterface->DatabaseConnection->prepare(
- "SELECT data FROM abacus WHERE name = '$abacus_name' AND sex = '$abacus_gender' AND side = 'left'"
- );
- if(!$statement->execute()) {
- return ['result' => 'ERROR', 'reason' => 'internal_error', 'message' => 'Database error', 'data' => $statement->errorInfo()];
- }
- $abacus_raw_data = json_decode($statement->fetchAll(\PDO::FETCH_ASSOC)[0]['data']);
- $abacus_data_left = [];
- foreach($abacus_raw_data as $raw_data) {
- $abacus_data_left[$raw_data->age] = [$raw_data->min, $raw_data->mean, $raw_data->max];
- }
- // ref values
- $abacusTable .= '<tr style="background-color: lightgray;"><td rowspan="2">'.$this->tr($lang, 'age').'</td><td colspan="2">'.$this->tr($lang, '25percent').'</td><td colspan="2">'.$this->tr($lang, '50percent').'</td><td colspan="2">'.$this->tr($lang, '75percent').'</td></tr>';
- $abacusTable .= '<tr style="background-color: lightgray;"><td>R</td><td>L</td><td>R</td><td>L</td><td>R</td><td>L</td></tr>';
- for($i=0; $i<count($abacus_data_right); $i++) {
- $k = array_keys($abacus_data_right)[$i];
- $abacusTable .= '<tr><td>'.$k.'</td>';
- $val_right = $abacus_data_right[$k];
- $val_left = $abacus_data_left[$k];
- for($v=0; $v<count($val_right); $v++) {
- $abacusTable .= '<td>'.$val_right[$v].'</td>';
- $abacusTable .= '<td>'.$val_left[$v].'</td>';
- }
- $abacusTable .= '</tr>';
- }
- // graph
- $graph_layout .= '<table style="width: 100%;" border="0">';
- $graph_layout .= '<tr><td style="width: 50%;">';
- $graph_layout .= '<img style="width: 100%;" src="'.$this->generateGraph2($abacus_data_right, 0.5, $lang, $imt_value_right, $patient['birthDate']).'">';
- $graph_layout .= '</td><td style="width: 50%;">';
- $graph_layout .= '<img style="width: 100%;" src="'.$this->generateGraph2($abacus_data_left, 0.5, $lang, $imt_value_left, $patient['birthDate']).'">';
- $graph_layout .= '</td></tr>';
- $graph_layout .= '</table>';
- }
- $page2 =
- '<div class="page-break">'.
- '<h3>'.$this->tr($lang, 'p2_title').' ('.$this->tr($lang, $patient['gender']).')</h3>'.
- '<table class="grid" style="width: 100%; margin-bottom: 16px; font-size: 12px;" border="0">'.
- $abacusTable.
- '</table>'.
- '<p style="width: 100%; text-align: center; margin-bottom: 16px; font-size: 12px;">'.$this->tr($lang, $data['abacus']).'</p>'.
- '<p style="width: 100%;" align="center">'.
- $graph_layout.
- '</p>'.
- '<h5 style="margin:0; padding-top: 0;">'.$this->tr($lang, 'indications').'</h4>'.
- '<p style="height:20px;">'.$data['indications'].'</p>'.
- '<h5 style="margin:0;">'.$this->tr($lang, 'clinical').'</h4>'.
- '<p style="height:20px;">'.$data['clinical'].'</p>'.
- '<h5 style="margin:0;">'.$this->tr($lang, 'report').'</h4>'.
- '<p style="height:160px;">'.$data['report'].'</p>'.
- '<p style="width: 100%; text-align: center; font-size: 12px;">'.$this->tr($lang, 'disclaimer').'</p>'.
- '<div class="footer">'.
- '<div style="position:absolute; left:0;">'.$password.'</div>'.
- $this->trDate($lang, date('Y-m-d')).
- '<div style="position:absolute; right:0;"><img src="'.$brand.'" style="width:96px;"></div>'.
- '</div>'.
- '</div>';
- }
- // 3rd page
- $page3 =
- '<div class="">'.
- '<h3 class="blue">'.$this->tr($lang, 'p3_title').'</h3>'.
- '<h4 class="blue">'.$this->tr($lang, 'p3_subtitle1').'</h4>'.
- '<p>'.$this->tr($lang, 'p3_text1').'</p>'.
- '<h4 class="blue">'.$this->tr($lang, 'p3_subtitle2').'</h4>'.
- '<p>'.$this->tr($lang, 'p3_text2').'</p>'.
- '<h4 class="blue">'.$this->tr($lang, 'p3_subtitle3').'</h4>'.
- '<p>'.$this->tr($lang, 'p3_text3').'</p>'.
- '<h4 class="blue">'.$this->tr($lang, 'p3_subtitle4').'</h4>'.
- '<p>'.$this->tr($lang, 'p3_text4').'</p>'.
- '<h4 class="blue">'.$this->tr($lang, 'p3_subtitle5').'</h4>'.
- '<p>'.$this->tr($lang, 'p3_text5').'</p>'.
- '<div class="footer">'.
- '<div style="position:absolute; left:0;">'.$patient['lastname'].' '.$patient['firstname'].'</div>'.
- $this->trDate($lang, date('Y-m-d')).
- '<div style="position:absolute; right:0;"><img src="'.$brand.'" style="width:96px;"></div>'.
- '</div>'.
- '</div>';
- $html = '<html><style>'.$style.'</style><body>'.$page1.$page2.$page3.'</body></html>';
- //file_put_contents('test.html', $html);
- $filename = $patient['lastname'].' '.$patient['firstname'].'-'.$visitID;
- $filename = str_replace(' ','_',$filename);
- $options = new \Dompdf\Options();
- $options->set('isRemoteEnabled', false);
- $dompdf = new \Dompdf\Dompdf($options);
- $dompdf->loadHtml($html, 'UTF-8');
- $dompdf->setPaper('A4', 'portrait');
- $dompdf->render();
- $dompdf->get_canvas()->get_cpdf()->setEncryption($password, $password);
- $baseDir = '../../storage/report/';
- \Tools\FS::mkpath($baseDir);
- $path = $baseDir.$filename.'.pdf';
- file_put_contents($path, $dompdf->output());
- $reportBase64 = base64_encode(file_get_contents($path));
- return [
- 'result' => 'OK',
- 'data' => $data,
- 'media' => $media,
- 'password' => $password,
- 'base64' => $reportBase64,
- 'filename' => $filename.'.pdf',
- 'patient' => $patient,
- 'visit' => $visit
- ];
- }
- public function tr($lang, $item) {
- return array_key_exists($item, DataInterface::$translation[$lang])?DataInterface::$translation[$lang][$item]:'?'.$item.'?';
- }
- public function trDate($lang, $date) {
- if($lang=='fr') {
- $t = explode('-', $date);
- return $t[2].'/'.$t[1].'/'.$t[0];
- }
- return $date;
- }
- protected function generateGraph2($abacus, $plot_offset, $lang, $imt_value, $birth) {
- $width = 450;
- $height = 300;
- $margin = 40;
- $margin2 = 20;
- $today = date("Y-m-d");
- $diff = date_diff(date_create($birth), date_create($today));
- $patientAge = $diff->y;
- $png_image = imagecreate($width+$margin+$margin+$margin2, $height+$margin);
- imagecolorallocate($png_image, 255, 255, 255);
- imageantialias($png_image, true);
- //imagesetthickness($png_image, 2);
- $white = imagecolorallocate($png_image, 255, 255, 255);
- $black = imagecolorallocate($png_image, 0, 0, 0);
- $red = imagecolorallocate($png_image, 255, 0, 0);
- $green = imagecolorallocate($png_image, 0, 128, 0);
- $blue = imagecolorallocate($png_image, 0, 0, 128);
- // scale
- $yr = 125 - 40;
- $yr2 = $yr / 5 * 2;
- $xr = 90 - 20;
- $xr2 = $xr / 5;
- // Y => 30 / 29 => 34 => 33
- $val = 0.4;
- imageline($png_image, $margin2+$margin, 0, $margin2+$margin, $height, $black);
- for($i=0; $i<=$yr2; $i++) {
- $y = $height - (($height-0)/$yr2 * $i);
- $offset = ($i%2)?2:5;
- imageline($png_image, $margin2+$margin-$offset, 0+$y, $margin2+$margin+$offset, 0+$y, $black);
- if(!($i%2) && $i<$yr2-1) {
- imagestring($png_image, 2, $margin2+$margin-32, $y-6, number_format($val,2), $black);
- $val+=0.05;
- }
- }
- // X
- $age = 20;
- imageline($png_image, $margin2+$margin, $height, $margin2+$width+$margin, $height, $black);
- for($i=0; $i<=$xr2; $i++) {
- $x = ($width-0)/$xr2 * $i;
- $offset = ($i%2)?2:5;
- imageline($png_image, $margin2+$margin+$x, $height-$offset, $margin2+$margin+$x, $height+$offset, $black);
- if(!($i%2)) {
- imagestring($png_image, 2, $margin2+$margin+$x-6, $height+6, $age, $black);
- $age+=10;
- }
- }
- // 25%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[0];
- }
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/($xr2/2) * (1+$i+$plot_offset);
- $x2 = ($width-1)/($xr2/2) * (1+$i+1+$plot_offset);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin2+$margin+$x1, $y1, $margin2+$margin+$x2, $y2, $green);
- imagefilledellipse($png_image, $margin2+$margin+$x1, $y1, 5, 5, $green);
- }
- imagefilledellipse($png_image, $margin2+$margin+(($width-1)/($xr2/2) * (1+count($tab)-1+$plot_offset)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $green);
- imagefilledrectangle($png_image, $margin2+$margin+40, 0, $margin2+$margin+50, 10, $green);
- imagettftext($png_image, 10, 0, $margin2+$margin+50+5, 10, $green, './arial.ttf', $this->tr($lang, '25percent'));
-
- // 50%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[1];
- }
- imagesetstyle($png_image, array($black, $black, $black, $black, $black, $black, $black, $black, $black, $black, $white, $white, $white, $white, $white, $white, $white, $white, $white, $white));
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/($xr2/2) * (1+$i+$plot_offset);
- $x2 = ($width-1)/($xr2/2) * (1+$i+1+$plot_offset);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin2+$margin+$x1, $y1, $margin2+$margin+$x2, $y2, IMG_COLOR_STYLED);
- imagefilledellipse($png_image, $margin2+$margin+$x1, $y1, 5, 5, $black);
- }
- imagefilledellipse($png_image, $margin2+$margin+(($width-1)/($xr2/2) * (1+count($tab)-1+$plot_offset)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $black);
- imagefilledrectangle($png_image, $margin2+$margin+180, 0, $margin2+$margin+190, 10, $black);
- imagettftext($png_image, 10, 0, $margin2+$margin+190+5, 10, $black, './arial.ttf', $this->tr($lang, '50percent'));
-
- // 75%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[2];
- }
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/($xr2/2) * (1+$i+$plot_offset);
- $x2 = ($width-1)/($xr2/2) * (1+$i+1+$plot_offset);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin2+$margin+$x1, $y1, $margin2+$margin+$x2, $y2, $red);
- imagefilledellipse($png_image, $margin2+$margin+$x1, $y1, 5, 5, $red);
- }
- imagefilledellipse($png_image, $margin2+$margin+(($width-1)/($xr2/2) * (1+count($tab)-1+$plot_offset)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $red);
- imagefilledrectangle($png_image, $margin2+$margin+320, 0, $margin2+$margin+330, 10, $red);
- imagettftext($png_image, 10, 0, $margin2+$margin+330+5, 10, $red, './arial.ttf', $this->tr($lang, '75percent'));
-
- // value
- $x = $margin+($width/($xr) * ($patientAge-20));
- $y = $height - ( $height / $yr * ($imt_value*100-40) );
- imagefilledellipse($png_image, $margin2+$x, $y, 9, 9, $blue);
- imagettftext($png_image, 10, 0, $margin2+$x + 6, $y + 5, $blue, './arial.ttf', number_format($imt_value,3));
- // legends
- imagettftext($png_image, 10, 0, $width/2+5, $height+32, $black, './arial.ttf', 'Age (y)');
- imagettftext($png_image, 10, 90, 10, $height/2-5, $black, './arial.ttf', 'IMT (mm)');
- ob_start();
- imagepng($png_image);
- $data = ob_get_contents();
- ob_end_clean();
- $res = 'data:image/png;base64,'.base64_encode($data);
- imagedestroy($png_image);
- return $res;
- }
- protected function generateGraph($ABQ, $abacus, $lang, $imt_value_left, $imt_value_right, $birth) {
- $width = 450;
- $height = 300;
- $margin = 40;
- $today = date("Y-m-d");
- $diff = date_diff(date_create($birth), date_create($today));
- $patientAge = $diff->y;
- $png_image = imagecreate($width+$margin+$margin, $height+$margin);
- imagecolorallocate($png_image, 255, 255, 255);
- imageantialias($png_image, true);
- //imagesetthickness($png_image, 2);
- $white = imagecolorallocate($png_image, 255, 255, 255);
- $black = imagecolorallocate($png_image, 0, 0, 0);
- $red = imagecolorallocate($png_image, 255, 0, 0);
- $green = imagecolorallocate($png_image, 0, 128, 0);
- $blue = imagecolorallocate($png_image, 0, 0, 128);
- // value
- $imt_value = $imt_value_left + $imt_value_right;
- if($imt_value_left>0 && $imt_value_right>0) {
- $imt_value /= 2.0;
- }
- // Y
- $val = 0.4;
- imageline($png_image, $margin, 0, $margin, $height, $black);
- for($i=0; $i<=30; $i++) {
- $y = $height - (($height-0)/30 * $i);
- $offset = ($i%2)?2:5;
- imageline($png_image, $margin-$offset, 0+$y, $margin+$offset, 0+$y, $black);
- if(!($i%2) && $i<29) {
- imagestring($png_image, 2, $margin-32, $y-6, number_format($val,2), $black);
- $val+=0.05;
- }
- }
- //
- $yr = 115 - 40;
- if($ABQ=='PARC') {
- // X
- $age = 20;
- imageline($png_image, $margin, $height, $width+$margin, $height, $black);
- for($i=0; $i<=12; $i++) {
- $x = ($width-0)/12 * $i;
- $offset = ($i%2)?2:5;
- imageline($png_image, $margin+$x, $height-$offset, $margin+$x, $height+$offset, $black);
- if(!($i%2)) {
- imagestring($png_image, 2, $margin+$x-6, $height+6, $age, $black);
- $age+=10;
- }
- }
- // 25%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[0];
- }
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/6 * (1+$i);
- $x2 = ($width-1)/6 * (1+$i+1);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin+$x1, $y1, $margin+$x2, $y2, $green);
- imagefilledellipse($png_image, $margin+$x1, $y1, 5, 5, $green);
- }
- imagefilledellipse($png_image, $margin+(($width-1)/6 * (1+count($tab)-1)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $green);
- imagefilledrectangle($png_image, $margin+40, 0, $margin+50, 10, $green);
- imagettftext($png_image, 10, 0, $marvisitgin+50+5, 10, $green, './arial.ttf', $this->tr($lang, '25percent'));
- // 50%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[1];
- }
- imagesetstyle($png_image, array($black, $black, $black, $black, $black, $black, $black, $black, $black, $black, $white, $white, $white, $white, $white, $white, $white, $white, $white, $white));
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/6 * (1+$i);
- $x2 = ($width-1)/6 * (1+$i+1);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin+$x1, $y1, $margin+$x2, $y2, IMG_COLOR_STYLED);
- imagefilledellipse($png_image, $margin+$x1, $y1, 5, 5, $black);
- }
- imagefilledellipse($png_image, $margin+(($width-1)/6 * (1+count($tab)-1)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $black);
- imagefilledrectangle($png_image, $margin+180, 0, $margin+190, 10, $black);
- imagettftext($png_image, 10, 0, $margin+190+5, 10, $black, './arial.ttf', $this->tr($lang, '50percent'));
- // 75%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[2];
- }
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/6 * (1+$i);
- $x2 = ($width-1)/6 * (1+$i+1);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin+$x1, $y1, $margin+$x2, $y2, $red);
- imagefilledellipse($png_image, $margin+$x1, $y1, 5, 5, $red);
- }
- imagefilledellipse($png_image, $margin+(($width-1)/6 * (1+count($tab)-1)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $red);
- imagefilledrectangle($png_image, $margin+320, 0, $margin+330, 10, $red);
- imagettftext($png_image, 10, 0, $margin+330+5, 10, $red, './arial.ttf', $this->tr($lang, '75percent'));
- // value
- $x = $margin+($width/(80-20) * ($patientAge-20));
- $y = $height - ( $height / $yr * ($imt_value*100-40) );
- imagefilledellipse($png_image, $x, $y, 9, 9, $blue);
- imagettftext($png_image, 10, 0, $x + 6, $y + 5, $blue, './arial.ttf', number_format($imt_value,3));
- }
- else if($ABQ=='VITA') {
- // X
- $age = 35;
- imageline($png_image, $margin, $height, $width+$margin, $height, $black);
- for($i=0; $i<=12; $i++) {
- $x = ($width-0)/12 * $i;
- $offset = ($i%2)?2:5;
- imageline($png_image, $margin+$x, $height-$offset, $margin+$x, $height+$offset, $black);
- if(!($i%2)) {
- imagestring($png_image, 2, $margin+$x-6, $height+6, $age, $black);
- $age+=5;
- }
- }
- // 20%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[0];
- }
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/6 * (2+$i);
- $x2 = ($width-1)/6 * (2+$i+1);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin+$x1, $y1, $margin+$x2, $y2, $green);
- imagefilledellipse($png_image, $margin+$x1, $y1, 5, 5, $green);
- }
- imagefilledellipse($png_image, $margin+(($width-1)/6 * (2+count($tab)-1)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $green);
- imagefilledrectangle($png_image, $margin+40, 0, $margin+50, 10, $green);
- imagettftext($png_image, 10, 0, $margin+50+5, 10, $green, './arial.ttf', $this->tr($lang, '20percent'));
- // 80%
- $tab = [];
- foreach($abacus as $age => $values) {
- $tab[] = $values[1];
- }
- for($i=0; $i<count($tab)-1; $i++) {
- $x1 = ($width-1)/6 * (2+$i);
- $x2 = ($width-1)/6 * (2+$i+1);
- $y1 = $height - ( $height / $yr * ($tab[$i]*100-40) );
- $y2 = $height - ( $height / $yr * ($tab[$i+1]*100-40) );
- imageline($png_image, $margin+$x1, $y1, $margin+$x2, $y2, $red);
- imagefilledellipse($png_image, $margin+$x1, $y1, 5, 5, $red);
- }
- imagefilledellipse($png_image, $margin+(($width-1)/6 * (2+count($tab)-1)), $height - ( $height / $yr * ($tab[count($tab)-1]*100-40) ), 5, 5, $red);
- imagefilledrectangle($png_image, $margin+180, 0, $margin+190, 10, $red);
- imagettftext($png_image, 10, 0, $margin+190+5, 10, $red, './arial.ttf', $this->tr($lang, '80percent'));
- // value
- $x = $margin+($width/(65-35) * ($patientAge-35));
- $y = $height - ( $height / $yr * ($imt_value*100-40) );
- imagefilledellipse($png_image, $x, $y, 9, 9, $blue);
- imagettftext($png_image, 10, 0, $x + 6, $y + 5, $blue, './arial.ttf', number_format($imt_value,3));
- }
- ob_start();
- imagepng($png_image);
- $data = ob_get_contents();
- ob_end_clean();
- $res = 'data:image/png;base64,'.base64_encode($data);
- imagedestroy($png_image);
- return $res;
- }
- }
- }
|