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

shanoir-issue#2372: add endpoint to remove SR from viewer #2403

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
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 @@ -8,12 +8,15 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.shanoir.ng.datasetacquisition.dto.DatasetAcquisitionDatasetsDTO;
import org.shanoir.ng.shared.exception.RestServiceException;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -170,6 +173,20 @@ ResponseEntity<String> findInstancesOfStudy(
@PreAuthorize("hasAnyRole('ADMIN', 'EXPERT', 'USER')")
ResponseEntity<Void> stow(HttpServletRequest request) throws RestServiceException;

@Operation(summary = "", description = "Delete the structured report")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "found series/acquisitions"),
@ApiResponse(responseCode = "204", description = "no serie/acquisition found"),
@ApiResponse(responseCode = "401", description = "unauthorized"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "500", description = "unexpected error") })
@RequestMapping(value = "/studies/{examinationUID}/series/{seriesInstanceUID}/reject/{reject}", method=RequestMethod.POST)
@PreAuthorize("hasAnyRole('ADMIN', 'EXPERT', 'USER')")
ResponseEntity<Void> deleteSEGAndSR(
@Parameter(description = "examinationUID", required = true) @PathVariable("examinationUID") String examinationUID,
@Parameter(description = "seriesInstanceUID", required = true) @PathVariable("seriesInstanceUID") String seriesInstanceUID,
@Parameter(description = "reject", required = true) @PathVariable("reject") String reject
) throws RestServiceException;

