diff --git a/GaelO2/app/GaelO/Constants/Constants.php b/GaelO2/app/GaelO/Constants/Constants.php index 0616da62c..7f2ae35f5 100644 --- a/GaelO2/app/GaelO/Constants/Constants.php +++ b/GaelO2/app/GaelO/Constants/Constants.php @@ -56,6 +56,8 @@ class Constants const TRACKER_QUALITY_CONTROL = "Quality Control"; const TRACKER_CREATE_USER = "Create User"; const TRACKER_EDIT_USER = "Edit User"; + const TRACKER_EDIT_USER_ROLE= "Edit User Role"; + const TRACKER_EDIT_USER_AFFILIATED_CENTER = "Edit User Affiliated Center"; const TRACKER_CREATE_CENTER = "Create Center"; const TRACKER_DELETE_CENTER = "Delete Center"; const TRACKER_EDIT_CENTER = "Edit Center"; diff --git a/GaelO2/app/GaelO/Services/ImportPatientService.php b/GaelO2/app/GaelO/Services/ImportPatientService.php index dc74eb53b..0012919fb 100644 --- a/GaelO2/app/GaelO/Services/ImportPatientService.php +++ b/GaelO2/app/GaelO/Services/ImportPatientService.php @@ -5,6 +5,7 @@ use App\GaelO\Constants\Enums\InclusionStatusEnum; use App\GaelO\Entities\StudyEntity; use App\GaelO\Exceptions\GaelOBadRequestException; +use App\GaelO\Exceptions\GaelOException; use App\GaelO\Exceptions\GaelOForbiddenException; use App\GaelO\Interfaces\Repositories\CenterRepositoryInterface; use App\GaelO\Interfaces\Repositories\PatientRepositoryInterface; @@ -66,16 +67,13 @@ public function import() //Check condition before import self::checkPatientGender($patientEntity['gender']); self::checkCorrectBirthDate($patientEntity['birthDay'], $patientEntity['birthMonth'], $patientEntity['birthYear']); - if ($patientEntity['inclusionStatus'] === InclusionStatusEnum::INCLUDED->value && $patientEntity['registrationDate'] == null) { - throw new GaelOBadRequestException('Registration Date Missing or Invalid'); - } - if ($patientEntity['inclusionStatus'] !== null) { + if ($patientEntity['inclusionStatus'] !== InclusionStatusEnum::PRE_INCLUDED->value) { $this->isRegistrationDateValid($patientEntity['registrationDate']); } if (!array_key_exists('metadata', $patientEntity)) { $patientEntity['metadata'] = null; - }else{ - if(!array_key_exists('tags', $patientEntity) || !is_array($patientEntity['metadata']['tags'])){ + } else { + if (!array_key_exists('tags', $patientEntity) || !is_array($patientEntity['metadata']['tags'])) { throw new GaelOBadRequestException('Tags key mandatory for metadata with array structure'); }; } @@ -180,7 +178,8 @@ private function isExistingCenter(?int $patientNumCenter): void private function isRegistrationDateValid(?string $registrationDate): void { try { - new DateTime($registrationDate); + $date = DateTime::createFromFormat("Y-m-d", $registrationDate); + if (!$date) throw new GaelOException("malformed date"); } catch (Throwable) { throw new GaelOBadRequestException('Registration Date Missing or Invalid'); } diff --git a/GaelO2/app/GaelO/UseCases/AddAffiliatedCenter/AddAffiliatedCenter.php b/GaelO2/app/GaelO/UseCases/AddAffiliatedCenter/AddAffiliatedCenter.php index 23380c06c..c294a4ef1 100644 --- a/GaelO2/app/GaelO/UseCases/AddAffiliatedCenter/AddAffiliatedCenter.php +++ b/GaelO2/app/GaelO/UseCases/AddAffiliatedCenter/AddAffiliatedCenter.php @@ -47,7 +47,7 @@ public function execute(AddAffiliatedCenterRequest $addAffiliatedCenterRequest, 'user_id' => $userId, 'add_affiliated_center' => $centerCode ]; - $this->trackerRepositoryInterface->writeAction($currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, null, null, Constants::TRACKER_EDIT_USER, $actionDetails); + $this->trackerRepositoryInterface->writeAction($currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, null, null, Constants::TRACKER_EDIT_USER_AFFILIATED_CENTER, $actionDetails); $addAffiliatedCenterResponse->status = '201'; $addAffiliatedCenterResponse->statusText = 'Created'; diff --git a/GaelO2/app/GaelO/UseCases/CreateUserRoles/CreateUserRoles.php b/GaelO2/app/GaelO/UseCases/CreateUserRoles/CreateUserRoles.php index 5e8a2a945..0a45bdd23 100644 --- a/GaelO2/app/GaelO/UseCases/CreateUserRoles/CreateUserRoles.php +++ b/GaelO2/app/GaelO/UseCases/CreateUserRoles/CreateUserRoles.php @@ -56,7 +56,7 @@ public function execute(CreateUserRolesRequest $createRoleRequest, CreateUserRol "study_name" => $studyName, "new_role" => $role ]; - $this->trackerRepositoryInterface->writeAction($currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, $studyName, null, Constants::TRACKER_EDIT_USER, $actionDetails); + $this->trackerRepositoryInterface->writeAction($currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, $studyName, null, Constants::TRACKER_EDIT_USER_ROLE, $actionDetails); $createRoleResponse->statusText = "Created"; $createRoleResponse->status = 201; diff --git a/GaelO2/app/GaelO/UseCases/DeleteAffiliatedCenter/DeleteAffiliatedCenter.php b/GaelO2/app/GaelO/UseCases/DeleteAffiliatedCenter/DeleteAffiliatedCenter.php index 46235ca50..e7e82ba16 100644 --- a/GaelO2/app/GaelO/UseCases/DeleteAffiliatedCenter/DeleteAffiliatedCenter.php +++ b/GaelO2/app/GaelO/UseCases/DeleteAffiliatedCenter/DeleteAffiliatedCenter.php @@ -40,7 +40,7 @@ public function execute(DeleteAffiliatedCenterRequest $deleteAffiliatedCenterReq 'deleted_affiliated_center' => $deleteAffiliatedCenterRequest->centerCode ]; - $this->trackerRepositoryInterface->writeAction($currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, null, null, Constants::TRACKER_EDIT_USER, $actionDetails); + $this->trackerRepositoryInterface->writeAction($currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, null, null, Constants::TRACKER_EDIT_USER_AFFILIATED_CENTER, $actionDetails); $deleteAffiliatedCenterResponse->status = 200; $deleteAffiliatedCenterResponse->statusText = 'OK'; diff --git a/GaelO2/app/GaelO/UseCases/DeleteUserRole/DeleteUserRole.php b/GaelO2/app/GaelO/UseCases/DeleteUserRole/DeleteUserRole.php index 1f6295e63..58d880b94 100644 --- a/GaelO2/app/GaelO/UseCases/DeleteUserRole/DeleteUserRole.php +++ b/GaelO2/app/GaelO/UseCases/DeleteUserRole/DeleteUserRole.php @@ -41,7 +41,7 @@ public function execute(DeleteUserRoleRequest $deleteUserRoleRequest, DeleteUser 'deleted_role' => $role ]; - $this->trackerRepositoryInterface->writeAction($deleteUserRoleRequest->currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, $studyName, null, Constants::TRACKER_EDIT_USER, $actionDetails); + $this->trackerRepositoryInterface->writeAction($deleteUserRoleRequest->currentUserId, Constants::TRACKER_ROLE_ADMINISTRATOR, $studyName, null, Constants::TRACKER_EDIT_USER_ROLE, $actionDetails); $deleteUserRoleResponse->status = 200; $deleteUserRoleResponse->statusText = 'OK'; diff --git a/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDate.php b/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDate.php index b03ad8b35..0313784cc 100644 --- a/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDate.php +++ b/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDate.php @@ -4,6 +4,7 @@ use App\GaelO\Constants\Constants; use App\GaelO\Exceptions\AbstractGaelOException; +use App\GaelO\Exceptions\GaelOBadRequestException; use App\GaelO\Exceptions\GaelOForbiddenException; use App\GaelO\Interfaces\Repositories\TrackerRepositoryInterface; use App\GaelO\Interfaces\Repositories\VisitRepositoryInterface; @@ -32,11 +33,16 @@ public function execute(ModifyVisitDateRequest $modifyVisitDateRequest, ModifyVi $visitId = $modifyVisitDateRequest->visitId; $currentUserId = $modifyVisitDateRequest->currentUserId; $newVisitDate = $modifyVisitDateRequest->visitDate; + $reason = $modifyVisitDateRequest->reason ?? null; + + if (!$reason || empty($reason)) { + throw new GaelOBadRequestException('Reason must be specified'); + } $visitContext = $this->visitRepositoryInterface->getVisitContext($visitId); $studyName = $visitContext['patient']['study_name']; - if($modifyVisitDateRequest->studyName !== $studyName){ + if ($modifyVisitDateRequest->studyName !== $studyName) { throw new GaelOForbiddenException("should be called from original study"); } diff --git a/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDateRequest.php b/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDateRequest.php index eeae3b695..6f300b0ad 100644 --- a/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDateRequest.php +++ b/GaelO2/app/GaelO/UseCases/ModifyVisitDate/ModifyVisitDateRequest.php @@ -8,4 +8,5 @@ class ModifyVisitDateRequest public string $studyName; public int $visitId; public string $visitDate; + public string $reason; } diff --git a/GaelO2/config/app.php b/GaelO2/config/app.php index 3bb93d024..611b4a7c6 100644 --- a/GaelO2/config/app.php +++ b/GaelO2/config/app.php @@ -25,7 +25,7 @@ | or any other location as required by the application or its packages. */ - 'version' => '2.7.3', + 'version' => '2.8.0', /* |-------------------------------------------------------------------------- diff --git a/GaelO2/tests/Feature/TestPatients/ImportPatientTest.php b/GaelO2/tests/Feature/TestPatients/ImportPatientTest.php index 9810ef13f..da099def6 100644 --- a/GaelO2/tests/Feature/TestPatients/ImportPatientTest.php +++ b/GaelO2/tests/Feature/TestPatients/ImportPatientTest.php @@ -227,6 +227,19 @@ public function testIncorrectPatientCodeLength() $this->assertEquals(123, $resp['fail']['Incorrect Patient Code Length'][0]); } + public function testWrongFormatInclusionDate() + { + $currentUserId = AuthorizationTools::actAsAdmin(false); + AuthorizationTools::addRoleToUser($currentUserId, Constants::ROLE_SUPERVISOR, $this->study->name); + + $this->validPayload[0]['registrationDate'] = '01-01-2024'; + $resp = $this->json('POST', '/api/studies/' . $this->study->name . '/import-patients?role=Supervisor', $this->validPayload); + //dd($resp); + $this->assertEquals(0, count($resp['success'])); + $this->assertNotEmpty($resp['fail']['Registration Date Missing or Invalid']); + $this->assertEquals(12341231234123, $resp['fail']['Registration Date Missing or Invalid'][0]); + } + public function testMissingInclusionDateWhileIncluded() { $currentUserId = AuthorizationTools::actAsAdmin(false); diff --git a/GaelO2/tests/Feature/TestVisits/ModifyVisitDateTest.php b/GaelO2/tests/Feature/TestVisits/ModifyVisitDateTest.php index 49ee173e4..6fe952326 100644 --- a/GaelO2/tests/Feature/TestVisits/ModifyVisitDateTest.php +++ b/GaelO2/tests/Feature/TestVisits/ModifyVisitDateTest.php @@ -27,7 +27,8 @@ public function testModifyVisitDate() AuthorizationTools::addRoleToUser($currentUserId, Constants::ROLE_SUPERVISOR, $this->studyName); $payload = [ - 'visitDate' => now() + 'visitDate' => now(), + 'reason' => 'changeDate' ]; $response = $this->put('/api/visits/'.$this->visit->id.'/visit-date?studyName='.$this->studyName, $payload); @@ -36,13 +37,29 @@ public function testModifyVisitDate() } + public function testModifyVisitDateShouldFailMissingReason() + { + $currentUserId = AuthorizationTools::actAsAdmin(false); + AuthorizationTools::addRoleToUser($currentUserId, Constants::ROLE_SUPERVISOR, $this->studyName); + + $payload = [ + 'visitDate' => now(), + ]; + + $response = $this->put('/api/visits/'.$this->visit->id.'/visit-date?studyName='.$this->studyName, $payload); + + $response->assertStatus(400); + + } + public function testModifyVisitDateShouldFailWrongStudy() { $currentUserId = AuthorizationTools::actAsAdmin(false); AuthorizationTools::addRoleToUser($currentUserId, Constants::ROLE_SUPERVISOR, $this->studyName); $payload = [ - 'visitDate' => now() + 'visitDate' => now(), + 'reason' => 'changeDate' ]; $response = $this->put('/api/visits/'.$this->visit->id.'/visit-date?studyName='.$this->studyName. 'wrong', $payload); @@ -57,7 +74,8 @@ public function testModifyVisitDateShouldFailNoRole() AuthorizationTools::addRoleToUser($currentUserId, Constants::ROLE_INVESTIGATOR, $this->studyName); $payload = [ - 'visitDate' => now() + 'visitDate' => now(), + 'reason' => 'changeDate' ]; $response = $this->put('/api/visits/'.$this->visit->id.'/visit-date?studyName='.$this->studyName, $payload); diff --git a/README.md b/README.md index aa5e7d2aa..4ec92b380 100755 --- a/README.md +++ b/README.md @@ -28,4 +28,4 @@ sheetname limité a 31 caractère $sheetName = substr($role, 0, 3) . '_' . $vi node_modules/mjml/bin/mjml ./app/GaelO/views/mails/mjml/qc_report_buttons.mjml -o ./app/GaelO/views/mails/mail_qc_report_buttons.blade.php node_modules/mjml/bin/mjml ./app/GaelO/views/mails/mjml/radiomics_report.mjml -o ./app/GaelO/views/mails/mail_radiomics_report.blade.php ``` -In blade generated files, edit file to keep only body content (remove header...) +In blade generated files, edit file to keep only body content (remove header...) \ No newline at end of file