From af0db6306015ec4787a03262068f3941d054d79d Mon Sep 17 00:00:00 2001 From: Salim Kanoun Date: Tue, 11 Jun 2024 22:04:55 +0200 Subject: [PATCH] Add allow_upload_supervisor in study table and apis --- GaelO2/app/GaelO/Entities/StudyEntity.php | 2 ++ .../Repositories/StudyRepositoryInterface.php | 2 +- .../GaelO/Repositories/StudyRepository.php | 3 +- .../UseCases/CreateStudy/CreateStudy.php | 7 ++++- .../CreateStudy/CreateStudyRequest.php | 1 + GaelO2/database/factories/StudyFactory.php | 10 +++++++ ...1_193737_allow_supervisor_upload_dicom.php | 28 +++++++++++++++++++ .../Feature/TestStudy/CreateStudyTest.php | 3 +- .../TestRepositories/StudyRepositoryTest.php | 2 ++ .../tests/Unit/TestServices/VisitTreeTest.php | 4 +-- 10 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 GaelO2/database/migrations/2024_06_11_193737_allow_supervisor_upload_dicom.php diff --git a/GaelO2/app/GaelO/Entities/StudyEntity.php b/GaelO2/app/GaelO/Entities/StudyEntity.php index bfa3eb20d..c012f340c 100644 --- a/GaelO2/app/GaelO/Entities/StudyEntity.php +++ b/GaelO2/app/GaelO/Entities/StudyEntity.php @@ -14,6 +14,7 @@ class StudyEntity public bool $documentationMandatory; public bool $deleted; public bool $creatablePatientsInvestigator; + public bool $allowSupervisorUploadDicom; public ?string $ancillaryOf; //Array of VisitGroupEntities @@ -31,6 +32,7 @@ public static function fillFromDBReponseArray(array $array) : StudyEntity $studyEntity->ancillaryOf = $array['ancillary_of']; $studyEntity->documentationMandatory = $array['documentation_mandatory']; $studyEntity->creatablePatientsInvestigator = $array['creatable_patients_investigator']; + $studyEntity->allowSupervisorUploadDicom = $array['allow_supervisor_upload_dicom']; $studyEntity->deleted = $array['deleted_at'] !== null; return $studyEntity; diff --git a/GaelO2/app/GaelO/Interfaces/Repositories/StudyRepositoryInterface.php b/GaelO2/app/GaelO/Interfaces/Repositories/StudyRepositoryInterface.php index d5e2e7f26..b8271fe39 100644 --- a/GaelO2/app/GaelO/Interfaces/Repositories/StudyRepositoryInterface.php +++ b/GaelO2/app/GaelO/Interfaces/Repositories/StudyRepositoryInterface.php @@ -11,7 +11,7 @@ public function find($name): StudyEntity; public function delete($name): void; - public function addStudy(String $name, string $code, int $patientCodeLength, string $contactEmail, bool $controllerShowAll, bool $monitorShowAll, bool $documentationMandatory, ?string $ancillaryOf, bool $creatablePatientsInvestigator): void; + public function addStudy(String $name, string $code, int $patientCodeLength, string $contactEmail, bool $controllerShowAll, bool $monitorShowAll, bool $documentationMandatory, ?string $ancillaryOf, bool $creatablePatientsInvestigator, bool $allowSupervisorUploadDicom): void; public function isExistingStudyName(string $name): bool; diff --git a/GaelO2/app/GaelO/Repositories/StudyRepository.php b/GaelO2/app/GaelO/Repositories/StudyRepository.php index 631f7ce71..9202c505e 100644 --- a/GaelO2/app/GaelO/Repositories/StudyRepository.php +++ b/GaelO2/app/GaelO/Repositories/StudyRepository.php @@ -27,7 +27,7 @@ public function delete($name): void $this->studyModel->findOrFail($name)->delete(); } - public function addStudy(String $name, string $code, int $patientCodeLength, string $contactEmail, bool $controllerShowAll, bool $monitorShowAll, bool $documentationMandatory, ?string $ancillaryOf, bool $creatablePatientsInvestigator): void + public function addStudy(String $name, string $code, int $patientCodeLength, string $contactEmail, bool $controllerShowAll, bool $monitorShowAll, bool $documentationMandatory, ?string $ancillaryOf, bool $creatablePatientsInvestigator, bool $allowSupervisorUploadDicom): void { $study = new Study(); $study->name = $name; @@ -39,6 +39,7 @@ public function addStudy(String $name, string $code, int $patientCodeLength, str $study->documentation_mandatory = $documentationMandatory; $study->ancillary_of = $ancillaryOf; $study->creatable_patients_investigator = $creatablePatientsInvestigator; + $study->allow_supervisor_upload_dicom = $allowSupervisorUploadDicom; $study->save(); } diff --git a/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudy.php b/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudy.php index c6484c7eb..b380d92bc 100644 --- a/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudy.php +++ b/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudy.php @@ -42,6 +42,7 @@ public function execute(CreateStudyRequest $createStudyRequest, CreateStudyRespo $contactEmail = $createStudyRequest->contactEmail; $ancillaryOf = $createStudyRequest->ancillaryOf; $creatablePatientsInvestigator = $createStudyRequest->creatablePatientsInvestigator; + $allowSupervisorUploadDicom = $createStudyRequest->allowSupervisorUploadDicom; if (preg_match('/[^A-Z0-9]/', $studyName)) { throw new GaelOBadRequestException('Only uppercase alphanumerical name allowed, no space or special characters'); @@ -75,7 +76,11 @@ public function execute(CreateStudyRequest $createStudyRequest, CreateStudyRespo throw new GaelOBadRequestException('Missing Creatable Patient Investigator'); } - $this->studyRepositoryInterface->addStudy($studyName, $studyCode, $patientCodeLength, $contactEmail, $controllerShowAll, $monitorShowAll, $documentationMandatory, $ancillaryOf, $creatablePatientsInvestigator); + if(!isset($allowSupervisorUploadDicom)){ + throw new GaelOBadRequestException('Missing Allow Upload Dicom Supervisor'); + } + + $this->studyRepositoryInterface->addStudy($studyName, $studyCode, $patientCodeLength, $contactEmail, $controllerShowAll, $monitorShowAll, $documentationMandatory, $ancillaryOf, $creatablePatientsInvestigator, $allowSupervisorUploadDicom); $currentUserId = $createStudyRequest->currentUserId; $actionDetails = [ diff --git a/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudyRequest.php b/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudyRequest.php index d4b55c670..2459ac7bf 100644 --- a/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudyRequest.php +++ b/GaelO2/app/GaelO/UseCases/CreateStudy/CreateStudyRequest.php @@ -14,4 +14,5 @@ class CreateStudyRequest public bool $documentationMandatory; public ?string $ancillaryOf = null; public bool $creatablePatientsInvestigator; + public bool $allowSupervisorUploadDicom; } diff --git a/GaelO2/database/factories/StudyFactory.php b/GaelO2/database/factories/StudyFactory.php index 4933881a7..e689d8b74 100644 --- a/GaelO2/database/factories/StudyFactory.php +++ b/GaelO2/database/factories/StudyFactory.php @@ -19,6 +19,7 @@ public function definition() 'documentation_mandatory' => false, 'ancillary_of' => null, 'creatable_patients_investigator' => false, + 'allow_supervisor_upload_dicom' => false ]; } @@ -93,4 +94,13 @@ public function creatablePatientsInvestigator() ]; }); } + + public function allowSupervisorUploadDicom() + { + return $this->state(function (array $attributes) { + return [ + 'allow_supervisor_upload_dicom' => true, + ]; + }); + } } diff --git a/GaelO2/database/migrations/2024_06_11_193737_allow_supervisor_upload_dicom.php b/GaelO2/database/migrations/2024_06_11_193737_allow_supervisor_upload_dicom.php new file mode 100644 index 000000000..90f513951 --- /dev/null +++ b/GaelO2/database/migrations/2024_06_11_193737_allow_supervisor_upload_dicom.php @@ -0,0 +1,28 @@ +boolean('allow_supervisor_upload_dicom')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('studies', function (Blueprint $table) { + $table->dropColumn('allow_supervisor_upload_dicom'); + }); + } +}; diff --git a/GaelO2/tests/Feature/TestStudy/CreateStudyTest.php b/GaelO2/tests/Feature/TestStudy/CreateStudyTest.php index 9435cb022..4713ec7d4 100644 --- a/GaelO2/tests/Feature/TestStudy/CreateStudyTest.php +++ b/GaelO2/tests/Feature/TestStudy/CreateStudyTest.php @@ -24,7 +24,8 @@ protected function setUp(): void 'monitorShowAll' => false, 'documentationMandatory' => false, 'contactEmail' => 'test@gaelo.fr', - 'creatablePatientsInvestigator' => false + 'creatablePatientsInvestigator' => false, + 'allowSupervisorUploadDicom' => false, ]; } diff --git a/GaelO2/tests/Unit/TestRepositories/StudyRepositoryTest.php b/GaelO2/tests/Unit/TestRepositories/StudyRepositoryTest.php index e005f8fd4..443006af7 100644 --- a/GaelO2/tests/Unit/TestRepositories/StudyRepositoryTest.php +++ b/GaelO2/tests/Unit/TestRepositories/StudyRepositoryTest.php @@ -40,6 +40,8 @@ public function testCreateStudy() $this->assertFalse((bool) $studyEntity->documentation_mandatory); $this->assertEquals(null, $studyEntity->ancillary_of); $this->assertFalse((bool) $studyEntity->creatable_patients_investigator); + $this->assertFalse((bool) $studyEntity->allow_supervisor_upload_dicom); + } public function testIsExistingStudy() diff --git a/GaelO2/tests/Unit/TestServices/VisitTreeTest.php b/GaelO2/tests/Unit/TestServices/VisitTreeTest.php index 49da9148d..59f0b8a2e 100644 --- a/GaelO2/tests/Unit/TestServices/VisitTreeTest.php +++ b/GaelO2/tests/Unit/TestServices/VisitTreeTest.php @@ -148,8 +148,8 @@ protected function setUp(): void 'documentation_mandatory' => false, 'ancillary_of' => null, 'deleted_at' => null, - 'creatable_patients_investigator' => false - + 'creatable_patients_investigator' => false, + 'allow_supervisor_upload_dicom' => false ]));