| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- <?php
- require_once('vo/com/imt/intimamedia/vo/UserVo.php');
- require_once('vo/com/imt/intimamedia/vo/PersonVo.php');
- require_once('vo/com/imt/intimamedia/vo/PatientVo.php');
- require_once('vo/com/imt/intimamedia/vo/HospitalVo.php');
- require_once('vo/com/imt/intimamedia/vo/UltraSoundScannerVo.php');
- require_once('vo/com/imt/intimamedia/vo/ProbeVo.php');
- require_once('vo/com/imt/intimamedia/vo/MailVo.php');
- require_once('vo/com/imt/intimamedia/vo/TermsVo.php');
- require_once('vo/com/imt/intimamedia/vo/MessageVo.php');
- require_once('vo/com/imt/intimamedia/vo/AppointmentVo.php');
- require_once('vo/com/imt/intimamedia/vo/TobaccoVo.php');
- require_once('vo/com/imt/intimamedia/vo/AtsVo.php');
- require_once('vo/com/imt/intimamedia/vo/ReturnObjectVo.php');
- require_once('vo/com/imt/intimamedia/vo/PersonalHistoryVo.php');
- require_once('vo/com/imt/intimamedia/vo/FamilyHistoryVo.php');
- require_once('vo/com/imt/intimamedia/vo/CvExaminatorVo.php');
- require_once('vo/com/imt/intimamedia/vo/TreatmentVo.php');
- require_once('common/SQLServerManager.php');
- require_once('common/SecurityManager.php');
- require_once('common/ImtMail.php');
- require_once('PatientService.php');
- require_once('AcquisitionService.php');
- require_once('MeasureService.php');
- define ('INTIMAMEDIA_APPLICATION', 'INTIMA');
- define("IP_HOST", "37.187.89.74");
- define ('EXAMPLE_PATIENT_FILE_UID_1', 'by3xs8kXHn');
- define ('EXAMPLE_PATIENT_FILE_ORGANIZATION_1', 158);
- Throw new Exception("Update User Id");
-
- $key = "3HFdkfjdz*$)kn;!fdD1nsf~2@KL-{{";
- $userId = 159 ;
-
- /*$ff=fopen("tmp.jd", "a+");
- fprintf($ff, "activation, user=%s, password=%s\n", $user, $password);
- fclose($ff);*/
-
- $query = "SELECT id, last_connection FROM [evolucare].[dbo].[tj_user] WHERE id = '".$userId."';";
-
- $result = SQLServerManager::queryOnDatabase( $query );
-
- $idFound = 0;
- foreach( $result as $value )
- {
- $idFound = $value->id;
- $lastConnection = $value->last_connection;
- }
-
- if (!$idFound || $lastConnection)
- {
- Throw new Exception("");
- }
-
- // last, create example patient file, for testing purpose
- createIntimamediaExample($userId, EXAMPLE_PATIENT_FILE_UID_1, EXAMPLE_PATIENT_FILE_ORGANIZATION_1);
-
- $now = date( "Y-m-d H:i:s" );
- $query = "UPDATE [evolucare].[dbo].[tj_user] SET last_connection = '". $now ."' WHERE id = '" . $userId . "'";
- $transaction = SQLServerManager::startTransaction();
- $executeQuery = SQLServerManager::executeQueryForTransaction( $query, $transaction );
- SQLServerManager::commitTransaction( $transaction );
-
- function createIntimamediaExample($userId, $patientUid, $organizationId)
- {
- $token = time() + 1000;
-
- // get personId
- $query = "SELECT fk_person FROM [evolucare].[dbo].[tj_user] WHERE id = '". $userId ."'";
-
- $results = SQLServerManager::queryOnDatabase( $query );
- foreach( $results as $value )
- $personId = $value->fk_person;
-
- // get patient
- $returnObjectVo = new ReturnObjectVo();
-
- $patientService = new PatientService();
- $returnObjectVo = $patientService->searchPatient('', $organizationId, $token);
-
- $patientVo = new PatientVo();
- foreach( $returnObjectVo->value as $value )
- {
- if (strcmp($value->uid, $patientUid))
- continue;
-
- $patientVo->firstName = $value->firstName;
- $patientVo->lastName = $value->lastName;
- $patientVo->sex = $value->sex;
- $patientVo->uid = $value->uid;
- $patientVo->birthCountry = $value->birthCountry;
- $patientVo->ethnicGroup = $value->ethnicGroup;
- $patientVo->creation = $value->creation;
- $patientVo->birthDate = $value->birthDate;
- $patientVo->lastVisit = $value->lastVisit;
- break;
-
- }
-
- // createPatient
- $patientId = createExamplePatient($patientVo, $personId);
-
- // getAppointments
- $returnObjectVo = $patientService->searchAppointments($patientUid, $token);
-
- $appointmentVo = new AppointmentVo();
- $nbAppointment = 1;
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "createIntimamediaExample, nbappointment=%s\n", sizeof($returnObjectVo->value));
- fclose($ff);*/
-
- foreach( $returnObjectVo->value as $value )
- {
- $getMeasures = true;
-
- $appointmentVo->number = $nbAppointment;
- $appointmentVo->patientId = $patientId;
- $appointmentVo->date = $value->date;
- $appointmentVo->weight = $value->weight;
- $appointmentVo->height = $value->height;
- $appointmentVo->livingCountry = $value->livingCountry;
-
- $srcAppointmentId = $value->id;
-
- // create appointment
- $appointmentVo->id = createExampleAppointment($appointmentVo, $patientUid);
-
- $atsVo = new AtsVo();
- $atsVo = $value->ats;
-
- $tobaccoVo = new TobaccoVo();
- $tobaccoVo = $value->tobacco;
-
- $personalHistoryVo = new PersonalHistoryVo();
- $personalHistoryVo = $value->personalHistory;
-
- $familyHistoryVo = new FamilyHistoryVo();
- $familyHistoryVo = $value->familyHistory;
-
- $cvExaminatorVo = new CvExaminatorVo();
- $cvExaminatorVo = $value->cvExaminator;
-
- $treatments = array();
- $treatments = $value->treatments;
-
- if ($atsVo && $tobaccoVo)
- $patientService->addATSRiskToAnAppointment($atsVo, $tobaccoVo, $appointmentVo->id, $token);
- if ($personalHistoryVo)
- $patientService->addPersonalHistoryToAnAppointment($personalHistoryVo, $appointmentVo->id, $token);
- if ($familyHistoryVo)
- $patientService->addFamilyHistoryToAnAppointment($familyHistoryVo, $appointmentVo->id, $token);
- if ($cvExaminatorVo)
- $patientService->addCardiovascularExaminatorToAnAppointment($cvExaminatorVo, $appointmentVo->id, $token);
- if ($treatments)
- $patientService->addTreatmentsToAnAppointment($treatments, $appointmentVo->id, $token);
-
- // get markers
- $acquisitionService = new AcquisitionService();
- $markerArray = $acquisitionService->getMarkersFromAppointment($srcAppointmentId);
- $acquisitionService->saveMarker($markerArray, $appointmentVo->id);
-
- // get images
- $imageArray = $acquisitionService->getImagesFromAppointment($srcAppointmentId);
-
- $imageIdList = array();
- foreach( $imageArray as $image )
- array_push($imageIdList, $image->id);
-
- // get measures
- $measureService = new MeasureService();
- try {
- $measureArray = $measureService->getMeasures($imageIdList);
- } catch (Exception $e) {$getMeasures = false;}
-
- $matchingId = array();
- foreach( $imageArray as $image )
- {
- $newImageId = createExampleImage($image, $srcAppointmentId, $appointmentVo->id);
- $matchingId["$image->id"] = $newImageId;
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "createIntimamediaExample, oldimageId = %d, newimageId=%d\n", $image->id, $newImageId);
- fclose($ff);*/
- }
-
- if (!$getMeasures)
- {
- $nbAppointment++;
- continue;
- }
-
- $measuresToPersist = array();
- foreach( $measureArray as $measure )
- {
- $dragAndDropVo = new DragAndDropVo();
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "createIntimamediaExample, matching=%d %d\n", $matchingId["$measure->imageId"], $measure->imageId);
- fclose($ff);*/
-
- $dragAndDropVo->id = $matchingId["$measure->imageId"];
- $dragAndDropVo->scale = $measure->scale;
- $dragAndDropVo->distance = $measure->distance;
- $dragAndDropVo->area = $measure->area;
- $dragAndDropVo->area2 = $measure->area2;
- $dragAndDropVo->nwImtResult = $measure->nwImt;
- $dragAndDropVo->fwImtResult = $measure->fwImt;
- $dragAndDropVo->ultraSoundScanner = 0;
-
- array_push($measuresToPersist, $dragAndDropVo);
- }
-
- $measureService->saveMeasures($measuresToPersist);
-
- $nbAppointment++;
- }
- }
-
- function createExamplePatient(PatientVo $patientVo, $personId)
- {
- $query = "SELECT fk_organization FROM [evolucare].[dbo].[t_person] WHERE id = '". $personId ."'";
- $results = SQLServerManager::queryOnDatabase( $query );
-
- foreach( $results as $value )
- $fk_organization = $value->fk_organization;
-
- $patientVo->uid = substr($patientVo->uid, 3);
- $patientVo->uid .= $personId;
- $query = "INSERT INTO [evolucare].[dbo].[t_patient] (uid_physician, first_name, last_name, creation, sex, birth_date, birth_country, ethnic_group, last_visit, fk_physician, fk_organization) VALUES ('".
- $patientVo->uid ."','". SQLServerManager::convertStringToSQLServer( $patientVo->firstName ) ."','".
- SQLServerManager::convertStringToSQLServer( $patientVo->lastName ) ."','".
- $patientVo->creation ."','". $patientVo->sex ."','".
- $patientVo->birthDate ."', '". $patientVo->birthCountry ."', '". $patientVo->ethnicGroup ."', '".
- $patientVo->lastVisit ."', " . $personId .", ". $fk_organization .")";
- $results = SQLServerManager::queryOnDatabase( $query );
-
- if( $results == "exception")
- Throw new Exception("E007");
-
- $query = "SELECT id FROM [evolucare].[dbo].[t_patient] WHERE uid_physician = '". $patientVo->uid ."'";
- $results = SQLServerManager::queryOnDatabase( $query );
-
- $patientId = -1;
- foreach( $results as $value )
- $patientId = $value->id;
-
- return $patientId;
- }
-
- function createExampleAppointment(AppointmentVo $appointmentVo, $patientUid)
- {
- $query = "INSERT INTO [intimamedia_physician].[dbo].[tj_appointment] ( number, date, weight, height, fk_patient, fk_live_country ) VALUES (".
- $appointmentVo->number .",'". $appointmentVo->date ."',". $appointmentVo->weight .",".
- $appointmentVo->height .",". $appointmentVo->patientId .",'". $appointmentVo->livingCountry ."')";
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "createExampleAppointment, query=%s\n", $query);
- fclose($ff);*/
-
- $results = SQLServerManager::queryOnDatabase( $query );
-
- if( $results == "exception")
- Throw new Exception("E008");
-
- $query = "SELECT MAX(id) AS lastId FROM [intimamedia_physician].[dbo].[tj_appointment]";
- $results = SQLServerManager::queryOnDatabase( $query );
-
- $appointmentId = -1;
- foreach( $results as $value )
- $appointmentId = $value->lastId;
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "++++++++++ createExampleAppointment, appointmentId=%s\n", $appointmentId);
- fclose($ff);*/
-
- return $appointmentId;
- }
-
- function createExampleImage( DragAndDropVo $dragAndDropVo, $srcAppointmentId, $appointmentId )
- {
- $path = "../images/";
- $srcFolder = $path . $srcAppointmentId;
- $folder = $path . $appointmentId;
-
- $keyType = $dragAndDropVo->type;
- $imageHigh = substr($dragAndDropVo->imageHigh, strrpos($dragAndDropVo->imageHigh, '/')+1);
- $imageSmall = substr($dragAndDropVo->imageSmall, strrpos($dragAndDropVo->imageSmall, '/')+1);
- $width = $dragAndDropVo->width;
- $height = $dragAndDropVo->height;
- $collection = $dragAndDropVo->collection;
- $incidence = $dragAndDropVo->incidence;
- $dicom = ($dragAndDropVo->isDicom) ? 1 : 0;
-
- if( !is_dir ( $folder ) )
- {
- mkdir( $folder );
- }
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "saveImages, src=%s dest=%s\n", $srcFolder. "/" . $imageHigh, $folder. "/". $imageHigh);
- fclose($ff);*/
-
- copy( $srcFolder. "/" . $imageHigh, $folder. "/". $imageHigh);
- copy( $srcFolder. "/" . $imageSmall, $folder. "/". $imageSmall);
-
- $url = "/images/". $appointmentId ."/";
-
- $transaction = SQLServerManager::startTransaction();
- $imageQuery = "INSERT INTO [intimamedia_physician].[dbo].[t_image] ( image, image_small, width, height, collection, fk_type, fk_appointment, incidence, dicom ) VALUES ( '". $url . $imageHigh ."', '". $url . $imageSmall ."', ". $width .", ". $height .", '". $collection ."', '".$keyType ."', ". $appointmentId .", '". $incidence ."', " . $dicom . ")";
- $validImageQuery = SQLServerManager::executeQueryForTransaction( $imageQuery, $transaction );
- $idImage = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_image]", $transaction );
-
- if( $validImageQuery )
- {
- SQLServerManager::commitTransaction( $transaction );
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "saveImages, imageid=%s added\n", $idImage);
- fclose($ff);*/
-
- return $idImage;
- }
-
- Throw new Exception("E017");
- }
-
- function createExampleMeasures( $list )
- {
- foreach( $list as $value )
- {
- $imgId = $value->id;
- $scale = $value->scale;
- $distance = $value->distance;
- $area = $value->area;
- $area2 = $value->area2;
- $nwImtResult = $value->nwImtResult;
- $fwImtResult = $value->fwImtResult;
- $ultraSoundScanner = $value->ultrasoudscanner;
-
- $query = "SELECT id FROM [intimamedia_physician].[dbo].[tj_measure] WHERE fk_image = ". $imgId;
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "createExampleMeasures, list=%d %f %f %f %d %d\n", $imgId, $scale, $distance, $area, $nwImtResult, $fwImtResult);
- fprintf($ff, "createExampleMeasures, sql=%s\n", $query);
- fclose($ff);*/
-
- $results = SQLServerManager::queryOnDatabase( $query );
-
- $resultArray = array();
- $measureId = 0;
-
- foreach( $results as $val )
- {
- $measureId = $val->id;
- }
-
- $operation = INSERT;
- if ($measureId)
- {
- // update
- $operation = UPDATE;
- }
-
- /*$ff=fopen("d:/tmp.jd", "a+");
- fprintf($ff, "createExampleMeasures, measureId=%s\n", $measureId);
- fclose($ff);*/
-
- $measureService = new MeasureService();
- $measureService->persistMeasure($measureId, $imgId, $operation, $scale, $distance, $area, $area2, $fwImtResult, $nwImtResult, $ultraSoundScanner);
- }
- }
-
- ?>
|