| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064 |
- <?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>';
- $html = '<html><style>'.$style.'</style><body>'.$page1.$page2.'</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;
- }
- }
- }
|