// @GET
// @NoCache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.shanoir.ng.dicom.web.service.DICOMWebService;
import org.shanoir.ng.examination.model.Examination;
import org.shanoir.ng.examination.service.ExaminationService;
import org.shanoir.ng.importer.service.DicomSEGAndSRImporterService;
import org.shanoir.ng.shared.exception.RestServiceException;
import org.shanoir.ng.utils.SecurityContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -65,9 +67,12 @@ public class DICOMWebApiController implements DICOMWebApi {
@Autowired
private SeriesInstanceUIDHandler seriesInstanceUIDHandler;

@Autowired
private DicomSEGAndSRImporterService dicomSRImporterService;

@Autowired
private ObjectMapper mapper;

@Override
public ResponseEntity<String> findPatients() throws RestServiceException {
return null;
Expand Down Expand Up @@ -264,5 +269,15 @@ public ResponseEntity<String> findInstancesOfStudy(String studyInstanceUID) thro
public ResponseEntity<Void> stow(HttpServletRequest request) throws RestServiceException {
return null;
}

}

@Override
public ResponseEntity<Void> deleteSEGAndSR(String examinationIdStr, String seriesInstanceUid, String reject) {
Long examinationId = studyInstanceUIDHandler.extractExaminationId(examinationIdStr);
SecurityContextUtil.initAuthenticationContext("ROLE_ADMIN");
michaelkain marked this conversation as resolved.
Show resolved Hide resolved
if (examinationId != null && seriesInstanceUid != null) {
dicomSRImporterService.deleteSR(examinationId, seriesInstanceUid);
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String findSeriesInstanceUIDFromCacheOrDatabase(String acquisitionUID) {
return seriesInstanceUID;
}

private String findSeriesInstanceUID(DatasetAcquisition acquisition) {
public String findSeriesInstanceUID(DatasetAcquisition acquisition) {
if (acquisition instanceof MrDatasetAcquisition
|| acquisition instanceof CtDatasetAcquisition
|| acquisition instanceof PetDatasetAcquisition) {
Expand Down Expand Up @@ -99,6 +99,26 @@ private String findSeriesInstanceUID(DatasetAcquisition acquisition) {
return null;
}

public String findSeriesInstanceUID(Dataset ds) {
List<DatasetExpression> expressions = ds.getDatasetExpressions();
if (!expressions.isEmpty()) {
for (DatasetExpression expression : expressions) {
// only DICOM is of interest here
if (expression.getDatasetExpressionFormat().equals(DatasetExpressionFormat.DICOM)) {
List<DatasetFile> files = expression.getDatasetFiles();
if (!files.isEmpty()) {
DatasetFile file = files.get(0);
if (file.isPacs()) {
String path = file.getPath();
return findSeriesInstanceUID(path);
}
}
}
}
}
return null;
}

private String findSeriesInstanceUID(String path) {
Pattern p = Pattern.compile(WADO_URI_SERIES_UID_OBJECT_UID);
Matcher m = p.matcher(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) request;
if (httpRequest.getMethod().equals(HttpMethod.POST.toString())
&& httpRequest.getRequestURI().contains(DICOMWEB_STUDIES)
&& httpRequest.getContentType() != null
&& httpRequest.getContentType().contains(MediaType.MULTIPART_RELATED_VALUE)) {
try(ByteArrayInputStream bIS = new ByteArrayInputStream(httpRequest.getInputStream().readAllBytes())) {
ByteArrayDataSource datasource = new ByteArrayDataSource(bIS, MediaType.MULTIPART_RELATED_VALUE);
Expand All @@ -92,5 +94,4 @@ public void doFilter(
}
chain.doFilter(request, response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public String findStudyInstanceUIDFromCacheOrDatabase(String examinationUID) {
* @param examination
* @return
*/
private String findStudyInstanceUID(Examination examination) {
public String findStudyInstanceUID(Examination examination) {
List<DatasetAcquisition> acquisitions = examination.getDatasetAcquisitions();
for (DatasetAcquisition acquisition : acquisitions) {
if (acquisition instanceof MrDatasetAcquisition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.dcm4che3.data.VR;
import org.dcm4che3.io.DicomInputStream;
import org.dcm4che3.io.DicomOutputStream;
import org.hibernate.Hibernate;
import org.shanoir.ng.dataset.modality.MeasurementDataset;
import org.shanoir.ng.dataset.modality.SegmentationDataset;
import org.shanoir.ng.dataset.model.CardinalityOfRelatedSubjects;
Expand All @@ -35,6 +36,7 @@
import org.shanoir.ng.datasetacquisition.model.pet.PetDatasetAcquisition;
import org.shanoir.ng.datasetacquisition.model.xa.XaDatasetAcquisition;
import org.shanoir.ng.datasetfile.DatasetFile;
import org.shanoir.ng.dicom.web.SeriesInstanceUIDHandler;
import org.shanoir.ng.dicom.web.StudyInstanceUIDHandler;
import org.shanoir.ng.dicom.web.service.DICOMWebService;
import org.shanoir.ng.examination.model.Examination;
Expand Down Expand Up @@ -88,10 +90,12 @@ public class DicomSEGAndSRImporterService {

@Autowired
private DICOMWebService dicomWebService;

@Autowired
private StudyInstanceUIDHandler studyInstanceUIDHandler;


@Autowired
private SeriesInstanceUIDHandler seriesInstanceUIDHandler;
@Value("${dcm4chee-arc.protocol}")
private String dcm4cheeProtocol;

Expand All @@ -103,7 +107,8 @@ public class DicomSEGAndSRImporterService {

@Value("${dcm4chee-arc.dicom.web.rs}")
private String dicomWebRS;



@Transactional
public boolean importDicomSEGAndSR(InputStream inputStream) {
// DicomInputStream consumes the input stream to read the data
Expand Down Expand Up @@ -133,6 +138,27 @@ public boolean importDicomSEGAndSR(InputStream inputStream) {
return true;
}

@Transactional
public void deleteSR(Long examId, String seriesUid) {
try {
Examination exam = examinationRepository.findById(examId).orElse(null);
if (exam != null) {
for (DatasetAcquisition acq : exam.getDatasetAcquisitions()) {
for (Dataset ds : acq.getDatasets()) {
String dsSeriesInstanceUid = seriesInstanceUIDHandler.findSeriesInstanceUID(ds);
if (dsSeriesInstanceUid.equals(seriesUid)) {
datasetService.deleteById(ds.getId());
solrService.deleteFromIndex(ds.getId());
return;
}
}
}
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}

/**
* This method replaces values of dicom tags within the DICOM SR file
* and searches the corresponding examination and returns it:
Expand Down
Loading