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); } } ?>