Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fli-iam#1864] Add NIRS type BIDS #1865

Merged
merged 14 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
import org.apache.commons.io.FileUtils;
import org.shanoir.ng.dataset.DatasetDescription;
import org.shanoir.ng.dataset.controler.DatasetApiController.CoordinatesSystem;
import org.shanoir.ng.dataset.modality.BidsDataset;
import org.shanoir.ng.dataset.modality.EegDataSetDescription;
import org.shanoir.ng.dataset.modality.EegDataset;
import org.shanoir.ng.dataset.modality.MrDataset;
import org.shanoir.ng.dataset.modality.MrDatasetNature;
import org.shanoir.ng.dataset.modality.PetDataset;
import org.shanoir.ng.dataset.modality.*;
import org.shanoir.ng.dataset.model.Dataset;
import org.shanoir.ng.dataset.model.DatasetExpression;
import org.shanoir.ng.dataset.model.DatasetExpressionFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public enum BidsDataType {
PET("pet"),

/* Microscopy.*/
MICR("micr");
MICR("micr"),

/* Near-Infrared Spectroscopy */
NIRS("nirs");

private String folderName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public enum DatasetModalityType {
MICR_DATASET(9),

// Behavioural Dataset
BEH_DATASET(10);
BEH_DATASET(10),

// Near-Infrared Spectroscopy dataset
NIRS_DATASET(11);

private int id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,36 +574,70 @@ public boolean hasUpdateRightOnDataset(Dataset dataset, String rightStr) throws
}
}

/**
* Check the connected user has the given right for the given dataset acquisition.
* If the study is updated, check the user has the given right in both former and new studies.
*
* @param datasetAcq the dataset acquisition
* @param rightStr the right
* @return true or false
* @throws EntityNotFoundException
*/
public boolean hasUpdateRightOnDatasetAcquisition(DatasetAcquisition datasetAcq, String rightStr) throws EntityNotFoundException {
youennmerel marked this conversation as resolved.
Show resolved Hide resolved
if (KeycloakUtil.getTokenRoles().contains("ROLE_ADMIN")) {
return true;
}
if (datasetAcq == null) {
throw new IllegalArgumentException("Dataset acquisition cannot be null here.");
}
if (datasetAcq.getId() == null) {
throw new IllegalArgumentException("Dataset acquisition id cannot be null here.");
}
if (datasetAcq.getExamination() == null || datasetAcq.getExamination().getStudyId() == null) {
return false;
}
DatasetAcquisition dbDatasetAcq = datasetAcquisitionRepository.findById(datasetAcq.getId()).orElse(null);
if (dbDatasetAcq == null) {
throw new EntityNotFoundException("Cannot find dataset acquisition with id " + datasetAcq.getId());
}
if (datasetAcq.getExamination().getStudyId() == dbDatasetAcq.getExamination().getStudyId()) { // study hasn't changed
return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr);
} else { // study has changed : check user has right on both studies
return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr) &&
this.hasRightOnStudyCenter(dbDatasetAcq.getExamination().getCenterId(), dbDatasetAcq.getExamination().getStudyId(), rightStr);
}
}

