token = SecurityManager::verifyToken( $token ); $query = "SELECT fk_organization FROM [evolucare].[dbo].[t_person] WHERE id = '". $personId ."'"; $resultsOrga = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsOrga as $value ) { $fk_organization = $value->fk_organization; } $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 ) ."','". date( "Y-m-d", $patientVo->creation/1000 ) ."','". $patientVo->sex ."','". date( "Y-m-d", $patientVo->birthDate/1000 ) ."', '". $patientVo->birthCountry ."', '". $patientVo->ethnicGroup ."', '". date( "Y-m-d", $patientVo->lastVisit/1000 )."', " . $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 ); foreach( $results as $value ) { $patientId = $value->id; } $query = "INSERT INTO [intimamedia_physician].[dbo].[tj_appointment] ( number, date, weight, height, fk_patient, fk_person, fk_live_country ) VALUES (". $appointmentVo->number .",'". date( "Y-m-d", $appointmentVo->date/1000 ) ."',". $appointmentVo->weight .",". $appointmentVo->height .",". $patientId .", ". $personId.", '". $appointmentVo->livingCountry ."')"; $results = SQLServerManager::queryOnDatabase( $query ); if($results == "exception") { Throw new Exception("E007"); } $returnObjectVo->value = $patientId; return $returnObjectVo; } public function searchPatient($criteria, $id_organization, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); /* $names = explode(" ", $criteria); if (sizeof($names) > 1) { $query = "SELECT pa.* FROM [evolucare].[dbo].[t_patient] as pa WHERE (( pa.last_name LIKE '%". $names[0] ."%' AND pa.first_name LIKE '%". $names[1] ."%') OR ( pa.last_name LIKE '%". $names[1] ."%' AND pa.first_name LIKE '%". $names[0] ."%')) AND fk_organization = ". $id_organization .";"; } else { $query = "SELECT pa.* FROM [evolucare].[dbo].[t_patient] as pa WHERE ( pa.last_name LIKE '%". $names[0] ."%' OR pa.first_name LIKE '%". $names[0] ."%') AND fk_organization = ". $id_organization .";"; } */ $query = "SELECT pa.* FROM [evolucare].[dbo].[t_patient] as pa WHERE fk_organization = ". $id_organization .";"; $results = SQLServerManager::queryOnDatabase( $query ); if ($results == "exception") { Throw new Exception("E009"); } $resultArray = array(); foreach( $results as $value ) { $patientVo = new PatientVo(); $patientVo->id = $value->id; $patientVo->firstName = trim( $value->first_name ); $patientVo->lastName = trim( $value->last_name ); $patientVo->sex = trim( $value->sex ); $patientVo->uid = trim( $value->uid_physician ); $patientVo->birthCountry = trim( $value->birth_country ); $patientVo->ethnicGroup = trim( $value->ethnic_group ); $patientVo->creation = $value->creation->format('Y-m-d'); $patientVo->birthDate = $value->birth_date->format('Y-m-d'); $patientVo->lastVisit = $value->last_visit->format('Y-m-d'); array_push( $resultArray, $patientVo ); } /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "searchPatient ---------------------------\n"); fclose($ff);*/ $returnObjectVo->value = $resultArray; return $returnObjectVo; } public function searchAppointments($criteria, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); $query = "SELECT [intimamedia_physician].[dbo].[tj_appointment].id as appointmentId, * FROM [intimamedia_physician].[dbo].[tj_appointment], [evolucare].[dbo].[t_patient] WHERE". " tj_appointment.fk_patient = t_patient.id AND t_patient.uid_physician = '". $criteria ."' ORDER BY number ASC"; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "-------------------- searchAppointments, patient=%s\n", $criteria); fprintf($ff, "searchAppointments, query=%s\n", $query); fclose($ff);*/ $results = SQLServerManager::queryOnDatabase( $query ); $resultArray = array(); foreach( $results as $value ) { $appointmentVo = new AppointmentVo(); $appointmentVo->id = $value->appointmentId; $appointmentVo->number = $value->number; $appointmentVo->date = $value->date->format('Y-m-d'); $appointmentVo->weight = $value->weight; $appointmentVo->height = $value->height; $appointmentVo->livingCountry = $value->fk_live_country; $appointmentVo->patientId = $value->fk_patient; $query = "SELECT collection FROM [intimamedia_physician].[dbo].[t_image] WHERE fk_appointment = ". $appointmentVo->id; $resultsType = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsType as $typeValue ) $appointmentVo->type = $typeValue->collection; $tobaccoVo = new TobaccoVo(); if( $value->fk_tobacco != null ) { $query = "SELECT * FROM [intimamedia_physician].[dbo].[t_tobacco] WHERE id = ". $value->fk_tobacco; $resultsTobacco = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsTobacco as $tobaccoValue ) { $tobaccoVo->smoke = $tobaccoValue->smoke; $tobaccoVo->age = $tobaccoValue->age; $tobaccoVo->cigarettesPerDay = $tobaccoValue->cigarettes_per_day; $tobaccoVo->ageStopSmoking = $tobaccoValue->age_stop_smoking; $tobaccoVo->paquetYear = $tobaccoValue->paquet_year; } $appointmentVo->tobacco = $tobaccoVo; } $atsVo = new AtsVo(); if( $value->fk_risk_ats != null ) { $query = "SELECT * FROM [intimamedia_physician].[dbo].[t_risk_ats] WHERE id = ". $value->fk_risk_ats; $resultsAts = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsAts as $atsValue ) { $atsVo->hta = $atsValue->hta; $atsVo->htaDuration = $atsValue->hta_duration; $atsVo->htg = $atsValue->htg; $atsVo->htgDuration = $atsValue->htg_duration; $atsVo->hct = $atsValue->hct; $atsVo->hctDuration = $atsValue->hct_duration; $atsVo->diabete = $atsValue->diabete; $atsVo->diabeteDuration = $atsValue->diabete_duration; } $appointmentVo->ats = $atsVo; } $personalHistoryVo = new PersonalHistoryVo(); if( $value->fk_personal_history != null ) { $query = "SELECT * FROM [intimamedia_physician].[dbo].[t_personal_history] WHERE id = ". $value->fk_personal_history; $resultsPersonalHistory = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsPersonalHistory as $personalHistoryValue ) { $personalHistoryVo->coronaryDisease = $personalHistoryValue->coronary_disease; $personalHistoryVo->typeCoronaryDisease = $personalHistoryValue->fk_coronary_disease; $personalHistoryVo->lastCoronaryDiseaseAge = strval($personalHistoryValue->last_coronary_disease_age); $personalHistoryVo->aic = $personalHistoryValue->aic; $personalHistoryVo->lastAicAge = strval($personalHistoryValue->last_aic_age); $personalHistoryVo->numberAic = $personalHistoryValue->number_aic; $personalHistoryVo->typeAic = $personalHistoryValue->fk_type_aic; $personalHistoryVo->ethiologyAic = strval($personalHistoryValue->fk_type_ethiology); } $appointmentVo->personalHistory = $personalHistoryVo; } $familyHistoryVo = new FamilyHistoryVo(); if( $value->fk_family_history != null ) { $query = "SELECT * FROM [intimamedia_physician].[dbo].[t_family_history] WHERE id = ". $value->fk_family_history; $resultsFamilyHistory = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsFamilyHistory as $familyHistoryValue ) { $familyHistoryVo->fatherCoronaryPathology = $familyHistoryValue->father_coronary_pathology; $familyHistoryVo->fatherCoronaryPathologyAge = $familyHistoryValue->father_coronary_pathology_age; $familyHistoryVo->motherCoronaryPathology = $familyHistoryValue->mother_coronary_pathology; $familyHistoryVo->motherCoronaryPathologyAge = $familyHistoryValue->mother_coronary_pathology_age; $familyHistoryVo->bsCoronaryPathology = $familyHistoryValue->bs_coronary_pathology; $familyHistoryVo->bsCoronaryPathologyAge = $familyHistoryValue->bs_coronary_pathology_age; $familyHistoryVo->fatherVascularPathology = $familyHistoryValue->father_vascular_pathology; $familyHistoryVo->fatherVascularPathologyAge = $familyHistoryValue->father_vascular_pathology_age; $familyHistoryVo->motherVascularPathology = $familyHistoryValue->mother_vascular_pathology; $familyHistoryVo->motherVascularPathologyAge = $familyHistoryValue->mother_vascular_pathology_age; $familyHistoryVo->bsVascularPathology = $familyHistoryValue->bs_vascular_pathology; $familyHistoryVo->bsVascularPathologyAge = $familyHistoryValue->bs_vascular_pathology_age; } $appointmentVo->familyHistory = $familyHistoryVo; } $cvExaminatorVo = new CvExaminatorVo(); if( $value->fk_cv_examination != null ) { $query = "SELECT * FROM [intimamedia_physician].[dbo].[t_cv_examination] WHERE id = ". $value->fk_cv_examination; $resultsCVExaminator = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsCVExaminator as $cvExaminatorValue ) { $cvExaminatorVo->frequency = $cvExaminatorValue->frequency; $cvExaminatorVo->arythmia = $cvExaminatorValue->arythmia; $cvExaminatorVo->pressureLeftMaxArm = $cvExaminatorValue->pressure_left_max_arm; $cvExaminatorVo->pressureRightMaxArm = $cvExaminatorValue->pressure_right_max_arm; $cvExaminatorVo->pressureLeftMaxLeg = $cvExaminatorValue->pressure_left_max_leg; $cvExaminatorVo->pressureRightMaxLeg = $cvExaminatorValue->pressure_right_max_leg; $cvExaminatorVo->pressureLeftMinArm = $cvExaminatorValue->pressure_left_min_arm; $cvExaminatorVo->pressureRightMinArm = $cvExaminatorValue->pressure_right_min_arm; $cvExaminatorVo->pressureLeftMinLeg = $cvExaminatorValue->pressure_left_min_leg; $cvExaminatorVo->pressureRightMinLeg = $cvExaminatorValue->pressure_right_min_leg; } $appointmentVo->cvExaminator = $cvExaminatorVo; } $query = "SELECT * FROM [intimamedia_physician].[dbo].[tj_risk] WHERE fk_appointment = ". $appointmentVo->id; $resultsRisk = SQLServerManager::queryOnDatabase( $query ); $treatments = array(); foreach( $resultsRisk as $riskValue ) { $query = "SELECT * FROM [intimamedia_physician].[dbo].[t_treatment] WHERE id = ". $riskValue->fk_treatment; $resultsTreatment = SQLServerManager::queryOnDatabase( $query ); foreach( $resultsTreatment as $treatmentValue ) { $treatmentVo = new TreatmentVo(); $treatmentVo->type = trim( $treatmentValue->type ); $treatmentVo->name = trim( $treatmentValue->name ); $treatmentVo->posology = trim( $treatmentValue->posology ); $treatmentVo->startDate = trim( $treatmentValue->date ); array_push( $treatments, $treatmentVo ); } } $appointmentVo->treatments = $treatments; array_push( $resultArray, $appointmentVo ); } if ($results == "exception") { Throw new Exception("E010"); } $returnObjectVo->value = $resultArray; return $returnObjectVo; } public function createAppointment(AppointmentVo $appointmentVo, $patientUid, $token) { // check if an empty appointment doesn't exist $query = "SELECT COUNT(id) as nbImages FROM [intimamedia_physician].[dbo].[t_image] ". "WHERE fk_appointment IN (SELECT MAX(id) FROM [intimamedia_physician].[dbo].[tj_appointment] WHERE fk_patient = " . $appointmentVo->patientId . " );"; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "createAppointment, query=%s\n", $query); fclose($ff);*/ $results = SQLServerManager::queryOnDatabase( $query ); $isLastAppointmentComplete = 0; foreach( $results as $value ) { $isLastAppointmentComplete = $value->nbImages; } if (!$isLastAppointmentComplete) { /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "createAppointment, last appointment not complete, patient=%s\n", $patientUid); fclose($ff);*/ Throw new Exception("E024"); } $query = "SELECT COUNT(id) as nbAppointment FROM [intimamedia_physician].[dbo].[tj_appointment] ". "WHERE fk_patient = " . $appointmentVo->patientId . ";"; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "createAppointment, query=%s\n", $query); fclose($ff);*/ $results = SQLServerManager::queryOnDatabase( $query ); $nbAppointment = 0; foreach( $results as $value ) { $nbAppointment = $value->nbAppointment + 1; } if( $nbAppointment == 0 ) { Throw new Exception("E008"); } $query = "INSERT INTO [intimamedia_physician].[dbo].[tj_appointment] ( number, date, weight, height, fk_patient, fk_live_country ) VALUES (". $nbAppointment .",'". date( "Y-m-d", $appointmentVo->date/1000 ) ."',". $appointmentVo->weight .",". $appointmentVo->height .",". $appointmentVo->patientId .",'". $appointmentVo->livingCountry ."')"; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "createAppointment, new appointment, query=%s\n", $query); fclose($ff);*/ $results = SQLServerManager::queryOnDatabase( $query ); $appointmentVo->number = $nbAppointment; 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, "++++++++++ createAppointment, appointmentId=%s\n", $appointmentId); fclose($ff);*/ if( $appointmentId == -1 ) { Throw new Exception("E011"); } $query = "UPDATE [evolucare].[dbo].[t_patient] SET [last_visit] = '". date( "Y-m-d", $appointmentVo->date/1000 ) ."' WHERE id = ". $appointmentVo->patientId; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "createAppointment, query2=%s\n", $query); fclose($ff);*/ $results = SQLServerManager::queryOnDatabase( $query ); if ($results == "exception") { Throw new Exception("E008"); } return $this->searchAppointments($patientUid, $token); } public function addATSRiskToAnAppointment(AtsVo $atsVo, TobaccoVo $tobaccoVo, $id, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); if ( $atsVo == null OR $tobaccoVo == null) { $returnObjectVo->value = null; return $returnObjectVo; } $query = "SELECT [intimamedia_physician].[dbo].[tj_appointment].fk_tobacco, [intimamedia_physician].[dbo].[tj_appointment].fk_risk_ats FROM [intimamedia_physician].[dbo].[tj_appointment]". " WHERE id = ". $id; $results = SQLServerManager::queryOnDatabase( $query ); $resultArray = array(); foreach( $results as $value ) { $idTobacco = $value->fk_tobacco; $idAts = $value->fk_risk_ats; } $transaction = SQLServerManager::startTransaction(); if ($idTobacco) { //update $tobacco = "UPDATE [intimamedia_physician].[dbo].[t_tobacco] SET smoke = '" . $tobaccoVo->smoke . "', age = '" . $tobaccoVo->age . "', " . "cigarettes_per_day = '" . $tobaccoVo->cigarettesPerDay . "', age_stop_smoking = '" . $tobaccoVo->ageStopSmoking . "', paquet_year = '" . $tobaccoVo->paquetYear . "' " . "WHERE id = " . $idTobacco; } else { $tobacco = "INSERT INTO [intimamedia_physician].[dbo].[t_tobacco] (smoke, age, cigarettes_per_day, age_stop_smoking, paquet_year) VALUES ". "( '". $tobaccoVo->smoke ."', ". $tobaccoVo->age .", ". $tobaccoVo->cigarettesPerDay .", ". $tobaccoVo->ageStopSmoking .", ". $tobaccoVo->paquetYear .")"; } /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addATSRiskToAnAppointment, tobacco=%s\n", $tobacco); fclose($ff);*/ $validTobacco = SQLServerManager::executeQueryForTransaction( $tobacco, $transaction ); if (!$idTobacco) $idTobacco = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_tobacco]", $transaction ); if ($idAts) { //update $ats = "UPDATE [intimamedia_physician].[dbo].[t_risk_ats] set hta = '". $atsVo->hta ."', hta_duration = '". $atsVo->htaDuration ."', hct = '" . $atsVo->hct . "', ". "hct_duration = '" . $atsVo->hctDuration . "', diabete = '" . $atsVo->diabete . "', diabete_duration = '" . $atsVo->diabeteDuration . "', ". "htg = '" . $atsVo->htg ."', htg_duration = '" . $atsVo->htgDuration . "' WHERE id = " . $idAts; } else { $ats = "INSERT INTO [intimamedia_physician].[dbo].[t_risk_ats] (hta, hta_duration, hct, hct_duration, diabete, diabete_duration, htg, htg_duration) VALUES". "('". $atsVo->hta ."', ". $atsVo->htaDuration .", '". $atsVo->hct ."', ". $atsVo->hctDuration .", '". $atsVo->diabete ."', '". $atsVo->diabeteDuration ."', '". $atsVo->htg ."', '". $atsVo->htgDuration ."')"; } /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addATSRiskToAnAppointment, query=%s\n", $ats); fclose($ff);*/ $validAts = SQLServerManager::executeQueryForTransaction( $ats, $transaction ); if (!$idAts) $idAts = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_risk_ats]", $transaction ); $appointment = "UPDATE [intimamedia_physician].[dbo].[tj_appointment] SET fk_tobacco = ". $idTobacco .", fk_risk_ats = ". $idAts ." WHERE id = ". $id; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addATSRiskToAnAppointment, query=%s\n", $appointment); fclose($ff);*/ $validAppointment = SQLServerManager::executeQueryForTransaction( $appointment, $transaction ); if( $validTobacco && $validAts && $validAppointment ) { SQLServerManager::commitTransaction( $transaction ); } else { SQLServerManager::rollBackTransaction( $transaction ); Throw new Exception("E012"); } $returnObjectVo->value = null; return $returnObjectVo; } public function addPersonalHistoryToAnAppointment(PersonalHistoryVo $personalHistoryVo, $id, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); if ($personalHistoryVo == null) { $returnObjectVo->value = null; return $returnObjectVo; } $query = "SELECT [intimamedia_physician].[dbo].[tj_appointment].fk_personal_history FROM [intimamedia_physician].[dbo].[tj_appointment] WHERE id = ". $id; $results = SQLServerManager::queryOnDatabase( $query ); $resultArray = array(); foreach( $results as $value ) { $idHistory = $value->fk_personal_history; } $transaction = SQLServerManager::startTransaction(); if ($idHistory) { // update $history = "UPDATE [intimamedia_physician].[dbo].[t_personal_history] ". "SET coronary_disease = '" . $personalHistoryVo->coronaryDisease . "', aic = '" . $personalHistoryVo->aic . "', number_aic = '" . $personalHistoryVo->numberAic . "', ". "fk_coronary_disease = '" . $personalHistoryVo->typeCoronaryDisease . "', fk_type_aic = '" . $personalHistoryVo->typeAic . "', ". "fk_type_ethiology = '" . $personalHistoryVo->ethiologyAic . "', last_aic_age = '" . intval($personalHistoryVo->lastAicAge) . "', ". "last_coronary_disease_age = '" . intval($personalHistoryVo->lastCoronaryDiseaseAge) . "' WHERE id = " . $idHistory; } else { $history = "INSERT INTO [intimamedia_physician].[dbo].[t_personal_history]". "(coronary_disease,aic,number_aic,fk_coronary_disease,fk_type_aic,fk_type_ethiology, last_aic_age, last_coronary_disease_age)". " VALUES('". $personalHistoryVo->coronaryDisease ."', '". $personalHistoryVo->aic ."', ". $personalHistoryVo->numberAic . ", '". $personalHistoryVo->typeCoronaryDisease ."', '". $personalHistoryVo->typeAic ."', '". $personalHistoryVo->ethiologyAic ."', '" . intval($personalHistoryVo->lastAicAge) . "', '" . intval($personalHistoryVo->lastCoronaryDiseaseAge) . "')"; } /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addPersonalHistoryToAnAppointment, query=%s\n", $history); fclose($ff);*/ $validHistory = SQLServerManager::executeQueryForTransaction( $history, $transaction ); if (!$idHistory) $idHistory = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_personal_history]", $transaction ); $appointment = "UPDATE [intimamedia_physician].[dbo].[tj_appointment] SET fk_personal_history = ". $idHistory ." WHERE id = ". $id; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addPersonalHistoryToAnAppointment, query=%s\n", $appointment); fclose($ff);*/ $validAppointment = SQLServerManager::executeQueryForTransaction( $appointment, $transaction ); if( $validHistory && $validAppointment ) { SQLServerManager::commitTransaction( $transaction ); } else { SQLServerManager::rollBackTransaction( $transaction ); Throw new Exception("E013"); } $returnObjectVo->value = null; return $returnObjectVo; } public function addFamilyHistoryToAnAppointment(FamilyHistoryVo $familyHistoryVo, $id, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); if ($familyHistoryVo == null) { $returnObjectVo->value = null; return $returnObjectVo; } $query = "SELECT [intimamedia_physician].[dbo].[tj_appointment].fk_family_history FROM [intimamedia_physician].[dbo].[tj_appointment] WHERE id = ". $id; $results = SQLServerManager::queryOnDatabase( $query ); $resultArray = array(); foreach( $results as $value ) { $idHistory = $value->fk_family_history; } $transaction = SQLServerManager::startTransaction(); if ($idHistory) { //update $history = "UPDATE [intimamedia_physician].[dbo].[t_family_history] ". "SET father_coronary_pathology = '" . $familyHistoryVo->fatherCoronaryPathology . "', father_coronary_pathology_age = '" . $familyHistoryVo->fatherCoronaryPathologyAge . "', ". "mother_coronary_pathology = '" . $familyHistoryVo->motherCoronaryPathology . "', mother_coronary_pathology_age = '" . $familyHistoryVo->motherCoronaryPathologyAge . "', ". "bs_coronary_pathology = '" . $familyHistoryVo->bsCoronaryPathology . "', bs_coronary_pathology_age = '" . $familyHistoryVo->bsCoronaryPathologyAge . "', ". "father_vascular_pathology = '" . $familyHistoryVo->fatherVascularPathology . "', father_vascular_pathology_age = '" . $familyHistoryVo->fatherVascularPathologyAge . "', ". "mother_vascular_pathology = '" . $familyHistoryVo->motherVascularPathology . "', mother_vascular_pathology_age = '" . $familyHistoryVo->motherVascularPathologyAge . "', ". "bs_vascular_pathology = '" . $familyHistoryVo->bsVascularPathology . "', bs_vascular_pathology_age = '" . $familyHistoryVo->bsVascularPathologyAge . "' WHERE id = " . $idHistory; } else { $history = "INSERT INTO [intimamedia_physician].[dbo].[t_family_history]". "(father_coronary_pathology, father_coronary_pathology_age, mother_coronary_pathology, mother_coronary_pathology_age, bs_coronary_pathology, bs_coronary_pathology_age, ". "father_vascular_pathology, father_vascular_pathology_age, mother_vascular_pathology, mother_vascular_pathology_age, bs_vascular_pathology, bs_vascular_pathology_age)". " VALUES ('". $familyHistoryVo->fatherCoronaryPathology ."', ". $familyHistoryVo->fatherCoronaryPathologyAge .", '". $familyHistoryVo->motherCoronaryPathology ."', ". "". $familyHistoryVo->motherCoronaryPathologyAge .", '". $familyHistoryVo->bsCoronaryPathology ."', ". $familyHistoryVo->bsCoronaryPathologyAge .", ". "'". $familyHistoryVo->fatherVascularPathology ."', ". $familyHistoryVo->fatherVascularPathologyAge .", '". $familyHistoryVo->motherVascularPathology ."', ". "". $familyHistoryVo->motherVascularPathologyAge .", '". $familyHistoryVo->bsVascularPathology ."', ". $familyHistoryVo->bsVascularPathologyAge .")"; } /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addFamilyHistoryToAnAppointment, query=%s\n", $history); fclose($ff);*/ $validHistory = SQLServerManager::executeQueryForTransaction( $history, $transaction ); if (!$idHistory) $idHistory = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_family_history]", $transaction ); $appointment = "UPDATE [intimamedia_physician].[dbo].[tj_appointment] SET fk_family_history = ". $idHistory ." WHERE id = ". $id; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addFamilyHistoryToAnAppointment, query=%s\n", $appointment); fclose($ff);*/ $validAppointment = SQLServerManager::executeQueryForTransaction( $appointment, $transaction ); if( $validHistory && $validAppointment ) { SQLServerManager::commitTransaction( $transaction ); } else { SQLServerManager::rollBackTransaction( $transaction ); Throw new Exception("E014"); } $returnObjectVo->value = null; return $returnObjectVo; } public function addCardiovascularExaminatorToAnAppointment(CvExaminatorVo $cvExaminatorVo, $id, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); if ($cvExaminatorVo == null) { $returnObjectVo->value = null; return $returnObjectVo; } $query = "SELECT [intimamedia_physician].[dbo].[tj_appointment].fk_cv_examination FROM [intimamedia_physician].[dbo].[tj_appointment] WHERE id = ". $id; $results = SQLServerManager::queryOnDatabase( $query ); $resultArray = array(); foreach( $results as $value ) { $idCVExaminator = $value->fk_cv_examination; } $transaction = SQLServerManager::startTransaction(); if ($idCVExaminator) { //update $cvExaminator = "UPDATE [intimamedia_physician].[dbo].[t_cv_examination] ". "SET frequency = '" . $cvExaminatorVo->frequency . "', arythmia = '" . $cvExaminatorVo->arythmia . "', ". "pressure_left_max_arm = '" . $cvExaminatorVo->pressureLeftMaxArm . "', pressure_right_max_arm = '" . $cvExaminatorVo->pressureRightMaxArm . "', ". "pressure_left_max_leg = '" . $cvExaminatorVo->pressureLeftMaxLeg . "', pressure_right_max_leg = '" . $cvExaminatorVo->pressureRightMaxLeg . "', ". "pressure_left_min_arm = '" . $cvExaminatorVo->pressureLeftMinArm . "', pressure_right_min_arm = '" . $cvExaminatorVo->pressureRightMinArm . "', ". "pressure_left_min_leg = '" . $cvExaminatorVo->pressureLeftMinLeg . "', pressure_right_min_leg = '" . $cvExaminatorVo->pressureRightMinLeg . "' WHERE id = " . $idCVExaminator; } else { $cvExaminator = "INSERT INTO [intimamedia_physician].[dbo].[t_cv_examination]". "(frequency, arythmia, pressure_left_max_arm, pressure_right_max_arm, pressure_left_max_leg, pressure_right_max_leg, ". "pressure_left_min_arm, pressure_right_min_arm, pressure_left_min_leg, pressure_right_min_leg)". " VALUES (". $cvExaminatorVo->frequency .", '". $cvExaminatorVo->arythmia ."', ". $cvExaminatorVo->pressureLeftMaxArm .", ". $cvExaminatorVo->pressureRightMaxArm .", ". $cvExaminatorVo->pressureLeftMaxLeg .", ". $cvExaminatorVo->pressureRightMaxLeg .", ". $cvExaminatorVo->pressureLeftMinArm .", ". $cvExaminatorVo->pressureRightMinArm .", ". $cvExaminatorVo->pressureLeftMinLeg .", ". $cvExaminatorVo->pressureRightMinLeg .")"; } /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addCardiovascularExaminatorToAnAppointment = %s\n", $cvExaminator); fclose($ff);*/ $validCVExaminator = SQLServerManager::executeQueryForTransaction( $cvExaminator, $transaction ); if (!$idCVExaminator) $idCVExaminator = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_cv_examination]", $transaction ); $appointment = "UPDATE [intimamedia_physician].[dbo].[tj_appointment] SET fk_cv_examination = ". $idCVExaminator ." WHERE id = ". $id; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addCardiovascularExaminatorToAnAppointment, query=%s\n", $appointment); fclose($ff);*/ $validAppointment = SQLServerManager::executeQueryForTransaction( $appointment, $transaction ); if( $validCVExaminator && $validAppointment ) { SQLServerManager::commitTransaction( $transaction ); } else { SQLServerManager::rollBackTransaction( $transaction ); Throw new Exception("E015"); } $returnObjectVo->value = null; return $returnObjectVo; } public function addTreatmentsToAnAppointment($list, $id, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); if ($list == null) { $returnObjectVo->value = null; return $returnObjectVo; } $dbTreatmentNameList = array(); $newTreatmentNameList = array(); foreach( $list as $value ) array_push( $newTreatmentNameList, $value->name ); $query = "SELECT name, r.fk_treatment FROM [intimamedia_physician].[dbo].[tj_risk] r LEFT JOIN [intimamedia_physician].[dbo].[t_treatment] t on t.id = r.fk_treatment WHERE r.fk_appointment = ". $id; $results = SQLServerManager::queryOnDatabase( $query ); foreach( $results as $value ) { if (!in_array(trim($value->name), $newTreatmentNameList)) { $query = "DELETE FROM [intimamedia_physician].[dbo].[tj_risk] WHERE fk_treatment = ". $value->fk_treatment; SQLServerManager::queryOnDatabase( $query ); $query = "DELETE FROM [intimamedia_physician].[dbo].[tj_treatment] WHERE fk_treatment = ". $value->fk_treatment; SQLServerManager::queryOnDatabase( $query ); } else array_push( $dbTreatmentNameList, trim($value->name) ); } foreach( $list as $value ) { if (in_array($value->name, $dbTreatmentNameList) ) continue; $transaction = SQLServerManager::startTransaction(); $treatment = "INSERT INTO [intimamedia_physician].[dbo].[t_treatment] (date, posology, name, type) VALUES ('". $value->startDate ."', '". $value->posology ."', '". $value->name ."', '". $value->type ."')"; $validTreatment = SQLServerManager::executeQueryForTransaction( $treatment, $transaction ); $idTreatment = SQLServerManager::getLastId( "[intimamedia_physician].[dbo].[t_treatment]", $transaction ); $risks = "INSERT INTO [intimamedia_physician].[dbo].[tj_risk] (fk_treatment, fk_appointment) VALUES (". $idTreatment .", ". $id .")"; $validRisks = SQLServerManager::executeQueryForTransaction( $risks, $transaction ); /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "addTreatments, query=%s\n", $risks); fclose($ff);*/ if( $validTreatment && $validRisks ) { SQLServerManager::commitTransaction( $transaction ); } else { SQLServerManager::rollBackTransaction( $transaction ); Throw new Exception("E016"); } } $returnObjectVo->value = null; return $returnObjectVo; } public function updatePatient(PatientVo $patientVo, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); if ( $patientVo != NULL) { $updatePatientQuery = "UPDATE [evolucare].[dbo].[t_patient] SET last_name = '" . $patientVo->lastName ."', ". "first_name = '" . $patientVo->firstName ."', sex = '". $patientVo->sex ."', ". "birth_date = '". date( "Y-m-d", $patientVo->birthDate/1000 ) ."', birth_country = '". $patientVo->birthCountry ."', ". "ethnic_group = '". $patientVo->ethnicGroup ."' ". "WHERE id = " . $patientVo->id; SQLServerManager::queryOnDatabase( $updatePatientQuery ); } $returnObjectVo->value = null; return $returnObjectVo; } public function updateAppointment(AppointmentVo $appointmentVo, $patientUid, $token) { $returnObjectVo = new ReturnObjectVo(); $returnObjectVo->token = SecurityManager::verifyToken( $token ); $returnObjectVo->value = null; /* $ff=fopen("d:/tmp.jd", "a+"); fprintf($ff, "updateAppointment, appointmentId=%s, patientId=%s\n", $appointmentVo->id, $patientUid); fclose($ff);*/ if ( $appointmentVo != NULL) { // update height, weight and living country $query = "UPDATE [intimamedia_physician].[dbo].[tj_appointment] SET weight = ". $appointmentVo->weight .", height = ". $appointmentVo->height .", ". "fk_live_country = '". $appointmentVo->livingCountry . "' ". "WHERE id = " . $appointmentVo->id .";"; SQLServerManager::queryOnDatabase( $query ); if ($appointmentVo->ats && $appointmentVo->tobacco) $this->addATSRiskToAnAppointment($appointmentVo->ats, $appointmentVo->tobacco, $appointmentVo->id, $token); if ($appointmentVo->personalHistory) $this->addPersonalHistoryToAnAppointment($appointmentVo->personalHistory, $appointmentVo->id, $token); if ($appointmentVo->familyHistory) $this->addFamilyHistoryToAnAppointment($appointmentVo->familyHistory, $appointmentVo->id, $token); if ($appointmentVo->cvExaminator) $this->addCardiovascularExaminatorToAnAppointment($appointmentVo->cvExaminator, $appointmentVo->id, $token); if ($appointmentVo->treatments) $this->addTreatmentsToAnAppointment($appointmentVo->treatments, $appointmentVo->id, $token); } return $returnObjectVo; } } ?>