Skip to content

Commit

Permalink
Merge pull request #735 from Pixilib/GaelO2-dev
Browse files Browse the repository at this point in the history
Gael o2 dev
  • Loading branch information
salimkanoun authored Dec 21, 2024
2 parents b4d7bb8 + caeb99e commit 769fe28
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 17 deletions.
2 changes: 2 additions & 0 deletions GaelO2/app/GaelO/Constants/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 6 additions & 7 deletions GaelO2/app/GaelO/Services/ImportPatientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
};
}
Expand Down Expand Up @@ -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');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class ModifyVisitDateRequest
public string $studyName;
public int $visitId;
public string $visitDate;
public string $reason;
}
2 changes: 1 addition & 1 deletion GaelO2/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
| or any other location as required by the application or its packages.
*/

'version' => '2.7.3',
'version' => '2.8.0',

/*
|--------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions GaelO2/tests/Feature/TestPatients/ImportPatientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 21 additions & 3 deletions GaelO2/tests/Feature/TestVisits/ModifyVisitDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

0 comments on commit 769fe28

Please sign in to comment.