/**
* Check the connected user has the given right for the given dataset acquisition.
* Check the connected user has the given right for the given dataset acquisition DTO.
* If the study is updated, check the user has the given right in both former and new studies.
*
* @param datasetAcq the dataset acquisition
* @param datasetAcqDto the dataset acquisition dto
* @param rightStr the right
* @return true or false
* @throws EntityNotFoundException
*/
public boolean hasUpdateRightOnDatasetAcquisition(DatasetAcquisition datasetAcq, String rightStr) throws EntityNotFoundException {
public boolean hasUpdateRightOnDatasetAcquisitionDTO(DatasetAcquisitionDTO datasetAcqDto, String rightStr) throws EntityNotFoundException {
if (KeycloakUtil.getTokenRoles().contains("ROLE_ADMIN")) {
return true;
}
if (datasetAcq == null) {
if (datasetAcqDto == null) {
throw new IllegalArgumentException("Dataset acquisition cannot be null here.");
}
if (datasetAcq.getId() == null) {
if (datasetAcqDto.getId() == null) {
throw new IllegalArgumentException("Dataset acquisition id cannot be null here.");
}
if (datasetAcq.getExamination() == null || datasetAcq.getExamination().getStudyId() == null) {
if (datasetAcqDto.getExamination() == null || datasetAcqDto.getExamination().getStudyId() == null) {
return false;
}
DatasetAcquisition dbDatasetAcq = datasetAcquisitionRepository.findById(datasetAcq.getId()).orElse(null);
DatasetAcquisition dbDatasetAcq = datasetAcquisitionRepository.findById(datasetAcqDto.getId()).orElse(null);
if (dbDatasetAcq == null) {
throw new EntityNotFoundException("Cannot find dataset acquisition with id " + datasetAcq.getId());
throw new EntityNotFoundException("Cannot find dataset acquisition with id " + datasetAcqDto.getId());
}
if (datasetAcq.getExamination().getStudyId() == dbDatasetAcq.getExamination().getStudyId()) { // study hasn't changed
return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr);
} else { // study has changed : check user has right on both studies
return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr) &&
if (datasetAcqDto.getExamination().getStudyId() == dbDatasetAcq.getExamination().getStudyId()) { // study hasn't changed
return this.hasRightOnStudyCenter(datasetAcqDto.getExamination().getCenterId(), datasetAcqDto.getExamination().getStudyId(), rightStr);
} else { // study has changed : check user has right on both studies
return this.hasRightOnStudyCenter(datasetAcqDto.getExamination().getCenterId(), datasetAcqDto.getExamination().getStudyId(), rightStr) &&
this.hasRightOnStudyCenter(dbDatasetAcq.getExamination().getCenterId(), dbDatasetAcq.getExamination().getStudyId(), rightStr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@
import java.util.Iterator;
import java.util.List;

import org.shanoir.ng.dataset.modality.BidsDataset;
import org.shanoir.ng.dataset.modality.CalibrationDataset;
import org.shanoir.ng.dataset.modality.CtDataset;
import org.shanoir.ng.dataset.modality.EegDataset;
import org.shanoir.ng.dataset.modality.GenericDataset;
import org.shanoir.ng.dataset.modality.MegDataset;
import org.shanoir.ng.dataset.modality.MeshDataset;
import org.shanoir.ng.dataset.modality.MrDataset;
import org.shanoir.ng.dataset.modality.ParameterQuantificationDataset;
import org.shanoir.ng.dataset.modality.PetDataset;
import org.shanoir.ng.dataset.modality.RegistrationDataset;
import org.shanoir.ng.dataset.modality.SegmentationDataset;
import org.shanoir.ng.dataset.modality.SpectDataset;
import org.shanoir.ng.dataset.modality.StatisticalDataset;
import org.shanoir.ng.dataset.modality.TemplateDataset;
import org.shanoir.ng.dataset.modality.*;
import org.shanoir.ng.dataset.model.Dataset;
import org.shanoir.ng.dataset.model.DatasetExpression;
import org.shanoir.ng.dataset.model.DatasetExpressionFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ ResponseEntity<List<DatasetAcquisitionDatasetsDTO>> findDatasetAcquisitionByData
@ApiResponse(responseCode = "500", description = "unexpected error") })
@RequestMapping(value = "/datasetacquisition/{datasetAcquisitionId}", produces = { "application/json" }, consumes = {
"application/json" }, method = RequestMethod.PUT)
@PreAuthorize("hasAnyRole('ADMIN', 'EXPERT') and #datasetAcquisitionId == #datasetAcquisition.getId() and @datasetSecurityService.hasUpdateRightOnDatasetAcquisition(#datasetAcquisition, 'CAN_ADMINISTRATE')")
@PreAuthorize("hasAnyRole('ADMIN', 'EXPERT') and #datasetAcquisitionId == #datasetAcquisition.getId() and @datasetSecurityService.hasUpdateRightOnDatasetAcquisitionDTO(#datasetAcquisition, 'CAN_ADMINISTRATE')")
ResponseEntity<Void> updateDatasetAcquisition(
@Parameter(name = "id of the datasetAcquisition", required = true) @PathVariable("datasetAcquisitionId") Long datasetAcquisitionId,
@Parameter(name = "datasetAcquisition to update", required = true) @Valid @RequestBody DatasetAcquisitionDTO datasetAcquisition, BindingResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import org.shanoir.ng.dataset.service.DatasetUtils;
import org.shanoir.ng.datasetacquisition.dto.DatasetAcquisitionDatasetsDTO;
import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.GenericDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.bids.BidsDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.ct.CtDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.eeg.EegDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.mr.MrDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.pet.PetDatasetAcquisition;
import org.shanoir.ng.examination.dto.mapper.ExaminationMapper;
Expand All @@ -54,8 +57,11 @@ DatasetAcquisitionDatasetsDTO datasetAcquisitionToDatasetAcquisitionDatasetsDTO(
default DatasetAcquisition createDatasetAcquisition(DatasetAcquisitionDatasetsDTO dto) {
if (dto.getType().equals("Mr")) return new MrDatasetAcquisition();
else if (dto.getType().equals("Pet")) return new PetDatasetAcquisition();
else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition();
else throw new IllegalStateException("Cannot map from a dataset acquisition dto that don't provide a valid type. Given type = " + dto.getType());
else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition();
else if (dto.getType().equals("BIDS")) return new BidsDatasetAcquisition();
else if (dto.getType().equals("Eeg")) return new EegDatasetAcquisition();
else if (dto.getType().equals("Generic")) return new GenericDatasetAcquisition();
else throw new IllegalStateException("Cannot map from a dataset acquisition dto that don't provide a valid type. Given type = " + dto.getType());
}

@ObjectFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import org.mapstruct.ObjectFactory;
import org.shanoir.ng.datasetacquisition.dto.DatasetAcquisitionDTO;
import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.GenericDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.bids.BidsDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.ct.CtDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.eeg.EegDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.mr.MrDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.pet.PetDatasetAcquisition;
import org.shanoir.ng.examination.dto.mapper.ExaminationMapper;
Expand All @@ -49,9 +52,12 @@ DatasetAcquisitionDTO datasetAcquisitionToDatasetAcquisitionDTO(

@ObjectFactory
default DatasetAcquisition createDatasetAcquisition(DatasetAcquisitionDTO dto) {
if (dto.getType().equals("Mr")) return new MrDatasetAcquisition();
else if (dto.getType().equals("Pet")) return new PetDatasetAcquisition();
else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition();
if (dto.getType().equals("Mr")) return new MrDatasetAcquisition();
else if (dto.getType().equals("Pet")) return new PetDatasetAcquisition();
else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition();
else if (dto.getType().equals("BIDS")) return new BidsDatasetAcquisition();
else if (dto.getType().equals("Eeg")) return new EegDatasetAcquisition();
else if (dto.getType().equals("Generic")) return new GenericDatasetAcquisition();
else throw new IllegalStateException("Cannot map from a dataset acquisition dto that don't provide a valid type. Given type = " + dto.getType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public void createAllBidsDatasetAcquisition(Message importJobStr) throws AmqpRej
case "micr":
importDataset(importJob, BidsDataType.MICR, DatasetModalityType.MICR_DATASET, event);
break;
case "nirs":
importDataset(importJob, BidsDataType.NIRS, DatasetModalityType.NIRS_DATASET, event);
break;
default:
if (event != null) {
LOG.error("The data type folder is not recognized. Please update your BIDS archive following the rules.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ private void testAll(String role) throws ShanoirException, RestServiceException

// findDatasetAcquisitions(Pageable)
assertThat(api.findDatasetAcquisitions(PageRequest.of(0, 10)).getBody()).hasSize(1);


given(rightsService.hasRightOnStudy(1L, "CAN_ADMINISTRATE")).willReturn(true);
// updateDatasetAcquisition(Long, DatasetAcquisitionDTO, BindingResult)
if ("ROLE_USER".equals(role)) {
assertAccessDenied(api::updateDatasetAcquisition, 1L, mockDsAcqDTO(1L), mockBindingResult);
Expand Down Expand Up @@ -291,6 +292,8 @@ private DatasetAcquisitionDTO mockDsAcqDTO(Long id) {
dto.setId(id);
dto.setAcquisitionEquipmentId(1L);
dto.setExamination(new ExaminationDTO());
dto.getExamination().setStudyId(1L);
dto.getExamination().setCenterId(1L);
dto.setRank(1);
dto.setSoftwareRelease("v1.0.0");
dto.setSortingIndex(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ <h2 class="header command-zone">Create dataset acquisition</h2>
<ng-template [ngSwitchCase]="'view'">
<a [routerLink]="['/study/details/', datasetAcquisition.examination?.study?.id]">
{{datasetAcquisition.examination?.study?.name}}
</a>
</ng-template>
</a>
</ng-template>
</span>
</li>
<li>
Expand All @@ -62,8 +62,8 @@ <h2 class="header command-zone">Create dataset acquisition</h2>
<ng-template [ngSwitchCase]="'view'">
<a [routerLink]="['/examination/details/', datasetAcquisition.examination?.id]">
{{datasetAcquisition.examination?.comment}}
</a>
</ng-template>
</a>
</ng-template>
</span>
</li>
<li>
Expand All @@ -90,10 +90,10 @@ <h2 class="header command-zone">Create dataset acquisition</h2>
<label>Acquisition equipment</label>
<span class="right-col" [ngSwitch]="mode">
<ng-template [ngSwitchCase]="'view'">
<a [routerLink]="['/acquisition-equipment/details/', datasetAcquisition.acquisitionEquipment?.id]">
<a *ngIf="datasetAcquisition.acquisitionEquipment?.id" [routerLink]="['/acquisition-equipment/details/', datasetAcquisition.acquisitionEquipment.id]">
{{datasetAcquisition.acquisitionEquipment | acqEqptLabel}}
</a>
</ng-template>
</ng-template>
<ng-template ngSwitchDefault>
<select-box formControlName="acq-eq" [(ngModel)]="datasetAcquisition.acquisitionEquipment" [optionArr]="acquisitionEquipments" [pipe]="acqEqPipe">
</select-box>
Expand Down Expand Up @@ -143,11 +143,11 @@ <h2 class="header command-zone">Create dataset acquisition</h2>

<fieldset *ngIf="mode=='view'">
<legend i18n="Examination data|Title@@examinationDetailDataTitle">Data</legend>
<dataset-acquisition-node
[input]="acquisitionNode"
<dataset-acquisition-node
[input]="acquisitionNode"
(nodeInit)="onNodeInit($event)"></dataset-acquisition-node >
</fieldset>

<form-footer
[state]="footerState"
(save)="save()"
Expand All @@ -158,4 +158,4 @@ <h2 class="header command-zone">Create dataset acquisition</h2>
></form-footer>
</div>
</form>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* Shanoir NG - Import, manage and share neuroimaging data
* Copyright (C) 2009-2019 Inria - https://www.inria.fr/
* Contact us on https://project.inria.fr/shanoir/
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html
*/
Expand Down Expand Up @@ -46,13 +46,17 @@ export class DatasetAcquisitionDTOService {
* Warning : DO NOT USE THIS IN A LOOP, use toDatasetAcquisitions instead
* @param result can be used to get an immediate temporary result without async data
*/
public toDatasetAcquisition(dto: DatasetAcquisitionDTO, result?: DatasetAcquisition): Promise<DatasetAcquisition> {
public toDatasetAcquisition(dto: DatasetAcquisitionDTO, result?: DatasetAcquisition): Promise<DatasetAcquisition> {
if (!result) result = DatasetAcquisitionUtils.getNewDAInstance(dto.type);
DatasetAcquisitionDTOService.mapSyncFields(dto, result);
return Promise.all([
this.acqEqService.get(dto.acquisitionEquipmentId).then(acqEq => result.acquisitionEquipment = acqEq), // TODO dto
this.studyService.get(dto.examination.studyId).then(study => result.examination.study = study) // TODO dto
]).then(([]) => {
let promises = [];
if(dto.acquisitionEquipmentId > 0){
promises.push(this.acqEqService.get(dto.acquisitionEquipmentId).then(acqEq => result.acquisitionEquipment = acqEq));
}else{
result.acquisitionEquipment = new AcquisitionEquipment();
}
promises.push( this.studyService.get(dto.examination.studyId).then(study => result.examination.study = study));
return Promise.all(promises).then(([]) => {
return result;
});
}
Expand All @@ -66,10 +70,6 @@ export class DatasetAcquisitionDTOService {
for (let dto of dtos ? dtos : []) {
let entity = DatasetAcquisitionUtils.getNewDAInstance(dto.type);
DatasetAcquisitionDTOService.mapSyncFields(dto, entity);
if (dto.acquisitionEquipmentId) {
entity.acquisitionEquipment = new AcquisitionEquipment();
entity.acquisitionEquipment.id = dto.acquisitionEquipmentId;
}
if ((dto as DatasetAcquisitionDatasetsDTO).datasets) {
entity.datasets = (dto as DatasetAcquisitionDatasetsDTO).datasets.map(dsdto => {
let simpleDataset: Dataset = DatasetUtils.getDatasetInstance(dsdto.type);
Expand Down Expand Up @@ -102,6 +102,10 @@ export class DatasetAcquisitionDTOService {
entity.sortingIndex = dto.sortingIndex;
entity.type = dto.type;
entity.creationDate = dto.creationDate;
if (dto.acquisitionEquipmentId) {
entity.acquisitionEquipment = new AcquisitionEquipment();
entity.acquisitionEquipment.id = dto.acquisitionEquipmentId;
}
if (dto.examination) {
entity.examination = new Examination();
ExaminationDTOService.mapSyncFields(dto.examination, entity.examination);
Expand Down Expand Up @@ -136,7 +140,7 @@ export class DatasetAcquisitionDTO {
}
this.acquisitionEquipmentId = dsAcq.acquisitionEquipment ? dsAcq.acquisitionEquipment.id : null;
if (dsAcq.examination) {
this.examination = new ExaminationDTO();
this.examination = new ExaminationDTO();
this.examination.id = dsAcq.examination.id;
}
this.rank = dsAcq.rank;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* Shanoir NG - Import, manage and share neuroimaging data
* Copyright (C) 2009-2019 Inria - https://www.inria.fr/
* Contact us on https://project.inria.fr/shanoir/
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html
*/
Expand All @@ -31,9 +31,10 @@ export enum DatasetType {
Statistical = 'Statistical',
Template = 'Template',
BIDS = 'BIDS',
NIRS = 'NIRS',
michaelkain marked this conversation as resolved.
Show resolved Hide resolved
Measurement = 'Measurement'
} export namespace DatasetType {

export function all(): Array<DatasetType> {
return allOfEnum<DatasetType>(DatasetType);
}
Expand Down
Loading