Skip to content

Commit

Permalink
MS Studies: adds find equipment by serial number to API + some clean …
Browse files Browse the repository at this point in the history
…ups + ShUp: add new endpoint
  • Loading branch information
michaelkain committed Nov 2, 2023
1 parent f2f2e66 commit 042e2ec
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void importDataset(ImportJob importJob, BidsDataType bidsDataType, Datas

Map<String, BidsDataset> datasetsByName = new HashMap<>();

Map<String, Integer> equipments = objectMapper.readValue((String) this.rabbitTemplate.convertSendAndReceive(RabbitMQConfiguration.ACQUISITION_EQUIPEMENT_CODE_QUEUE, "all"), Map.class);
Map<String, Integer> equipments = objectMapper.readValue((String) this.rabbitTemplate.convertSendAndReceive(RabbitMQConfiguration.ACQUISITION_EQUIPMENT_CODE_QUEUE, "all"), Map.class);
Long equipmentId = 0L;

for (File importedFile : filesToImport) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ public class RabbitMQConfiguration {
/** Queue to retrieve informations about studyc cards. */
public static final String FIND_STUDY_CARD_QUEUE = "find-study-card-queue";

/** Queue to retrieve the center ID from an acquisition equipement ID. */
public static final String ACQUISITION_EQUIPEMENT_CENTER_QUEUE = "acquisition-equipement-center-queue";
/** Queue to retrieve the center ID from an acquisition equipement ID. */
public static final String ACQUISITION_EQUIPEMENT_UPDATE_QUEUE = "acquisition-equipement-update-queue";
/** Queue to retrieve the center ID from an acquisition equipment ID. */
public static final String ACQUISITION_EQUIPMENT_CENTER_QUEUE = "acquisition-equipment-center-queue";

/** Queue to retrieve the center ID from an acquisition equipment ID. */
public static final String ACQUISITION_EQUIPEMENT_UPDATE_QUEUE = "acquisition-equipment-update-queue";

/** Queue to create exam for import bids. */
public static final String EXAMINATION_CREATION_QUEUE = "examination-creation-queue";
Expand Down Expand Up @@ -140,7 +141,7 @@ public class RabbitMQConfiguration {
public static final String IMPORTER_BIDS_DATASET_QUEUE = "importer-bids-dataset-queue";

/** Queue to create get equipment ID from code. */
public static final String ACQUISITION_EQUIPEMENT_CODE_QUEUE = "acquisition-equipment-code-queue";
public static final String ACQUISITION_EQUIPMENT_CODE_QUEUE = "acquisition-equipment-code-queue";

/** Queue to get the study card from a equipment code. */
public static final String IMPORT_STUDY_CARD_QUEUE="import-study-card-queue";
Expand Down Expand Up @@ -169,31 +170,6 @@ public class RabbitMQConfiguration {
/** Queue used to get anonymisation profile of a study. */
public static final String STUDY_ANONYMISATION_PROFILE_QUEUE = "study-anonymisation-profile-queue";

////////// IN / OUT THINGS (to be comented to make it clearer) /////////
private static final String ACQ_EQPT_QUEUE_NAME_OUT = "acq_eqpt_queue_from_ng";

private static final String CENTER_QUEUE_NAME_OUT = "center_queue_from_ng";

private static final String COIL_QUEUE_NAME_OUT = "coil_queue_from_ng";

private static final String DELETE_ACQ_EQPT_QUEUE_NAME_OUT = "delete_acq_eqpt_queue_from_ng";

private static final String DELETE_CENTER_QUEUE_NAME_OUT = "delete_center_queue_from_ng";

private static final String DELETE_COIL_QUEUE_NAME_OUT = "delete_coil_queue_from_ng";

private static final String STUDY_QUEUE_NAME_IN = "study_queue_to_ng";

private static final String STUDY_DELETE_QUEUE_NAME_IN = "study_delete_queue_to_ng";

private static final String STUDY_QUEUE_NAME_OUT = "study_queue_from_ng";

private static final String SUBJECT_RPC_QUEUE_OUT = "subject_queue_with_RPC_from_ng";

private static final String SUBJECT_RPC_QUEUE_IN = "subject_queue_with_RPC_to_ng";

private static final String SUBJECT_QUEUE_OUT = "subject_queue_from_ng";

////////////////// EXCHANGES //////////////////

/** Exchange used to publish / treat all sort of shanoir events. */
Expand Down Expand Up @@ -317,7 +293,7 @@ public static Queue findStudyCardQueue() {

@Bean
public static Queue acquisitionEquipementCenterQueue() {
return new Queue(ACQUISITION_EQUIPEMENT_CENTER_QUEUE, true);
return new Queue(ACQUISITION_EQUIPMENT_CENTER_QUEUE, true);
}
@Bean
public static Queue acquisitionEquipementUpdateQueue() {
Expand Down Expand Up @@ -376,7 +352,7 @@ public static Queue importBidsDatasetQueue() {

@Bean
public static Queue acquisitionEquipmentCodeQueue() {
return new Queue(ACQUISITION_EQUIPEMENT_CODE_QUEUE, true);
return new Queue(ACQUISITION_EQUIPMENT_CODE_QUEUE, true);
}

@Bean
Expand All @@ -403,10 +379,6 @@ public static Queue studyInvitationQueue() {
public static Queue importStudyCardQueue() {
return new Queue(IMPORT_STUDY_CARD_QUEUE, true);
}
@Bean
public static Queue equipmentFromCodeQueue() {
return new Queue(EQUIPMENT_FROM_CODE_QUEUE, true);
}

@Bean
public static Queue studyAdminQueue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ ResponseEntity<Void> deleteAcquisitionEquipment(
ResponseEntity<AcquisitionEquipmentDTO> findAcquisitionEquipmentById(
@Parameter(name = "id of the acquisition equipment", required = true) @PathVariable("acquisitionEquipmentId") Long acquisitionEquipmentId);

@Operation(summary = "", description = "If exists, returns the acquisition equipments corresponding to the given serial number")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "found acquisition equipment"),
@ApiResponse(responseCode = "204", description = "no acquisition equipment found"),
@ApiResponse(responseCode = "401", description = "unauthorized"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "500", description = "unexpected error") })
@RequestMapping(value = "/bySerialNumber/{serialNumber}", produces = { "application/json" }, method = RequestMethod.GET)
@PreAuthorize("hasAnyRole('USER', 'ADMIN', 'EXPERT')")
ResponseEntity<List<AcquisitionEquipmentDTO>> findAcquisitionEquipmentsBySerialNumber(
@Parameter(name = "serial number of the acquisition equipment", required = true) @PathVariable("serialNumber") String serialNumber);

@Operation(summary = "", description = "Returns all the acquisition equipments for a center")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "found acquisition equipments"),
Expand All @@ -83,7 +95,6 @@ ResponseEntity<AcquisitionEquipmentDTO> findAcquisitionEquipmentById(
@PreAuthorize("hasAnyRole('USER', 'ADMIN', 'EXPERT')")
ResponseEntity<List<AcquisitionEquipmentDTO>> findAcquisitionEquipmentsByStudy(@Parameter(name = "id of the study", required = true) @PathVariable("studyId") Long studyId);


@Operation(summary = "", description = "Returns all the acquisition equipments")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "found acquisition equipments"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,18 @@ private void checkDataIntegrityException(DataIntegrityViolationException e, Acqu
}
}
}

@Override
public ResponseEntity<List<AcquisitionEquipmentDTO>> findAcquisitionEquipmentsBySerialNumber(
@Parameter(name = "serial number of the acquisition equipment", required = true) @PathVariable("serialNumber") final String serialNumber) {
List<AcquisitionEquipment> equipments = acquisitionEquipmentService.findAll();
// Remove "unknown" equipment
equipments = equipments.stream().filter(equipment -> equipment.getId() != 0).collect(Collectors.toList());
if (equipments.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(
acquisitionEquipmentMapper.acquisitionEquipmentsToAcquisitionEquipmentDTOs(equipments), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface AcquisitionEquipmentRepository extends CrudRepository<Acquisiti

List<AcquisitionEquipment> findByCenterStudyCenterListStudyId(Long studyId);

AcquisitionEquipment findBySerialNumber(String serialNumber);
List<AcquisitionEquipment> findBySerialNumber(String serialNumber);

List<AcquisitionEquipment> findByManufacturerModelId(Long manufacturerModelId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ public interface AcquisitionEquipmentService {

List<AcquisitionEquipment> findAllByStudyId(Long studyId);

List<AcquisitionEquipment> findAllBySerialNumber(String serialNumber);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@
import java.util.List;
import java.util.Optional;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.shanoir.ng.acquisitionequipment.model.AcquisitionEquipment;
import org.shanoir.ng.acquisitionequipment.repository.AcquisitionEquipmentRepository;
import org.shanoir.ng.center.model.Center;
import org.shanoir.ng.center.service.CenterServiceImpl;
import org.shanoir.ng.shared.configuration.RabbitMQConfiguration;
import org.shanoir.ng.shared.core.model.IdName;
import org.shanoir.ng.shared.exception.EntityNotFoundException;
import org.shanoir.ng.utils.Utils;
import org.shanoir.ng.shared.exception.MicroServiceCommunicationException;
import org.shanoir.ng.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Acquisition equipment service implementation.
*
Expand All @@ -54,6 +53,7 @@ public class AcquisitionEquipmentServiceImpl implements AcquisitionEquipmentServ
private ObjectMapper objectMapper;

private static final Logger LOG = LoggerFactory.getLogger(AcquisitionEquipmentServiceImpl.class);

@Override
public Optional<AcquisitionEquipment> findById(final Long id) {
return repository.findById(id);
Expand All @@ -78,6 +78,10 @@ public List<AcquisitionEquipment> findAllByStudyId(Long studyId) {
return this.repository.findByCenterStudyCenterListStudyId(studyId);
}

public List<AcquisitionEquipment> findAllBySerialNumber(String serialNumber) {
return this.repository.findBySerialNumber(serialNumber);
}

public AcquisitionEquipment create(AcquisitionEquipment entity) {
AcquisitionEquipment newDbAcEq = repository.save(entity);
String datasetAcEqName = newDbAcEq.getManufacturerModel().getManufacturer().getName().trim() + " " + newDbAcEq.getManufacturerModel().getName().trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
public class RabbitMqCenterService {

@Autowired
private AcquisitionEquipmentRepository acquisitionEquipementService;
private AcquisitionEquipmentRepository acquisitionEquipmentService;

@Autowired
private ObjectMapper mapper;

@RabbitListener(queues = RabbitMQConfiguration.ACQUISITION_EQUIPEMENT_CENTER_QUEUE)
@RabbitListener(queues = RabbitMQConfiguration.ACQUISITION_EQUIPMENT_CENTER_QUEUE)
@RabbitHandler
@Transactional
public String findCenterIdFromAcquisitionEquipement(String message) {
public String findCenterIdFromAcquisitionEquipment(String message) {
try {
AcquisitionEquipment ae = acquisitionEquipementService.findById(Long.valueOf(message)).orElse(null);
AcquisitionEquipment ae = acquisitionEquipmentService.findById(Long.valueOf(message)).orElse(null);
if (ae == null) {
return null;
} else {
Expand All @@ -61,12 +61,12 @@ public String findCenterIdFromAcquisitionEquipement(String message) {
}
}

@RabbitListener(queues = RabbitMQConfiguration.ACQUISITION_EQUIPEMENT_CODE_QUEUE)
@RabbitListener(queues = RabbitMQConfiguration.ACQUISITION_EQUIPMENT_CODE_QUEUE)
@RabbitHandler
@Transactional
public String findAcquisitionEquipements(String message) {
public String findAcquisitionEquipments(String message) {
try {
List<AcquisitionEquipment> aes = Utils.toList(acquisitionEquipementService.findAll());
List<AcquisitionEquipment> aes = Utils.toList(acquisitionEquipmentService.findAll());
Map<String, Long> easMap = new HashMap<>();
for (AcquisitionEquipment ae : aes) {
if (ae.getSerialNumber() != null) {
Expand All @@ -84,14 +84,14 @@ public String findAcquisitionEquipements(String message) {
@Transactional
public Long getEquipmentFromCode(String message) {
try {

AcquisitionEquipment equip = this.acquisitionEquipementService.findBySerialNumber(message);
if (equip == null) {
return null;
}
return equip.getId();
List<AcquisitionEquipment> equipList = acquisitionEquipmentService.findBySerialNumber(message);
if (equipList == null && equipList.isEmpty()) {
return null;
}
return equipList.get(0).getId();
} catch (Exception e) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.log4j.Logger;
import org.shanoir.uploader.ShUpConfig;
import org.shanoir.uploader.dicom.MRI;
import org.shanoir.uploader.dicom.query.SerieTreeNode;
import org.shanoir.uploader.gui.ImportDialog;
import org.shanoir.uploader.gui.MainWindow;
import org.shanoir.uploader.model.rest.AcquisitionEquipment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class ShanoirUploaderServiceClient {

private static final String SERVICE_ACQUISITION_EQUIPMENTS = "service.acquisition.equipments";

private static final String SERVICE_ACQUISITION_EQUIPMENTS_BY_SERIAL_NUMBER = "service.acquisition.equipments.by.serial.number";

private static final String SERVICE_MANUFACTURER_MODELS = "service.manufacturer.models";

private static final String SERVICE_MANUFACTURERS = "service.manufacturers";
Expand Down Expand Up @@ -109,6 +111,8 @@ public class ShanoirUploaderServiceClient {

private String serviceURLAcquisitionEquipments;

private String serviceURLAcquisitionEquipmentsBySerialNumber;

private String serviceURLManufacturerModels;

private String serviceURLManufacturers;
Expand Down Expand Up @@ -164,6 +168,8 @@ public ShanoirUploaderServiceClient() {
+ ShUpConfig.endpointProperties.getProperty(SERVICE_CENTERS_CREATE);
this.serviceURLAcquisitionEquipments = this.serverURL
+ ShUpConfig.endpointProperties.getProperty(SERVICE_ACQUISITION_EQUIPMENTS);
this.serviceURLAcquisitionEquipmentsBySerialNumber = this.serverURL
+ ShUpConfig.endpointProperties.getProperty(SERVICE_ACQUISITION_EQUIPMENTS_BY_SERIAL_NUMBER);
this.serviceURLManufacturerModels = this.serverURL
+ ShUpConfig.endpointProperties.getProperty(SERVICE_MANUFACTURER_MODELS);
this.serviceURLManufacturers = this.serverURL
Expand Down
1 change: 1 addition & 0 deletions shanoir-uploader/src/main/resources/endpoint.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ service.studycards.find.by.study.ids=/shanoir-ng/datasets/studycards/search
service.studycards.apply.on.study=/shanoir-ng/datasets/studycards/apply_on_study/
service.centers.create=/shanoir-ng/studies/centers
service.acquisition.equipments=/shanoir-ng/studies/acquisitionequipments
service.acquisition.equipments.by.serial.number=/shanoir-ng/studies/acquisitionequipments/bySerialNumber/
service.manufacturer.models=/shanoir-ng/studies/manufacturermodels
service.manufacturers=/shanoir-ng/studies/manufacturers
service.subjects.find.by.identifier=/shanoir-ng/studies/subjects/findByIdentifier/
Expand Down

0 comments on commit 042e2ec

Please sign in to comment.