Skip to content

Commit

Permalink
Merge pull request #1930 from michaelkain/auto-test-import
Browse files Browse the repository at this point in the history
ShUp: new version v8.0.0 (after refactor) final fixes
  • Loading branch information
michaelkain authored Feb 1, 2024
2 parents 5aef3b3 + 049276a commit 58841db
Show file tree
Hide file tree
Showing 82 changed files with 1,349 additions and 765 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;

import org.shanoir.ng.shared.dateTime.LocalDateAnnotations;
import org.shanoir.ng.shared.dicom.EquipmentDicom;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,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 @@ -14,26 +14,34 @@

package org.shanoir.ng.studycard.model.condition;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.List;

import org.hibernate.annotations.Check;
import org.hibernate.annotations.GenericGenerator;
import org.shanoir.ng.shared.core.model.AbstractEntity;
import org.shanoir.ng.studycard.model.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorType;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.validation.constraints.NotNull;

@Entity
@Check(constraints = "(dicomTag IS NOT NULL AND shanoirField IS NULL) OR (dicomTag IS NULL AND shanoirField IS NOT NULL)")
@GenericGenerator(name = "IdOrGenerate", strategy = "org.shanoir.ng.shared.model.UseIdOrGenerate")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="scope", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorColumn(name="scope", discriminatorType = DiscriminatorType.STRING, length = 47)
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "scope")
@JsonSubTypes({
@JsonSubTypes.Type(value = StudyCardDICOMConditionOnDatasets.class, name = "StudyCardDICOMConditionOnDatasets"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class RabbitMqStudyCardService {
private StudyCardRepository studyCardService;

@Autowired
ObjectMapper mapper;
private ObjectMapper mapper;

@RabbitListener(queues = RabbitMQConfiguration.FIND_STUDY_CARD_QUEUE)
@RabbitHandler
Expand All @@ -59,10 +59,9 @@ public String findStudyCard(String message) {
public Long getBestStudyCard(String message) {
try {
Properties properties = mapper.readValue(message, Properties.class);
String equipmentId = String.valueOf(properties.getProperty("EQUIPMENT_ID_PROPERTY"));
Long equipmentId = Long.valueOf(properties.getProperty("EQUIPMENT_ID_PROPERTY"));
Long studyId = Long.valueOf(properties.getProperty("STUDY_ID_PROPERTY"));
Long studyCardId = Long.valueOf(properties.getProperty("STUDYCARD_ID_PROPERTY"));

List<StudyCard> studyCards = this.studyCardService.findByStudyId(studyId);
for (StudyCard sc : studyCards) {
if (sc.getAcquisitionEquipmentId().equals(equipmentId)) {
Expand All @@ -74,4 +73,5 @@ public Long getBestStudyCard(String message) {
throw new AmqpRejectAndDontRequeueException(e);
}
}

}
2 changes: 1 addition & 1 deletion shanoir-ng-datasets/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html
<appender-ref ref="DIMSE_FILE_LOG" />
</logger>


<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="CONSOLE" />
</root>

</configuration>
32 changes: 1 addition & 31 deletions shanoir-ng-datasets/src/main/resources/scripts/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,4 @@ VALUES
INSERT INTO study_cards
(id, acquisition_equipment_id, disabled, last_edit_timestamp, name, nifti_converter_id, study_id)
VALUES
(1,1,false,0,'StudyCard1',1,1),
(2,null,false,0,'QualityCard_UCAN',null,1);

INSERT INTO study_card_rule
(id, study_card_id, scope,or_conditions)
VALUES
(1,2,'DatasetAcquisition',false),
(2,2,'Dataset',false);

INSERT INTO study_card_condition
(id, dicom_tag, operation, scope, cardinality)
VALUES
(1,2,4,'StudyCardDICOMCondition', 1),
(2,2,4,'StudyCardDICOMCondition', 1);

INSERT INTO study_card_condition_join
(study_card_rule_id, condition_id)
VALUES
(1,1),
(2,2);

INSERT INTO study_card_condition_values
(study_card_condition_id, value)
VALUES
(1,'tof'),
(1,'flight'),
(2,'gado'),
(2,'gd'),
(2,'gadolinium'),
(2,'contrast'),
(2,'enhanced');
(1,1,false,0,'StudyCard1',1,1);
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String calculateIdentifierWithHashs(final String firstNameHash, final Str
* @throws NoSuchAlgorithmException
* @throws UnsupportedEncodingException
*/
public String calculateIdentifier(final String firstName, final String lastName, final Date birthDate) throws NoSuchAlgorithmException, UnsupportedEncodingException {
public String calculateIdentifier(final String firstName, final String lastName, final String birthDate) throws NoSuchAlgorithmException, UnsupportedEncodingException {
final String subjectIdentifierSeed = firstName + lastName + birthDate;
String hex = calculateSHA(subjectIdentifierSeed);
return hex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Assert;
import org.junit.Before;
Expand All @@ -26,25 +23,10 @@ public class IdentifierCalculatorTest {
private static final String FIRST_NAME = "firstName";

private static final String LAST_NAME = "lastName";

private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

private Date birthDate;

@SuppressWarnings("deprecation")
@Before
public void setup() {
identifierCalculator = new IdentifierCalculator();
try {
birthDate = sdf.parse("01/01/2020");
/**
* This behaviour is strange and is there to produce the same result
* as when using the Web GUI of sh-old, where 01:00:00 is set programmatically
* in the backend, even if not entered by the user, maybe because of time zone problems.
*/
birthDate.setHours(1);
} catch (ParseException e) {
}
}

@Test
Expand All @@ -57,9 +39,9 @@ public void testCalculateIdentifierWithHashs() throws UnsupportedEncodingExcepti

@Test
public void testCalculateIdentifier() throws UnsupportedEncodingException, NoSuchAlgorithmException {
String subjectIdentifier = identifierCalculator.calculateIdentifier(FIRST_NAME, LAST_NAME, birthDate);
String subjectIdentifier = identifierCalculator.calculateIdentifier(FIRST_NAME, LAST_NAME, "01/01/2020");
// Values have been acquired during tests with master sh-old
// Assert.assertEquals("AC-844A74B6-74", subjectIdentifier);
Assert.assertEquals("AB-859C-100131", subjectIdentifier);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

package org.shanoir.ng.importer;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.shanoir.ng.exchange.model.Exchange;
import org.shanoir.ng.importer.dicom.query.DicomQuery;
import org.shanoir.ng.importer.model.EegImportJob;
import org.shanoir.ng.importer.model.ImportJob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public ResponseEntity<ImportJob> queryPACS(
importJob.setWorkFolder("");
importJob.setFromPacs(true);
importJob.setUserId(KeycloakUtil.getTokenUserId());
} catch (ShanoirException e) {
} catch (Exception e) {
throw new RestServiceException(
new ErrorModel(HttpStatus.UNPROCESSABLE_ENTITY.value(), e.getMessage(), null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ private void downloadAndMoveDicomFilesToImportJobDir(final File importJobDir, Li
event.setMessage("Downloading DICOM files from PACS for serie [" + (serie.getProtocolName() == null ? serie.getSeriesInstanceUID() : serie.getProtocolName()) + "] (" + cpt + "/" + nbSeries + ")");
eventService.publishEvent(event);

queryPACSService.queryCMOVE(serie);
String serieID = serie.getSeriesInstanceUID();
File serieIDFolderDir = new File(importJobDir + File.separator + serieID);
String studyInstanceUID = study.getStudyInstanceUID();
String seriesInstanceUID = serie.getSeriesInstanceUID();
queryPACSService.queryCMOVE(studyInstanceUID, seriesInstanceUID);
File serieIDFolderDir = new File(importJobDir + File.separator + seriesInstanceUID);

if(!serieIDFolderDir.exists()) {
serieIDFolderDir.mkdirs();
Expand All @@ -327,9 +328,9 @@ private void downloadAndMoveDicomFilesToImportJobDir(final File importJobDir, Li
for (Iterator<Instance> iterator = serie.getInstances().iterator(); iterator.hasNext();) {
Instance instance = iterator.next();
String sopInstanceUID = instance.getSopInstanceUID();
File oldFile = new File(dicomStoreSCPServer.getStorageDirPath() + File.separator + serieID + File.separator + sopInstanceUID + DicomStoreSCPServer.DICOM_FILE_SUFFIX);
File oldFile = new File(dicomStoreSCPServer.getStorageDirPath() + File.separator + seriesInstanceUID + File.separator + sopInstanceUID + DicomStoreSCPServer.DICOM_FILE_SUFFIX);
if (oldFile.exists()) {
File newFile = new File(importJobDir.getAbsolutePath() + File.separator + serieID + File.separator + oldFile.getName());
File newFile = new File(importJobDir.getAbsolutePath() + File.separator + seriesInstanceUID + File.separator + oldFile.getName());
oldFile.renameTo(newFile);
LOG.debug("Moving file: {} to ", oldFile.getAbsolutePath(), newFile.getAbsolutePath());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

package org.shanoir.ng.importer.dcm2nii;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.NotBlank;
import org.shanoir.ng.shared.hateoas.HalEntity;
Expand All @@ -25,6 +22,9 @@

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;

/**
* The class NIfTIConverter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.v3.oas.annotations.tags.Tag;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
* @author yyao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.shanoir.ng.utils.ImportUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* This class is a helper class, that will in the future be used to detect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.dcm4che3.data.UID;
import org.dcm4che3.emf.MultiframeExtractor;
import org.dcm4che3.io.DicomInputStream;
import org.shanoir.ng.importer.model.EquipmentDicom;
import org.shanoir.ng.importer.model.Image;
import org.shanoir.ng.importer.model.Instance;
import org.shanoir.ng.importer.model.InstitutionDicom;
Expand All @@ -38,6 +37,7 @@
import org.shanoir.ng.importer.model.Study;
import org.shanoir.ng.shared.dateTime.DateTimeUtils;
import org.shanoir.ng.shared.dicom.EchoTime;
import org.shanoir.ng.shared.dicom.EquipmentDicom;
import org.shanoir.ng.shared.event.ShanoirEvent;
import org.shanoir.ng.shared.event.ShanoirEventService;
import org.slf4j.Logger;
Expand Down Expand Up @@ -213,7 +213,7 @@ public File getFileFromInstance(Instance instance, Serie serie, String folderFil
return instanceFile;
} else {
throw new FileNotFoundException(
"instanceFilePath in DicomDir: missing file: " + instanceFilePath);
"instanceFilePath: missing file: " + instanceFilePath);
}
}

Expand Down
Loading

0 comments on commit 58841db

Please sign in to comment.