diff --git a/src/main/java/org/cbioportal/model/ClinicalData.java b/src/main/java/org/cbioportal/model/ClinicalData.java index 553a4b57899..3943de6044f 100644 --- a/src/main/java/org/cbioportal/model/ClinicalData.java +++ b/src/main/java/org/cbioportal/model/ClinicalData.java @@ -52,7 +52,7 @@ public String getAttrId() { } public Boolean isPatientAttribute() { - if(clinicalAttribute == null) { + if (clinicalAttribute == null) { return null; } return this.clinicalAttribute.getPatientAttribute(); diff --git a/src/main/java/org/cbioportal/model/ClinicalEvent.java b/src/main/java/org/cbioportal/model/ClinicalEvent.java index 679dfed37c3..c98a7ea95f0 100644 --- a/src/main/java/org/cbioportal/model/ClinicalEvent.java +++ b/src/main/java/org/cbioportal/model/ClinicalEvent.java @@ -1,8 +1,10 @@ package org.cbioportal.model; -import java.util.List; import jakarta.validation.constraints.NotNull; +import java.util.List; +import java.util.Objects; + public class ClinicalEvent extends UniqueKeyBase { private Integer clinicalEventId; @@ -71,4 +73,17 @@ public List getAttributes() { public void setAttributes(List attributes) { this.attributes = attributes; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClinicalEvent that = (ClinicalEvent) o; + return Objects.equals(clinicalEventId, that.clinicalEventId) && Objects.equals(studyId, that.studyId) && Objects.equals(patientId, that.patientId) && Objects.equals(eventType, that.eventType) && Objects.equals(startDate, that.startDate) && Objects.equals(stopDate, that.stopDate) && Objects.equals(attributes, that.attributes); + } + + @Override + public int hashCode() { + return Objects.hash(clinicalEventId, studyId, patientId, eventType, startDate, stopDate, attributes); + } } diff --git a/src/main/java/org/cbioportal/persistence/ClinicalEventRepository.java b/src/main/java/org/cbioportal/persistence/ClinicalEventRepository.java index 74835374c94..bf6d31470c9 100644 --- a/src/main/java/org/cbioportal/persistence/ClinicalEventRepository.java +++ b/src/main/java/org/cbioportal/persistence/ClinicalEventRepository.java @@ -35,4 +35,11 @@ List getAllClinicalEventsInStudy(String studyId, String projectio @Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()") List getPatientsDistinctClinicalEventInStudies(List studyIds, List patientIds); + + + @Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()") + List getTimelineEvents(List studyIds, List patientIds, List clinicalEvents); + + @Cacheable(cacheResolver = "generalRepositoryCacheResolver", condition = "@cacheEnabledConfig.getEnabled()") + List getClinicalEventsMeta(List studyIds, List patientIds, List clinicalEvents); } diff --git a/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMapper.java b/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMapper.java index 32da3ebc0e8..d87b0e8467d 100644 --- a/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMapper.java +++ b/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMapper.java @@ -23,4 +23,8 @@ List getStudyClinicalEvent(String studyId, String projection, Int List getSamplesOfPatientsPerEventType(List studyIds, List sampleIds); List getPatientsDistinctClinicalEventInStudies(List studyIds, List patientIds); + + List getTimelineEvents(List studyIds, List patientIds, List clinicalEvents); + + List getClinicalEventsMeta(List studyIds, List patientIds, List clinicalEvents); } diff --git a/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepository.java b/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepository.java index 82abd29a241..ef65f4fa879 100644 --- a/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepository.java +++ b/src/main/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepository.java @@ -66,4 +66,16 @@ public Map> getSamplesOfPatientsPerEventTypeInStudy(List getPatientsDistinctClinicalEventInStudies(List studyIds, List patientIds) { return clinicalEventMapper.getPatientsDistinctClinicalEventInStudies(studyIds, patientIds); } + + @Override + public List getTimelineEvents(List studyIds, + List patientIds, + List clinicalEvents) { + return clinicalEventMapper.getTimelineEvents(studyIds, patientIds, clinicalEvents); + } + + @Override + public List getClinicalEventsMeta(List studyIds, List patientIds, List clinicalEvents) { + return clinicalEventMapper.getClinicalEventsMeta(studyIds, patientIds, clinicalEvents); + } } diff --git a/src/main/java/org/cbioportal/service/ClinicalEventService.java b/src/main/java/org/cbioportal/service/ClinicalEventService.java index a1b0a5c7ae6..ad0009ac0b6 100644 --- a/src/main/java/org/cbioportal/service/ClinicalEventService.java +++ b/src/main/java/org/cbioportal/service/ClinicalEventService.java @@ -1,10 +1,12 @@ package org.cbioportal.service; +import org.cbioportal.model.ClinicalData; import org.cbioportal.model.ClinicalEvent; import org.cbioportal.model.ClinicalEventTypeCount; import org.cbioportal.model.meta.BaseMeta; import org.cbioportal.service.exception.PatientNotFoundException; import org.cbioportal.service.exception.StudyNotFoundException; +import org.cbioportal.web.parameter.SurvivalRequest; import java.util.List; import java.util.Map; @@ -29,4 +31,11 @@ BaseMeta getMetaClinicalEvents(String studyId) Map> getPatientsSamplesPerClinicalEventType(List studyIds, List sampleIds); List getClinicalEventTypeCounts(List studyIds, List sampleIds); + + List getSurvivalData(List studyIds, List patientIds, + String attributeIdPrefix, + SurvivalRequest survivalRequest); + + List getClinicalEventsMeta(List studyIds, List patientIds, + List clinicalEvents); } diff --git a/src/main/java/org/cbioportal/service/FrontendPropertiesServiceImpl.java b/src/main/java/org/cbioportal/service/FrontendPropertiesServiceImpl.java index da96d0debfa..02f193b08f3 100644 --- a/src/main/java/org/cbioportal/service/FrontendPropertiesServiceImpl.java +++ b/src/main/java/org/cbioportal/service/FrontendPropertiesServiceImpl.java @@ -175,6 +175,7 @@ public enum FrontendProperty { skin_patient_view_copy_number_table_columns_show_on_init("skin.patient_view.copy_number_table.columns.show_on_init", null), skin_patient_view_structural_variant_table_columns_show_on_init("skin.patient_view.structural_variant_table.columns.show_on_init", null), skin_results_view_tables_default_sort_column("skin.results_view.tables.default_sort_column", null), + skin_survival_plot_clinical_event_types_show_on_init("skin.survival_plot.clinical_event_types.show_on_init", null), skin_patient_view_tables_default_sort_column("skin.patient_view.tables.default_sort_column", null), enable_treatment_groups("enable_treatment_groups", null), diff --git a/src/main/java/org/cbioportal/service/impl/ClinicalEventServiceImpl.java b/src/main/java/org/cbioportal/service/impl/ClinicalEventServiceImpl.java index 7cb3f304bdb..6d70c1647f6 100644 --- a/src/main/java/org/cbioportal/service/impl/ClinicalEventServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/ClinicalEventServiceImpl.java @@ -1,17 +1,33 @@ package org.cbioportal.service.impl; -import org.cbioportal.model.*; +import org.apache.commons.collections4.CollectionUtils; +import org.cbioportal.model.ClinicalData; +import org.cbioportal.model.ClinicalEvent; +import org.cbioportal.model.ClinicalEventData; +import org.cbioportal.model.ClinicalEventTypeCount; +import org.cbioportal.model.Patient; import org.cbioportal.model.meta.BaseMeta; import org.cbioportal.persistence.ClinicalEventRepository; import org.cbioportal.service.ClinicalEventService; import org.cbioportal.service.PatientService; import org.cbioportal.service.exception.PatientNotFoundException; import org.cbioportal.service.exception.StudyNotFoundException; +import org.cbioportal.web.parameter.ClinicalEventRequestIdentifier; +import org.cbioportal.web.parameter.OccurrencePosition; +import org.cbioportal.web.parameter.SurvivalRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.function.ToIntFunction; import java.util.stream.Collectors; +import java.util.stream.Stream; @Service public class ClinicalEventServiceImpl implements ClinicalEventService { @@ -108,4 +124,137 @@ public List getClinicalEventTypeCounts(List stud .map(e -> new ClinicalEventTypeCount(e.getKey(),e.getValue())) .collect(Collectors.toList()); } + + @Override + public List getSurvivalData(List studyIds, + List patientIds, + String attributeIdPrefix, + SurvivalRequest survivalRequest) { + List startClinicalEventsMeta = getToClinicalEvents(survivalRequest.getStartEventRequestIdentifier()); + List patientStartEvents = clinicalEventRepository.getTimelineEvents(studyIds, patientIds, startClinicalEventsMeta); + + // only fetch end timeline events for patients that have endClinicalEventsMeta and start timeline events + List patientEndEvents = filterClinicalEvents(patientStartEvents, survivalRequest.getEndEventRequestIdentifier()); + + ToIntFunction startPositionIdentifier = getPositionIdentifier(survivalRequest.getStartEventRequestIdentifier().getPosition()); + ToIntFunction endPositionIdentifier = getPositionIdentifier(survivalRequest.getEndEventRequestIdentifier().getPosition()); + Map patientEndEventsById = patientEndEvents.stream().collect(Collectors.toMap(ClinicalEventServiceImpl::getKey, Function.identity())); + + // filter out cases where start event is less than end event + patientStartEvents = patientStartEvents.stream() + .filter(event -> + Optional.ofNullable(patientEndEventsById.get(getKey(event))) + .map(endPositionIdentifier::applyAsInt) + .map(endDate -> startPositionIdentifier.applyAsInt(event) < endDate) + .orElse(true) + ).toList(); + + List patientCensoredEvents = filterClinicalEvents(patientStartEvents, survivalRequest.getCensoredEventRequestIdentifier()); + + return patientStartEvents.stream() + .flatMap(event -> { + ClinicalData clinicalDataMonths = buildClinicalSurvivalMonths(attributeIdPrefix, event, survivalRequest, patientEndEvents, patientCensoredEvents); + if (clinicalDataMonths == null) return Stream.empty(); + ClinicalData clinicalDataStatus = buildClinicalSurvivalStatus(attributeIdPrefix, event, patientEndEvents); + + return Stream.of(clinicalDataMonths, clinicalDataStatus); + }).toList(); + } + + @Override + public List getClinicalEventsMeta(List studyIds, List patientIds, List clinicalEvents) { + return clinicalEventRepository.getClinicalEventsMeta(studyIds, patientIds, clinicalEvents); + } + + private static String getKey(ClinicalEvent clinicalEvent) { + return clinicalEvent.getStudyId() + clinicalEvent.getPatientId(); + } + + private static List getToClinicalEvents(ClinicalEventRequestIdentifier clinicalEventRequestIdentifier) { + return clinicalEventRequestIdentifier.getClinicalEventRequests().stream().map(x -> { + ClinicalEvent clinicalEvent = new ClinicalEvent(); + clinicalEvent.setEventType(x.getEventType()); + clinicalEvent.setAttributes(x.getAttributes()); + + return clinicalEvent; + }).toList(); + } + + private ToIntFunction getPositionIdentifier(OccurrencePosition position) { + return position.equals(OccurrencePosition.FIRST) ? ClinicalEvent::getStartDate : ClinicalEvent::getStopDate; + } + + private List filterClinicalEvents(List patientEvents, + ClinicalEventRequestIdentifier clinicalEventRequestIdentifier) { + List filteredStudyIds = new ArrayList<>(); + List filteredPatientIds = new ArrayList<>(); + for (ClinicalEvent clinicalEvent : patientEvents) { + filteredStudyIds.add(clinicalEvent.getStudyId()); + filteredPatientIds.add(clinicalEvent.getPatientId()); + } + + List clinicalEventsMeta = new ArrayList<>(); + if (clinicalEventRequestIdentifier != null) { + clinicalEventsMeta = getToClinicalEvents(clinicalEventRequestIdentifier); + } + + // only fetch end timeline events for patients that have endClinicalEventsMeta and start timeline events + List queriedPatientEvents = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(clinicalEventsMeta) && CollectionUtils.isNotEmpty(filteredStudyIds)) { + queriedPatientEvents = clinicalEventRepository.getTimelineEvents(filteredStudyIds, filteredPatientIds, clinicalEventsMeta); + } + return queriedPatientEvents; + } + + private ClinicalData buildClinicalSurvivalMonths(String attributeIdPrefix, ClinicalEvent event, SurvivalRequest survivalRequest, List patientEndEvents, List patientCensoredEvents) { + final String SURVIVAL_MONTH_ATTRIBUTE = attributeIdPrefix + "_MONTHS"; + ClinicalData clinicalDataMonths = new ClinicalData(); + clinicalDataMonths.setStudyId(event.getStudyId()); + clinicalDataMonths.setPatientId(event.getPatientId()); + clinicalDataMonths.setAttrId(SURVIVAL_MONTH_ATTRIBUTE); + + Map patientEndEventsById = patientEndEvents.stream().collect(Collectors.toMap(ClinicalEventServiceImpl::getKey, Function.identity())); + Map patientCensoredEventsById = patientCensoredEvents.stream().collect(Collectors.toMap(ClinicalEventServiceImpl::getKey, Function.identity())); + + ToIntFunction startPositionIdentifier = getPositionIdentifier(survivalRequest.getStartEventRequestIdentifier().getPosition()); + ToIntFunction endPositionIdentifier = survivalRequest.getEndEventRequestIdentifier() == null ? ClinicalEvent::getStopDate : getPositionIdentifier(survivalRequest.getEndEventRequestIdentifier().getPosition()); + ToIntFunction censoredPositionIdentifier = survivalRequest.getCensoredEventRequestIdentifier() == null ? ClinicalEvent::getStopDate : getPositionIdentifier(survivalRequest.getCensoredEventRequestIdentifier().getPosition()); + + int startDate = startPositionIdentifier.applyAsInt(event); + int endDate; + if (patientEndEventsById.containsKey(getKey(event))) { + endDate = endPositionIdentifier.applyAsInt(patientEndEventsById.get(getKey(event))); + } else { + // ignore cases where patient does not have censored timeline events or + // stop date of start event is less than start date of censored events + if (!patientCensoredEventsById.containsKey(getKey(event)) || + startDate >= censoredPositionIdentifier.applyAsInt(patientCensoredEventsById.get(getKey(event))) + ) { + return null; + } + + endDate = censoredPositionIdentifier.applyAsInt(patientCensoredEventsById.get(getKey(event))); + } + final String SURVIVAL_MONTH = String.valueOf((endDate - startDate) / 30.4); + clinicalDataMonths.setAttrValue(SURVIVAL_MONTH); + + return clinicalDataMonths; + } + + private ClinicalData buildClinicalSurvivalStatus(String attributeIdPrefix, ClinicalEvent event, List patientEndEvents) { + Map patientEndEventsById = patientEndEvents.stream().collect(Collectors.toMap(ClinicalEventServiceImpl::getKey, Function.identity())); + + ClinicalData clinicalDataStatus = new ClinicalData(); + clinicalDataStatus.setStudyId(event.getStudyId()); + clinicalDataStatus.setPatientId(event.getPatientId()); + clinicalDataStatus.setAttrId(attributeIdPrefix + "_STATUS"); + + if (patientEndEventsById.containsKey(getKey(event))) { + clinicalDataStatus.setAttrValue("1:EVENT"); + } else { + clinicalDataStatus.setAttrValue("0:CENSORED"); + } + + return clinicalDataStatus; + } } diff --git a/src/main/java/org/cbioportal/web/ClinicalEventController.java b/src/main/java/org/cbioportal/web/ClinicalEventController.java index 08ff9a60357..cb8efec5e75 100644 --- a/src/main/java/org/cbioportal/web/ClinicalEventController.java +++ b/src/main/java/org/cbioportal/web/ClinicalEventController.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import org.cbioportal.model.ClinicalEvent; @@ -15,9 +16,11 @@ import org.cbioportal.service.exception.StudyNotFoundException; import org.cbioportal.web.config.InternalApiTags; import org.cbioportal.web.config.annotation.InternalApi; +import org.cbioportal.web.parameter.ClinicalEventAttributeRequest; import org.cbioportal.web.parameter.Direction; import org.cbioportal.web.parameter.HeaderKeyConstants; import org.cbioportal.web.parameter.PagingConstants; +import org.cbioportal.web.parameter.PatientIdentifier; import org.cbioportal.web.parameter.Projection; import org.cbioportal.web.parameter.sort.ClinicalEventSortBy; import org.springframework.beans.factory.annotation.Autowired; @@ -28,11 +31,15 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; @InternalApi @@ -120,4 +127,42 @@ public ResponseEntity> getAllClinicalEventsInStudy( sortBy == null ? null : sortBy.getOriginalValue(), direction.name()), HttpStatus.OK); } } + + @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/clinical-events-meta/fetch", + method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(description = "Fetch clinical events meta") + @ApiResponse(responseCode = "200", description = "OK", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ClinicalEvent.class)))) + public ResponseEntity> fetchClinicalEventsMeta( + @Parameter(required = true, description = "clinical events Request") + @Valid @RequestBody(required = false) ClinicalEventAttributeRequest clinicalEventAttributeRequest, + @Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface + @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, + @Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface. This attribute is needed for the @PreAuthorize tag above. + @Valid @RequestAttribute(required = false, value = "interceptedClinicalEventAttributeRequest") ClinicalEventAttributeRequest interceptedClinicalEventAttributeRequest) { + + List studyIds = new ArrayList<>(); + List patientIds = new ArrayList<>(); + for (PatientIdentifier patientIdentifier : interceptedClinicalEventAttributeRequest.getPatientIdentifiers()) { + studyIds.add(patientIdentifier.getStudyId()); + patientIds.add(patientIdentifier.getPatientId()); + } + + List clinicalEventsRequest = interceptedClinicalEventAttributeRequest.getClinicalEventRequests() + .stream() + .map(x -> { + ClinicalEvent clinicalEvent = new ClinicalEvent(); + clinicalEvent.setEventType(x.getEventType()); + clinicalEvent.setAttributes(x.getAttributes()); + return clinicalEvent; + }) + .toList(); + + return new ResponseEntity<>(clinicalEventService.getClinicalEventsMeta( + studyIds, patientIds, clinicalEventsRequest), HttpStatus.OK); + + } } diff --git a/src/main/java/org/cbioportal/web/SurvivalController.java b/src/main/java/org/cbioportal/web/SurvivalController.java new file mode 100644 index 00000000000..202b344406c --- /dev/null +++ b/src/main/java/org/cbioportal/web/SurvivalController.java @@ -0,0 +1,76 @@ +package org.cbioportal.web; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.cbioportal.model.ClinicalData; +import org.cbioportal.service.ClinicalEventService; +import org.cbioportal.web.config.annotation.InternalApi; +import org.cbioportal.web.parameter.PatientIdentifier; +import org.cbioportal.web.parameter.SurvivalRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@InternalApi +@RestController() +@RequestMapping("/api") +@Validated +@Tag(name = "Survival", description = " ") +public class SurvivalController { + private final ClinicalEventService clinicalEventService; + + @Autowired + public SurvivalController(ClinicalEventService clinicalEventService) { + this.clinicalEventService = clinicalEventService; + } + + @PreAuthorize("hasPermission(#involvedCancerStudies, 'Collection', T(org.cbioportal.utils.security.AccessLevel).READ)") + @RequestMapping(value = "/survival-data/fetch", + method = RequestMethod.POST, + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(description = "Fetch survival data") + @ApiResponse(responseCode = "200", description = "OK", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ClinicalData.class)))) + public ResponseEntity> fetchSurvivalData( + @Parameter(required = true, description = "Survival Data Request") + @Valid @RequestBody(required = false) SurvivalRequest survivalRequest, + @Parameter(hidden = true) // prevent reference to this attribute in the swagger-ui interface + @RequestAttribute(required = false, value = "involvedCancerStudies") Collection involvedCancerStudies, + @Parameter(hidden = true) + // prevent reference to this attribute in the swagger-ui interface. this attribute is needed for the @PreAuthorize tag above. + @Valid @RequestAttribute(required = false, value = "interceptedSurvivalRequest") SurvivalRequest interceptedSurvivalRequest) { + + List studyIds = new ArrayList<>(); + List patientIds = new ArrayList<>(); + for (PatientIdentifier patientIdentifier : interceptedSurvivalRequest.getPatientIdentifiers()) { + studyIds.add(patientIdentifier.getStudyId()); + patientIds.add(patientIdentifier.getPatientId()); + } + + List result = clinicalEventService.getSurvivalData(studyIds, + patientIds, + interceptedSurvivalRequest.getAttributeIdPrefix(), + interceptedSurvivalRequest); + + return new ResponseEntity<>(result, HttpStatus.OK); + } +} diff --git a/src/main/java/org/cbioportal/web/parameter/ClinicalEventAttributeRequest.java b/src/main/java/org/cbioportal/web/parameter/ClinicalEventAttributeRequest.java new file mode 100644 index 00000000000..4cc2d6f254e --- /dev/null +++ b/src/main/java/org/cbioportal/web/parameter/ClinicalEventAttributeRequest.java @@ -0,0 +1,31 @@ +package org.cbioportal.web.parameter; + +import jakarta.validation.constraints.Size; + +import java.io.Serializable; +import java.util.List; +import java.util.Set; + +public class ClinicalEventAttributeRequest implements Serializable { + + @Size(min = 1, max = PagingConstants.MAX_PAGE_SIZE) + private List patientIdentifiers; + + private Set clinicalEventRequests; + + public List getPatientIdentifiers() { + return patientIdentifiers; + } + + public void setPatientIdentifiers(List patientIdentifiers) { + this.patientIdentifiers = patientIdentifiers; + } + + public Set getClinicalEventRequests() { + return clinicalEventRequests; + } + + public void setClinicalEventRequests(Set clinicalEventRequests) { + this.clinicalEventRequests = clinicalEventRequests; + } +} \ No newline at end of file diff --git a/src/main/java/org/cbioportal/web/parameter/ClinicalEventRequest.java b/src/main/java/org/cbioportal/web/parameter/ClinicalEventRequest.java new file mode 100644 index 00000000000..1397e0dcb85 --- /dev/null +++ b/src/main/java/org/cbioportal/web/parameter/ClinicalEventRequest.java @@ -0,0 +1,32 @@ +package org.cbioportal.web.parameter; + +import org.cbioportal.model.ClinicalEventData; + +import jakarta.validation.constraints.NotNull; + +import java.io.Serializable; +import java.util.List; + +public class ClinicalEventRequest implements Serializable { + + @NotNull + private String eventType; + + private List attributes; + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } +} diff --git a/src/main/java/org/cbioportal/web/parameter/ClinicalEventRequestIdentifier.java b/src/main/java/org/cbioportal/web/parameter/ClinicalEventRequestIdentifier.java new file mode 100644 index 00000000000..2d38a85e91c --- /dev/null +++ b/src/main/java/org/cbioportal/web/parameter/ClinicalEventRequestIdentifier.java @@ -0,0 +1,31 @@ +package org.cbioportal.web.parameter; + + +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import java.io.Serializable; +import java.util.Set; + +public class ClinicalEventRequestIdentifier implements Serializable { + + @Size(max = PagingConstants.MAX_PAGE_SIZE) + private Set clinicalEventRequests; + @NotNull + private OccurrencePosition position; + + public Set getClinicalEventRequests() { + return clinicalEventRequests; + } + + public void setClinicalEventRequests(Set clinicalEventRequests) { + this.clinicalEventRequests = clinicalEventRequests; + } + + public OccurrencePosition getPosition() { + return position; + } + + public void setPosition(OccurrencePosition position) { + this.position = position; + } +} diff --git a/src/main/java/org/cbioportal/web/parameter/OccurrencePosition.java b/src/main/java/org/cbioportal/web/parameter/OccurrencePosition.java new file mode 100644 index 00000000000..b9a5dbc9aad --- /dev/null +++ b/src/main/java/org/cbioportal/web/parameter/OccurrencePosition.java @@ -0,0 +1,6 @@ +package org.cbioportal.web.parameter; + +public enum OccurrencePosition { + FIRST, + LAST +} diff --git a/src/main/java/org/cbioportal/web/parameter/SurvivalRequest.java b/src/main/java/org/cbioportal/web/parameter/SurvivalRequest.java new file mode 100644 index 00000000000..7f770d9cd42 --- /dev/null +++ b/src/main/java/org/cbioportal/web/parameter/SurvivalRequest.java @@ -0,0 +1,65 @@ +package org.cbioportal.web.parameter; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import java.io.Serializable; +import java.util.List; + +public class SurvivalRequest implements Serializable { + + @Size(min = 1, max = PagingConstants.MAX_PAGE_SIZE) + private List patientIdentifiers; + + @NotNull + private String attributeIdPrefix; + + @Valid + private ClinicalEventRequestIdentifier startEventRequestIdentifier; + + @Valid + private ClinicalEventRequestIdentifier endEventRequestIdentifier; + + @Valid + private ClinicalEventRequestIdentifier censoredEventRequestIdentifier; + + public List getPatientIdentifiers() { + return patientIdentifiers; + } + + public void setPatientIdentifiers(List patientIdentifiers) { + this.patientIdentifiers = patientIdentifiers; + } + + public String getAttributeIdPrefix() { + return attributeIdPrefix; + } + + public void setAttributeIdPrefix(String attributeIdPrefix) { + this.attributeIdPrefix = attributeIdPrefix; + } + + public ClinicalEventRequestIdentifier getStartEventRequestIdentifier() { + return startEventRequestIdentifier; + } + + public void setStartEventRequestIdentifier(ClinicalEventRequestIdentifier startEventRequestIdentifier) { + this.startEventRequestIdentifier = startEventRequestIdentifier; + } + + public ClinicalEventRequestIdentifier getEndEventRequestIdentifier() { + return endEventRequestIdentifier; + } + + public void setEndEventRequestIdentifier(ClinicalEventRequestIdentifier endEventRequestIdentifier) { + this.endEventRequestIdentifier = endEventRequestIdentifier; + } + + public ClinicalEventRequestIdentifier getCensoredEventRequestIdentifier() { + return censoredEventRequestIdentifier; + } + + public void setCensoredEventRequestIdentifier(ClinicalEventRequestIdentifier censoredEventRequestIdentifier) { + this.censoredEventRequestIdentifier = censoredEventRequestIdentifier; + } +} diff --git a/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java b/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java index 3a11b33f973..547e50e44ee 100644 --- a/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java +++ b/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java @@ -45,6 +45,7 @@ import org.cbioportal.web.parameter.ClinicalDataCountFilter; import org.cbioportal.web.parameter.ClinicalDataIdentifier; import org.cbioportal.web.parameter.ClinicalDataMultiStudyFilter; +import org.cbioportal.web.parameter.ClinicalEventAttributeRequest; import org.cbioportal.web.parameter.GenePanelDataMultipleStudyFilter; import org.cbioportal.web.parameter.GenericAssayDataBinCountFilter; import org.cbioportal.web.parameter.GenericAssayDataCountFilter; @@ -64,6 +65,7 @@ import org.cbioportal.web.parameter.SampleMolecularIdentifier; import org.cbioportal.web.parameter.StructuralVariantFilter; import org.cbioportal.web.parameter.StudyViewFilter; +import org.cbioportal.web.parameter.SurvivalRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -72,6 +74,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -128,6 +131,8 @@ public class InvolvedCancerStudyExtractorInterceptor implements HandlerIntercept public static final String GENERIC_ASSAY_CATEGORICAL_ENRICHMENT_FETCH_PATH = "/generic-assay-categorical-enrichments/fetch"; public static final String GENERIC_ASSAY_BINARY_ENRICHMENT_FETCH_PATH = "/generic-assay-binary-enrichments/fetch"; public static final String CLINICAL_EVENT_TYPE_COUNT_FETCH_PATH = "/clinical-event-type-counts/fetch"; + public static final String SURVIVAL_DATA_FETCH_PATH = "/survival-data/fetch"; + public static final String CLINICAL_EVENT_META_FETCH_PATH = "/clinical-events-meta/fetch"; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { if (!request.getMethod().equals("POST")) { @@ -189,6 +194,10 @@ public class InvolvedCancerStudyExtractorInterceptor implements HandlerIntercept return extractAttributesFromStructuralVariantFilter(request); } else if (requestPathInfo.equals(GENERIC_ASSAY_DATA_MULTIPLE_STUDY_FETCH_PATH)) { return extractAttributesFromGenericAssayDataMultipleStudyFilter(request); + } else if (requestPathInfo.equals(SURVIVAL_DATA_FETCH_PATH)) { + return extractCancerStudyIdsFromSurvivalRequest(request); + } else if (requestPathInfo.equals(CLINICAL_EVENT_META_FETCH_PATH)) { + return extractCancerStudyIdsFromClinicalEventAttributeRequest(request); } return true; } @@ -196,16 +205,16 @@ public class InvolvedCancerStudyExtractorInterceptor implements HandlerIntercept private boolean extractAttributesFromPatientFilter(HttpServletRequest request) { try { PatientFilter patientFilter = objectMapper.readValue(request.getInputStream(), PatientFilter.class); - LOG.debug("extracted patientFilter: " + patientFilter.toString()); - LOG.debug("setting interceptedPatientFilter to " + patientFilter); + LOG.debug("extracted patientFilter: {}", patientFilter); + LOG.debug("setting interceptedPatientFilter to {}", patientFilter); request.setAttribute("interceptedPatientFilter", patientFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromPatientFilter(patientFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of patientFilter: " + e); + LOG.error("exception thrown during extraction of patientFilter: {}", e.getMessage()); return false; } return true; @@ -227,16 +236,16 @@ private Collection extractCancerStudyIdsFromPatientFilter(PatientFilter private boolean extractAttributesFromSampleFilter(HttpServletRequest request) { try { SampleFilter sampleFilter = objectMapper.readValue(request.getInputStream(), SampleFilter.class); - LOG.debug("extracted sampleFilter: " + sampleFilter.toString()); - LOG.debug("setting interceptedSampleFilter to " + sampleFilter); + LOG.debug("extracted sampleFilter: {}", sampleFilter); + LOG.debug("setting interceptedSampleFilter to {}", sampleFilter); request.setAttribute("interceptedSampleFilter", sampleFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromSampleFilter(sampleFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of sampleFilter: " + e); + LOG.error("exception thrown during extraction of sampleFilter: {}", e.getMessage()); return false; } return true; @@ -258,16 +267,16 @@ private Collection extractCancerStudyIdsFromSampleFilter(SampleFilter sa private boolean extractAttributesFromMolecularProfileFilter(HttpServletRequest request) { try { MolecularProfileFilter molecularProfileFilter = objectMapper.readValue(request.getInputStream(), MolecularProfileFilter.class); - LOG.debug("extracted molecularProfileFilter: " + molecularProfileFilter.toString()); - LOG.debug("setting interceptedMolecularProfileFilter to " + molecularProfileFilter); + LOG.debug("extracted molecularProfileFilter: {}", molecularProfileFilter); + LOG.debug("setting interceptedMolecularProfileFilter to {}", molecularProfileFilter); request.setAttribute("interceptedMolecularProfileFilter", molecularProfileFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromMolecularProfileFilter(molecularProfileFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of molecularProfileFilter: " + e); + LOG.error("exception thrown during extraction of molecularProfileFilter: {}", e.getMessage()); return false; } return true; @@ -287,16 +296,16 @@ private Collection extractCancerStudyIdsFromMolecularProfileFilter(Molec private boolean extractAttributesFromClinicalAttributeCountFilter(HttpServletRequest request) { try { ClinicalAttributeCountFilter clinicalAttributeCountFilter = objectMapper.readValue(request.getInputStream(), ClinicalAttributeCountFilter.class); - LOG.debug("extracted clinicalAttributeCountFilter: " + clinicalAttributeCountFilter.toString()); - LOG.debug("setting interceptedClinicalAttributeCountFilter to " + clinicalAttributeCountFilter); + LOG.debug("extracted clinicalAttributeCountFilter: {}", clinicalAttributeCountFilter); + LOG.debug("setting interceptedClinicalAttributeCountFilter to {}", clinicalAttributeCountFilter); request.setAttribute("interceptedClinicalAttributeCountFilter", clinicalAttributeCountFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromClinicalAttributeCountFilter(clinicalAttributeCountFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of clinicalAttributeCountFilter: " + e); + LOG.error("exception thrown during extraction of clinicalAttributeCountFilter: {}", e.getMessage()); return false; } return true; @@ -306,7 +315,7 @@ private Collection extractCancerStudyIdsFromClinicalAttributeCountFilter // use hashset as the study list in the clinicalAttributeCountFilter may be populated with many duplicate values Set studyIdSet = new HashSet<>(); if (clinicalAttributeCountFilter.getSampleListId() != null) { - extractCancerStudyIdsFromSampleListIds(Arrays.asList(clinicalAttributeCountFilter.getSampleListId()), studyIdSet); + extractCancerStudyIdsFromSampleListIds(Collections.singletonList(clinicalAttributeCountFilter.getSampleListId()), studyIdSet); } else { extractCancerStudyIdsFromSampleIdentifiers(clinicalAttributeCountFilter.getSampleIdentifiers(), studyIdSet); } @@ -316,16 +325,16 @@ private Collection extractCancerStudyIdsFromClinicalAttributeCountFilter private boolean extractAttributesFromClinicalDataMultiStudyFilter(HttpServletRequest request) { try { ClinicalDataMultiStudyFilter clinicalDataMultiStudyFilter = objectMapper.readValue(request.getInputStream(), ClinicalDataMultiStudyFilter.class); - LOG.debug("extracted clinicalDataMultiStudyFilter: " + clinicalDataMultiStudyFilter.toString()); - LOG.debug("setting interceptedClinicalDataMultiStudyFilter to " + clinicalDataMultiStudyFilter); + LOG.debug("extracted clinicalDataMultiStudyFilter: {}", clinicalDataMultiStudyFilter); + LOG.debug("setting interceptedClinicalDataMultiStudyFilter to {}", clinicalDataMultiStudyFilter); request.setAttribute("interceptedClinicalDataMultiStudyFilter", clinicalDataMultiStudyFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromClinicalDataMultiStudyFilter(clinicalDataMultiStudyFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of clinicalDataMultiStudyFilter: " + e); + LOG.error("exception thrown during extraction of clinicalDataMultiStudyFilter: {}", e.getMessage()); return false; } return true; @@ -343,16 +352,16 @@ private Collection extractCancerStudyIdsFromClinicalDataMultiStudyFilter private boolean extractAttributesFromGenePanelDataMultipleStudyFilter(HttpServletRequest request) { try { GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter = objectMapper.readValue(request.getInputStream(), GenePanelDataMultipleStudyFilter.class); - LOG.debug("extracted genePanelDataMultipleStudyFilter: " + genePanelDataMultipleStudyFilter.toString()); - LOG.debug("setting interceptedGenePanelDataMultipleStudyFilter to " + genePanelDataMultipleStudyFilter); + LOG.debug("extracted genePanelDataMultipleStudyFilter: {}", genePanelDataMultipleStudyFilter); + LOG.debug("setting interceptedGenePanelDataMultipleStudyFilter to {}", genePanelDataMultipleStudyFilter); request.setAttribute("interceptedGenePanelDataMultipleStudyFilter", genePanelDataMultipleStudyFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromGenePanelDataMultipleStudyFilter(genePanelDataMultipleStudyFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of genePanelSampleMolecularIdentifiers: " + e); + LOG.error("exception thrown during extraction of genePanelSampleMolecularIdentifiers: {}", e.getMessage()); return false; } return true; @@ -371,16 +380,16 @@ private Collection extractCancerStudyIdsFromGenePanelDataMultipleStudyFi private boolean extractAttributesFromMolecularDataMultipleStudyFilter(HttpServletRequest request) { try { MolecularDataMultipleStudyFilter molecularDataMultipleStudyFilter = objectMapper.readValue(request.getInputStream(), MolecularDataMultipleStudyFilter.class); - LOG.debug("extracted molecularDataMultipleStudyFilter: " + molecularDataMultipleStudyFilter.toString()); - LOG.debug("setting interceptedMolecularDataMultipleStudyFilter to " + molecularDataMultipleStudyFilter); + LOG.debug("extracted molecularDataMultipleStudyFilter: {}", molecularDataMultipleStudyFilter); + LOG.debug("setting interceptedMolecularDataMultipleStudyFilter to {}", molecularDataMultipleStudyFilter); request.setAttribute("interceptedMolecularDataMultipleStudyFilter", molecularDataMultipleStudyFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromMolecularDataMultipleStudyFilter(molecularDataMultipleStudyFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of molecularDataMultipleStudyFilter: " + e); + LOG.error("exception thrown during extraction of molecularDataMultipleStudyFilter: {}", e.getMessage()); return false; } return true; @@ -399,16 +408,16 @@ private Collection extractCancerStudyIdsFromMolecularDataMultipleStudyFi private boolean extractAttributesFromGenericAssayDataMultipleStudyFilter(HttpServletRequest request) { try { GenericAssayDataMultipleStudyFilter genericAssayDataMultipleStudyFilter = objectMapper.readValue(request.getInputStream(), GenericAssayDataMultipleStudyFilter.class); - LOG.debug("extracted genericAssayDataMultipleStudyFilter: " + genericAssayDataMultipleStudyFilter.toString()); - LOG.debug("setting interceptedGenericAssayDataMultipleStudyFilter to " + genericAssayDataMultipleStudyFilter); + LOG.debug("extracted genericAssayDataMultipleStudyFilter: {}", genericAssayDataMultipleStudyFilter); + LOG.debug("setting interceptedGenericAssayDataMultipleStudyFilter to {}", genericAssayDataMultipleStudyFilter); request.setAttribute("interceptedGenericAssayDataMultipleStudyFilter", genericAssayDataMultipleStudyFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromGenericAssayDataMultipleStudyFilter(genericAssayDataMultipleStudyFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of genericAssayDataMultipleStudyFilter: " + e); + LOG.error("exception thrown during extraction of genericAssayDataMultipleStudyFilter: {}", e.getMessage()); return false; } return true; @@ -427,16 +436,16 @@ private Collection extractCancerStudyIdsFromGenericAssayDataMultipleStud private boolean extractAttributesFromMutationMultipleStudyFilter(HttpServletRequest request) { try { MutationMultipleStudyFilter mutationMultipleStudyFilter = objectMapper.readValue(request.getInputStream(), MutationMultipleStudyFilter.class); - LOG.debug("extracted mutationMultipleStudyFilter: " + mutationMultipleStudyFilter.toString()); - LOG.debug("setting interceptedMutationMultipleStudyFilter to " + mutationMultipleStudyFilter); + LOG.debug("extracted mutationMultipleStudyFilter: {}", mutationMultipleStudyFilter); + LOG.debug("setting interceptedMutationMultipleStudyFilter to {}", mutationMultipleStudyFilter); request.setAttribute("interceptedMutationMultipleStudyFilter", mutationMultipleStudyFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromMutationMultipleStudyFilter(mutationMultipleStudyFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of mutationMultipleStudyFilter: " + e); + LOG.error("exception thrown during extraction of mutationMultipleStudyFilter: {}", e.getMessage()); return false; } return true; @@ -455,16 +464,16 @@ private Set extractCancerStudyIdsFromMutationMultipleStudyFilter(Mutatio private boolean extractAttributesFromSampleIdentifiers(HttpServletRequest request) { try { List sampleIdentifiers = Arrays.asList(objectMapper.readValue(request.getInputStream(), SampleIdentifier[].class)); - LOG.debug("extracted sampleIdentifiers: " + sampleIdentifiers.toString()); - LOG.debug("setting interceptedSampleIdentifiers to " + sampleIdentifiers); + LOG.debug("extracted sampleIdentifiers: {}", sampleIdentifiers); + LOG.debug("setting interceptedSampleIdentifiers to {}", sampleIdentifiers); request.setAttribute("interceptedSampleIdentifiers", sampleIdentifiers); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromSampleIdentifiers(sampleIdentifiers); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of sampleIdentifiers: " + e); + LOG.error("exception thrown during extraction of sampleIdentifiers: {}", e.getMessage()); return false; } return true; @@ -474,17 +483,17 @@ private boolean extractAttributesFromClinicalDataBinCountFilter(HttpServletReque try { ClinicalDataBinCountFilter clinicalDataBinCountFilter = objectMapper.readValue(request.getInputStream(), ClinicalDataBinCountFilter.class); - LOG.debug("extracted clinicalDataBinCountFilter: " + clinicalDataBinCountFilter.toString()); - LOG.debug("setting interceptedClinicalDataBinCountFilter to " + clinicalDataBinCountFilter); + LOG.debug("extracted clinicalDataBinCountFilter: {}", clinicalDataBinCountFilter); + LOG.debug("setting interceptedClinicalDataBinCountFilter to {}", clinicalDataBinCountFilter); request.setAttribute("interceptedClinicalDataBinCountFilter", clinicalDataBinCountFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromClinicalDataBinCountFilter( clinicalDataBinCountFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of clinicalDataBinCountFilter: " + e); + LOG.error("exception thrown during extraction of clinicalDataBinCountFilter: {}", e.getMessage()); return false; } return true; @@ -494,17 +503,17 @@ private boolean extractAttributesFromGenomicDataBinCountFilter(HttpServletReques try { GenomicDataBinCountFilter genomicDataBinCountFilter = objectMapper.readValue(request.getInputStream(), GenomicDataBinCountFilter.class); - LOG.debug("extracted genomicDataBinCountFilter: " + genomicDataBinCountFilter.toString()); - LOG.debug("setting interceptedGenomicDataBinCountFilter to " + genomicDataBinCountFilter); + LOG.debug("extracted genomicDataBinCountFilter: {}", genomicDataBinCountFilter); + LOG.debug("setting interceptedGenomicDataBinCountFilter to {}", genomicDataBinCountFilter); request.setAttribute("interceptedGenomicDataBinCountFilter", genomicDataBinCountFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromGenomicDataBinCountFilter( genomicDataBinCountFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of genomicDataBinCountFilter: " + e); + LOG.error("exception thrown during extraction of genomicDataBinCountFilter: {}", e.getMessage()); return false; } return true; @@ -514,17 +523,17 @@ private boolean extractAttributesFromGenomicDataCountFilter(HttpServletRequest r try { GenomicDataCountFilter genomicDataCountFilter = objectMapper.readValue(request.getInputStream(), GenomicDataCountFilter.class); - LOG.debug("extracted genomicDataCountFilter: " + genomicDataCountFilter.toString()); - LOG.debug("setting interceptedGenomicDataCountFilter to " + genomicDataCountFilter); + LOG.debug("extracted genomicDataCountFilter: {}", genomicDataCountFilter); + LOG.debug("setting interceptedGenomicDataCountFilter to {}", genomicDataCountFilter); request.setAttribute("interceptedGenomicDataCountFilter", genomicDataCountFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromGenomicDataCountFilter( genomicDataCountFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of genomicDataCountFilter: " + e); + LOG.error("exception thrown during extraction of genomicDataCountFilter: {}", e.getMessage()); return false; } return true; @@ -534,17 +543,17 @@ private boolean extractAttributesFromGenericAssayDataBinCountFilter(HttpServletR try { GenericAssayDataBinCountFilter genericAssayDataBinCountFilter = objectMapper .readValue(request.getInputStream(), GenericAssayDataBinCountFilter.class); - LOG.debug("extracted genericAssayDataBinCountFilter: " + genericAssayDataBinCountFilter.toString()); - LOG.debug("setting interceptedGenericAssayDataBinCountFilter to " + genericAssayDataBinCountFilter); + LOG.debug("extracted genericAssayDataBinCountFilter: {}", genericAssayDataBinCountFilter); + LOG.debug("setting interceptedGenericAssayDataBinCountFilter to {}", genericAssayDataBinCountFilter); request.setAttribute("interceptedGenericAssayDataBinCountFilter", genericAssayDataBinCountFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromGenericAssayDataBinCountFilter( genericAssayDataBinCountFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of genericAssayDataBinCountFilter: " + e); + LOG.error("exception thrown during extraction of genericAssayDataBinCountFilter: {}", e.getMessage()); return false; } return true; @@ -554,17 +563,17 @@ private boolean extractAttributesFromGenericAssayDataCountFilter(HttpServletRequ try { GenericAssayDataCountFilter genericAssayDataCountFilter = objectMapper .readValue(request.getInputStream(), GenericAssayDataCountFilter.class); - LOG.debug("extracted genericAssayDataCountFilter: " + genericAssayDataCountFilter.toString()); - LOG.debug("setting interceptedGenericAssayDataCountFilter to " + genericAssayDataCountFilter); + LOG.debug("extracted genericAssayDataCountFilter: {}", genericAssayDataCountFilter); + LOG.debug("setting interceptedGenericAssayDataCountFilter to {}", genericAssayDataCountFilter); request.setAttribute("interceptedGenericAssayDataCountFilter", genericAssayDataCountFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromGenericAssayDataCountFilter( genericAssayDataCountFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of genericAssayDataCountFilter: " + e); + LOG.error("exception thrown during extraction of genericAssayDataCountFilter: {}", e.getMessage()); return false; } return true; @@ -574,17 +583,17 @@ private boolean extractAttributesFromClinicalDataCountFilter(HttpServletRequest try { ClinicalDataCountFilter clinicalDataCountFilter = objectMapper.readValue(request.getInputStream(), ClinicalDataCountFilter.class); - LOG.debug("extracted clinicalDataBinCountFilter: " + clinicalDataCountFilter.toString()); - LOG.debug("setting interceptedClinicalDataCountFilter to " + clinicalDataCountFilter); + LOG.debug("extracted clinicalDataBinCountFilter: {}", clinicalDataCountFilter); + LOG.debug("setting interceptedClinicalDataCountFilter to {}", clinicalDataCountFilter); request.setAttribute("interceptedClinicalDataCountFilter", clinicalDataCountFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromClinicalDataCountFilter( clinicalDataCountFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of clinicalDataBinCountFilter: " + e); + LOG.error("exception thrown during extraction of clinicalDataBinCountFilter: {}", e.getMessage()); return false; } return true; @@ -594,18 +603,18 @@ private boolean extractAttributesFromGroupFilter(HttpServletRequest request) { try { GroupFilter groupFilter = objectMapper.readValue(request.getInputStream(), GroupFilter.class); - LOG.debug("extracted groupFilter: " + groupFilter.toString()); - LOG.debug("setting interceptedGroupFilter to " + groupFilter); + LOG.debug("extracted groupFilter: {}", groupFilter); + LOG.debug("setting interceptedGroupFilter to {}", groupFilter); request.setAttribute("interceptedGroupFilter", groupFilter); if (cacheMapUtil.hasCacheEnabled()) { List sampleIdentifiers = groupFilter.getGroups().stream() .flatMap(group -> group.getSampleIdentifiers().stream()).collect(Collectors.toList()); Collection cancerStudyIdCollection = extractCancerStudyIdsFromSampleIdentifiers(sampleIdentifiers); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of groupFilter: " + e); + LOG.error("exception thrown during extraction of groupFilter: {}", e.getMessage()); return false; } return true; @@ -624,16 +633,16 @@ private boolean extractAttributesFromStudyViewFilter(HttpServletRequest request) // when the StructuralVariantFilters are not part of the request. studyViewFilter.setStructuralVariantFilters(new ArrayList<>()); } - LOG.debug("extracted studyViewFilter: " + studyViewFilter.toString()); - LOG.debug("setting interceptedStudyViewFilter to " + studyViewFilter); + LOG.debug("extracted studyViewFilter: {}", studyViewFilter); + LOG.debug("setting interceptedStudyViewFilter to {}", studyViewFilter); request.setAttribute("interceptedStudyViewFilter", studyViewFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromStudyViewFilter(studyViewFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of studyViewFilter: " + e); + LOG.error("exception thrown during extraction of studyViewFilter: {}", e.getMessage()); return false; } return true; @@ -643,17 +652,17 @@ private boolean extractAttributesFromMolecularProfileCasesGroups(HttpServletRequ try { List molecularProfileCasesGroupFilters = Arrays .asList(objectMapper.readValue(request.getInputStream(), MolecularProfileCasesGroupFilter[].class)); - LOG.debug("extracted molecularProfileCasesGroupFilters: " + molecularProfileCasesGroupFilters.toString()); - LOG.debug("setting interceptedMolecularProfileCasesGroupFilters to " + molecularProfileCasesGroupFilters); + LOG.debug("extracted molecularProfileCasesGroupFilters: {}", molecularProfileCasesGroupFilters); + LOG.debug("setting interceptedMolecularProfileCasesGroupFilters to {}", molecularProfileCasesGroupFilters); request.setAttribute("interceptedMolecularProfileCasesGroupFilters", molecularProfileCasesGroupFilters); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromMolecularProfileCasesGroups( molecularProfileCasesGroupFilters); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of molecularProfileCasesGroupFilters: " + e); + LOG.error("exception thrown during extraction of molecularProfileCasesGroupFilters: {}", e.getMessage()); return false; } return true; @@ -663,23 +672,23 @@ private boolean extractAttributesFromMolecularProfileCasesGroupsAndAlterationTyp try { MolecularProfileCasesGroupAndAlterationTypeFilter molecularProfileCasesAndAlterationTypesGroupFilters = objectMapper.readValue(request.getInputStream(), MolecularProfileCasesGroupAndAlterationTypeFilter.class); List molecularProfileCasesGroupFilters = molecularProfileCasesAndAlterationTypesGroupFilters.getMolecularProfileCasesGroupFilter(); - LOG.debug("extracted molecularProfileCasesGroupFilters: " + molecularProfileCasesGroupFilters.toString()); - LOG.debug("setting interceptedMolecularProfileCasesGroupFilters to " + molecularProfileCasesGroupFilters); + LOG.debug("extracted molecularProfileCasesGroupFilters: {}", molecularProfileCasesGroupFilters); + LOG.debug("setting interceptedMolecularProfileCasesGroupFilters to {}", molecularProfileCasesGroupFilters); request.setAttribute("interceptedMolecularProfileCasesGroupFilters", molecularProfileCasesGroupFilters); if (molecularProfileCasesAndAlterationTypesGroupFilters.getAlterationEventTypes() != null) { AlterationFilter alterationEnrichmentEventTypes = molecularProfileCasesAndAlterationTypesGroupFilters.getAlterationEventTypes(); - LOG.debug("extracted alterationEventTypes: " + alterationEnrichmentEventTypes.toString()); - LOG.debug("setting alterationEventTypes to " + alterationEnrichmentEventTypes); + LOG.debug("extracted alterationEventTypes: {}", alterationEnrichmentEventTypes); + LOG.debug("setting alterationEventTypes to {}", alterationEnrichmentEventTypes); request.setAttribute("alterationEventTypes", alterationEnrichmentEventTypes); } if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromMolecularProfileCasesGroups( molecularProfileCasesGroupFilters); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of molecularProfileCasesGroupFilters: " + e); + LOG.error("exception thrown during extraction of molecularProfileCasesGroupFilters: {}", e.getMessage()); return false; } return true; @@ -689,22 +698,22 @@ private boolean extractAttributesFromStructuralVariantFilter(HttpServletRequest try { StructuralVariantFilter structuralVariantFilter = objectMapper.readValue(request.getInputStream(), StructuralVariantFilter.class); - LOG.debug("extracted structuralVariantFilter: " + structuralVariantFilter.toString()); + LOG.debug("extracted structuralVariantFilter: {}", structuralVariantFilter); if (structuralVariantFilter.getStructuralVariantQueries() == null) { // For backwards compatibility an empty set of queries is inferred // when the StructuralVariantFilter is not part of the request. structuralVariantFilter.setStructuralVariantQueries(new ArrayList<>()); } - LOG.debug("setting interceptedStructuralVariantFilter to " + structuralVariantFilter); + LOG.debug("setting interceptedStructuralVariantFilter to {}", structuralVariantFilter); request.setAttribute("interceptedStructuralVariantFilter", structuralVariantFilter); if (cacheMapUtil.hasCacheEnabled()) { Collection cancerStudyIdCollection = extractCancerStudyIdsFromStructuralVariantFilter( structuralVariantFilter); - LOG.debug("setting involvedCancerStudies to " + cancerStudyIdCollection); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); } } catch (Exception e) { - LOG.error("exception thrown during extraction of structuralVariantFilter: " + e); + LOG.error("exception thrown during extraction of structuralVariantFilter: {}", e.getMessage()); return false; } return true; @@ -827,4 +836,48 @@ private Set extractCancerStudyIdsFromMolecularProfileCasesGroups(Collect return studyIdSet; } + private boolean extractCancerStudyIdsFromSurvivalRequest(HttpServletRequest request) { + try { + SurvivalRequest survivalRequest = objectMapper.readValue(request.getInputStream(), SurvivalRequest.class); + LOG.debug("extracted survivalRequest: {}", survivalRequest); + LOG.debug("setting interceptedSurvivalRequest to {}", survivalRequest); + request.setAttribute("interceptedSurvivalRequest", survivalRequest); + if (cacheMapUtil.hasCacheEnabled()) { + Collection cancerStudyIdCollection = survivalRequest + .getPatientIdentifiers() + .stream() + .map(PatientIdentifier::getStudyId) + .collect(Collectors.toSet()); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); + request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); + } + } catch (Exception e) { + LOG.error("exception thrown during extraction of survivalRequest: {}", e.getMessage()); + return false; + } + return true; + } + + private boolean extractCancerStudyIdsFromClinicalEventAttributeRequest(HttpServletRequest request) { + try { + ClinicalEventAttributeRequest clinicalEventAttributeRequest = objectMapper.readValue(request.getInputStream(), ClinicalEventAttributeRequest.class); + LOG.debug("extracted clinicalEventAttributeRequest: {}", clinicalEventAttributeRequest); + LOG.debug("setting interceptedClinicalEventAttributeRequest to {}", clinicalEventAttributeRequest); + request.setAttribute("interceptedClinicalEventAttributeRequest", clinicalEventAttributeRequest); + if (cacheMapUtil.hasCacheEnabled()) { + Collection cancerStudyIdCollection = clinicalEventAttributeRequest + .getPatientIdentifiers() + .stream() + .map(PatientIdentifier::getStudyId) + .collect(Collectors.toSet()); + LOG.debug("setting involvedCancerStudies to {}", cancerStudyIdCollection); + request.setAttribute("involvedCancerStudies", cancerStudyIdCollection); + } + } catch (Exception e) { + LOG.error("exception thrown during extraction of clinicalEventAttributeRequest: {}", e.getMessage()); + return false; + } + return true; + } + } diff --git a/src/main/resources/org/cbioportal/persistence/mybatis/ClinicalEventMapper.xml b/src/main/resources/org/cbioportal/persistence/mybatis/ClinicalEventMapper.xml index 58cd60d098f..f9ff12ee766 100644 --- a/src/main/resources/org/cbioportal/persistence/mybatis/ClinicalEventMapper.xml +++ b/src/main/resources/org/cbioportal/persistence/mybatis/ClinicalEventMapper.xml @@ -184,4 +184,121 @@ Group by clinical_event.EVENT_TYPE, patient.STABLE_ID + + + + + + + + + + + diff --git a/src/test/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepositoryTest.java b/src/test/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepositoryTest.java index 90fe8046a9e..60a8d1067de 100644 --- a/src/test/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepositoryTest.java +++ b/src/test/java/org/cbioportal/persistence/mybatis/ClinicalEventMyBatisRepositoryTest.java @@ -1,8 +1,5 @@ package org.cbioportal.persistence.mybatis; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; import org.cbioportal.model.ClinicalEvent; import org.cbioportal.model.ClinicalEventData; import org.cbioportal.model.meta.BaseMeta; @@ -19,11 +16,10 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import static java.util.stream.Collectors.groupingBy; - @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = {ClinicalEventMyBatisRepository.class, MolecularProfileCaseIdentifierUtil.class, TestConfig.class}) public class ClinicalEventMyBatisRepositoryTest { @@ -145,7 +141,7 @@ public void getAllClinicalEventsInStudyIdProjection() throws Exception { List result = clinicalEventMyBatisRepository.getAllClinicalEventsInStudy( "study_tcga_pub", "ID", null, null, null, null); - Assert.assertEquals(4, result.size()); + Assert.assertEquals(5, result.size()); Optional clinicalEventOptional = result.stream().filter(r -> r.getClinicalEventId() == 2).findAny(); @@ -163,7 +159,7 @@ public void getAllClinicalEventsInStudySummaryProjection() throws Exception { List result = clinicalEventMyBatisRepository.getAllClinicalEventsInStudy( "study_tcga_pub", "SUMMARY", null, null, null, null); - Assert.assertEquals(4, result.size()); + Assert.assertEquals(5, result.size()); Optional clinicalEventOptional = result.stream().filter(r -> r.getClinicalEventId() == 2).findAny(); @@ -182,7 +178,7 @@ public void getAllClinicalEventsInStudyDetailedProjection() throws Exception { List result = clinicalEventMyBatisRepository.getAllClinicalEventsInStudy( "study_tcga_pub", "DETAILED", null, null, null, null); - Assert.assertEquals(4, result.size()); + Assert.assertEquals(5, result.size()); Optional clinicalEventOptional = result.stream().filter(r -> r.getClinicalEventId() == 2).findAny(); @@ -210,7 +206,7 @@ public void getAllClinicalEventsInStudySummaryProjectionEventTypeSort() throws E List result = clinicalEventMyBatisRepository.getAllClinicalEventsInStudy( "study_tcga_pub", "SUMMARY", null, null, "eventType", "ASC"); - Assert.assertEquals(4, result.size()); + Assert.assertEquals(5, result.size()); Assert.assertEquals("SPECIMEN", result.get(1).getEventType()); Assert.assertEquals("STATUS", result.get(2).getEventType()); } @@ -220,7 +216,7 @@ public void getMetaClinicalEvents() throws Exception { BaseMeta result = clinicalEventMyBatisRepository.getMetaClinicalEvents("study_tcga_pub"); - Assert.assertEquals((Integer) 4, result.getTotalCount()); + Assert.assertEquals((Integer) 5, result.getTotalCount()); } @Test @@ -247,4 +243,55 @@ public void getPatientsDistinctClinicalEventInStudies() { Assert.assertEquals(2, result.size()); Assert.assertTrue(eventTypes.contains("STATUS")); } + + @Test + public void getTimelineEvents() { + List studyList = new ArrayList<>(); + studyList.add("study_tcga_pub"); + List patientList = new ArrayList<>(); + patientList.add("TCGA-A1-A0SD"); + + ClinicalEventData clinicalEventData1 = new ClinicalEventData(); + clinicalEventData1.setKey("AGENT"); + clinicalEventData1.setValue("Madeupanib"); + + ClinicalEventData clinicalEventData2 = new ClinicalEventData(); + clinicalEventData2.setKey("AGENT"); + clinicalEventData2.setValue("abc"); + + ClinicalEvent requestClinicalEvent = new ClinicalEvent(); + requestClinicalEvent.setEventType("TREATMENT"); + requestClinicalEvent.setAttributes(Arrays.asList(clinicalEventData1, clinicalEventData2)); + List result = clinicalEventMyBatisRepository.getTimelineEvents(studyList, patientList, List.of(requestClinicalEvent)); + + Assert.assertEquals(1, result.size()); + Assert.assertEquals((Integer) 213, result.getFirst().getStartDate()); + Assert.assertEquals((Integer) 543, result.getFirst().getStopDate()); + } + + + @Test + public void getClinicalEventsMeta() { + List studyList = new ArrayList<>(); + studyList.add("study_tcga_pub"); + List patientList = new ArrayList<>(); + patientList.add("TCGA-A1-A0SD"); + + ClinicalEventData clinicalEventData1 = new ClinicalEventData(); + clinicalEventData1.setKey("AGENT"); + clinicalEventData1.setValue("Madeupanib"); + + ClinicalEventData clinicalEventData2 = new ClinicalEventData(); + clinicalEventData2.setKey("AGENT"); + clinicalEventData2.setValue("abc"); + + ClinicalEvent requestClinicalEvent = new ClinicalEvent(); + requestClinicalEvent.setEventType("TREATMENT"); + requestClinicalEvent.setAttributes(Arrays.asList(clinicalEventData1, clinicalEventData2)); + List result = clinicalEventMyBatisRepository.getClinicalEventsMeta(studyList, patientList, List.of(requestClinicalEvent)); + + List eventTypes = result.stream().map(ClinicalEvent::getEventType).toList(); + Assert.assertEquals(1, result.size()); + Assert.assertTrue(eventTypes.contains("treatment")); + } } diff --git a/src/test/java/org/cbioportal/persistence/mybatis/TreatmentMyBatisRepositoryTest.java b/src/test/java/org/cbioportal/persistence/mybatis/TreatmentMyBatisRepositoryTest.java index 99f518f9a27..5cdc3506c34 100644 --- a/src/test/java/org/cbioportal/persistence/mybatis/TreatmentMyBatisRepositoryTest.java +++ b/src/test/java/org/cbioportal/persistence/mybatis/TreatmentMyBatisRepositoryTest.java @@ -1,13 +1,8 @@ package org.cbioportal.persistence.mybatis; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.cbioportal.model.ClinicalEventKeyCode; import org.cbioportal.model.ClinicalEventSample; import org.cbioportal.model.Treatment; -import org.cbioportal.model.ClinicalEventKeyCode; import org.cbioportal.persistence.TreatmentRepository; import org.cbioportal.persistence.mybatis.config.TestConfig; import org.junit.Assert; @@ -17,6 +12,12 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = {TreatmentMyBatisRepository.class, TestConfig.class}) public class TreatmentMyBatisRepositoryTest { @@ -26,16 +27,22 @@ public class TreatmentMyBatisRepositoryTest { @Test public void getTreatmentsByPatientId() { - Treatment treatment = new Treatment(); - treatment.setTreatment("Madeupanib"); - treatment.setStudyId("study_tcga_pub"); - treatment.setPatientId("TCGA-A1-A0SD"); - treatment.setStart(213); - treatment.setStop(445); + Treatment treatment1 = new Treatment(); + treatment1.setTreatment("Madeupanib"); + treatment1.setStudyId("study_tcga_pub"); + treatment1.setPatientId("TCGA-A1-A0SD"); + treatment1.setStart(213); + treatment1.setStop(445); + + Treatment treatment2 = new Treatment(); + treatment2.setTreatment("abc"); + treatment2.setStudyId("study_tcga_pub"); + treatment2.setPatientId("TCGA-A1-A0SD"); + treatment2.setStart(313); + treatment2.setStop(543); Map> expected = new HashMap<>(); - expected.put("TCGA-A1-A0SD", Collections.singletonList(treatment)); - + expected.put("TCGA-A1-A0SD", Arrays.asList(treatment1, treatment2)); Map> actual = treatmentRepository.getTreatmentsByPatientId( Collections.singletonList("TCGA-A1-A0SD-01"), @@ -43,30 +50,41 @@ public void getTreatmentsByPatientId() { ClinicalEventKeyCode.Agent ); - Assert.assertEquals(actual, expected); } - @Test public void getTreatmentAgentsByPatientId() { - Treatment targetA = new Treatment(); - targetA.setTreatment("Directly to forehead"); - targetA.setStudyId("study_tcga_pub"); - targetA.setPatientId("TCGA-A1-A0SD"); - targetA.setStart(213); - targetA.setStop(445); - - Treatment targetB = new Treatment(); - targetB.setTreatment("Elbow"); - targetB.setStudyId("study_tcga_pub"); - targetB.setPatientId("TCGA-A1-A0SD"); - targetB.setStart(213); - targetB.setStop(445); + Treatment treatment1 = new Treatment(); + treatment1.setTreatment("Directly to forehead"); + treatment1.setStudyId("study_tcga_pub"); + treatment1.setPatientId("TCGA-A1-A0SD"); + treatment1.setStart(213); + treatment1.setStop(445); + + Treatment treatment2 = new Treatment(); + treatment2.setTreatment("Elbow"); + treatment2.setStudyId("study_tcga_pub"); + treatment2.setPatientId("TCGA-A1-A0SD"); + treatment2.setStart(213); + treatment2.setStop(445); + + Treatment treatment3 = new Treatment(); + treatment3.setTreatment("Left arm"); + treatment3.setStudyId("study_tcga_pub"); + treatment3.setPatientId("TCGA-A1-A0SD"); + treatment3.setStart(313); + treatment3.setStop(543); + + Treatment treatment4 = new Treatment(); + treatment4.setTreatment("Ankle"); + treatment4.setStudyId("study_tcga_pub"); + treatment4.setPatientId("TCGA-A1-A0SD"); + treatment4.setStart(313); + treatment4.setStop(543); Map> expected = new HashMap<>(); - expected.put("TCGA-A1-A0SD", Arrays.asList(targetA, targetB)); - + expected.put("TCGA-A1-A0SD", Arrays.asList(treatment1, treatment2, treatment3, treatment4)); Map> actual = treatmentRepository.getTreatmentsByPatientId( Collections.singletonList("TCGA-A1-A0SD-01"), @@ -74,7 +92,6 @@ public void getTreatmentAgentsByPatientId() { ClinicalEventKeyCode.AgentTarget ); - Assert.assertEquals(actual, expected); } diff --git a/src/test/java/org/cbioportal/service/impl/ClinicalDataServiceImplTest.java b/src/test/java/org/cbioportal/service/impl/ClinicalDataServiceImplTest.java old mode 100644 new mode 100755 diff --git a/src/test/java/org/cbioportal/service/impl/ClinicalEventServiceImplTest.java b/src/test/java/org/cbioportal/service/impl/ClinicalEventServiceImplTest.java index 89a0976c0dc..e6fe83f8c7e 100644 --- a/src/test/java/org/cbioportal/service/impl/ClinicalEventServiceImplTest.java +++ b/src/test/java/org/cbioportal/service/impl/ClinicalEventServiceImplTest.java @@ -1,5 +1,6 @@ package org.cbioportal.service.impl; +import org.cbioportal.model.ClinicalData; import org.cbioportal.model.ClinicalEvent; import org.cbioportal.model.ClinicalEventData; import org.cbioportal.model.ClinicalEventTypeCount; @@ -8,12 +9,14 @@ import org.cbioportal.persistence.ClinicalEventRepository; import org.cbioportal.service.PatientService; import org.cbioportal.service.exception.PatientNotFoundException; -import org.junit.Assert; +import org.cbioportal.web.parameter.ClinicalEventRequest; +import org.cbioportal.web.parameter.ClinicalEventRequestIdentifier; +import org.cbioportal.web.parameter.OccurrencePosition; +import org.cbioportal.web.parameter.SurvivalRequest; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; @@ -24,11 +27,18 @@ import java.util.Map; import java.util.Set; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class ClinicalEventServiceImplTest extends BaseServiceImplTest { - private static final String CLINICAL_EVENT_TYPE = "SERVICE"; + private static final String TEST_CLINICAL_EVENT_TYPE_1 = "SERVICE"; + private static final String TEST_CLINICAL_EVENT_TYPE_2 = "test_clinical_event_type_2"; + private static final String TEST_CLINICAL_EVENT_TYPE_3 = "test_clinical_event_type_3"; + private static final String TEST_SURVIVAL_PREFIX = "survival_prefix"; @InjectMocks private ClinicalEventServiceImpl clinicalEventService; @@ -46,7 +56,7 @@ public void getAllClinicalEventsOfPatientInStudy() throws Exception { clinicalEvent.setClinicalEventId(CLINICAL_EVENT_ID); expectedClinicalEventList.add(clinicalEvent); - Mockito.when(clinicalEventRepository.getAllClinicalEventsOfPatientInStudy(STUDY_ID, PATIENT_ID_1, PROJECTION, + when(clinicalEventRepository.getAllClinicalEventsOfPatientInStudy(STUDY_ID, PATIENT_ID_1, PROJECTION, PAGE_SIZE, PAGE_NUMBER, SORT, DIRECTION)).thenReturn(expectedClinicalEventList); List expectedClinicalEventDataList = new ArrayList<>(); @@ -54,22 +64,22 @@ public void getAllClinicalEventsOfPatientInStudy() throws Exception { clinicalEventData.setClinicalEventId(CLINICAL_EVENT_ID); expectedClinicalEventDataList.add(clinicalEventData); - Mockito.when(clinicalEventRepository.getDataOfClinicalEvents(Arrays.asList(CLINICAL_EVENT_ID))) + when(clinicalEventRepository.getDataOfClinicalEvents(Arrays.asList(CLINICAL_EVENT_ID))) .thenReturn(expectedClinicalEventDataList); List result = clinicalEventService.getAllClinicalEventsOfPatientInStudy(STUDY_ID, PATIENT_ID_1, PROJECTION, PAGE_SIZE, PAGE_NUMBER, SORT, DIRECTION); - Assert.assertEquals(1, result.size()); - Assert.assertEquals(clinicalEvent, result.get(0)); - Assert.assertEquals(1, result.get(0).getAttributes().size()); - Assert.assertEquals(clinicalEventData, result.get(0).getAttributes().get(0)); + assertEquals(1, result.size()); + assertEquals(clinicalEvent, result.get(0)); + assertEquals(1, result.get(0).getAttributes().size()); + assertEquals(clinicalEventData, result.get(0).getAttributes().get(0)); } @Test(expected = PatientNotFoundException.class) public void getAllClinicalEventsOfPatientInStudyPatientNotFound() throws Exception { - Mockito.when(patientService.getPatientInStudy(STUDY_ID, PATIENT_ID_1)).thenThrow(new PatientNotFoundException( + when(patientService.getPatientInStudy(STUDY_ID, PATIENT_ID_1)).thenThrow(new PatientNotFoundException( STUDY_ID, PATIENT_ID_1)); clinicalEventService.getAllClinicalEventsOfPatientInStudy(STUDY_ID, PATIENT_ID_1, PROJECTION, PAGE_SIZE, PAGE_NUMBER, SORT, DIRECTION); @@ -79,30 +89,30 @@ public void getAllClinicalEventsOfPatientInStudyPatientNotFound() throws Excepti public void getMetaPatientClinicalEvents() throws Exception { BaseMeta expectedBaseMeta = new BaseMeta(); - Mockito.when(clinicalEventRepository.getMetaPatientClinicalEvents(STUDY_ID, PATIENT_ID_1)) + when(clinicalEventRepository.getMetaPatientClinicalEvents(STUDY_ID, PATIENT_ID_1)) .thenReturn(expectedBaseMeta); BaseMeta result = clinicalEventService.getMetaPatientClinicalEvents(STUDY_ID, PATIENT_ID_1); - Assert.assertEquals(expectedBaseMeta, result); + assertEquals(expectedBaseMeta, result); } @Test(expected = PatientNotFoundException.class) public void getMetaPatientClinicalEventsPatientNotFound() throws Exception { - Mockito.when(patientService.getPatientInStudy(STUDY_ID, PATIENT_ID_1)).thenThrow(new PatientNotFoundException( + when(patientService.getPatientInStudy(STUDY_ID, PATIENT_ID_1)).thenThrow(new PatientNotFoundException( STUDY_ID, PATIENT_ID_1)); clinicalEventService.getMetaPatientClinicalEvents(STUDY_ID, PATIENT_ID_1); } @Test - public void getAllClinicalEventsInStudy() throws Exception { + public void getAllClinicalEventsInStudy() { List expectedClinicalEventList = new ArrayList<>(); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setClinicalEventId(CLINICAL_EVENT_ID); expectedClinicalEventList.add(clinicalEvent); - Mockito.when(clinicalEventRepository.getAllClinicalEventsInStudy(STUDY_ID, PROJECTION, + when(clinicalEventRepository.getAllClinicalEventsInStudy(STUDY_ID, PROJECTION, PAGE_SIZE, PAGE_NUMBER, SORT, DIRECTION)).thenReturn(expectedClinicalEventList); List expectedClinicalEventDataList = new ArrayList<>(); @@ -110,27 +120,27 @@ public void getAllClinicalEventsInStudy() throws Exception { clinicalEventData.setClinicalEventId(CLINICAL_EVENT_ID); expectedClinicalEventDataList.add(clinicalEventData); - Mockito.when(clinicalEventRepository.getDataOfClinicalEvents(Arrays.asList(CLINICAL_EVENT_ID))) + when(clinicalEventRepository.getDataOfClinicalEvents(Arrays.asList(CLINICAL_EVENT_ID))) .thenReturn(expectedClinicalEventDataList); List result = clinicalEventService.getAllClinicalEventsInStudy(STUDY_ID, PROJECTION, PAGE_SIZE, PAGE_NUMBER, SORT, DIRECTION); - Assert.assertEquals(1, result.size()); - Assert.assertEquals(clinicalEvent, result.get(0)); - Assert.assertEquals(1, result.get(0).getAttributes().size()); - Assert.assertEquals(clinicalEventData, result.get(0).getAttributes().get(0)); + assertEquals(1, result.size()); + assertEquals(clinicalEvent, result.get(0)); + assertEquals(1, result.get(0).getAttributes().size()); + assertEquals(clinicalEventData, result.get(0).getAttributes().get(0)); } @Test public void getMetaClinicalEvents() throws Exception { BaseMeta expectedBaseMeta = new BaseMeta(); - Mockito.when(clinicalEventRepository.getMetaClinicalEvents(STUDY_ID)) + when(clinicalEventRepository.getMetaClinicalEvents(STUDY_ID)) .thenReturn(expectedBaseMeta); BaseMeta result = clinicalEventService.getMetaClinicalEvents(STUDY_ID); - Assert.assertEquals(expectedBaseMeta, result); + assertEquals(expectedBaseMeta, result); } @Test @@ -139,12 +149,12 @@ public void getPatientsSamplesPerClinicalEventType() { List sampleIds = Arrays.asList(SAMPLE_ID1); Map> patientsSamplesPerEventType = new HashMap<>(); - patientsSamplesPerEventType.put(CLINICAL_EVENT_TYPE, new HashSet<>(sampleIds)); + patientsSamplesPerEventType.put(TEST_CLINICAL_EVENT_TYPE_1, new HashSet<>(sampleIds)); - Mockito.when(clinicalEventRepository.getSamplesOfPatientsPerEventTypeInStudy(anyList(), anyList())) + when(clinicalEventRepository.getSamplesOfPatientsPerEventTypeInStudy(anyList(), anyList())) .thenReturn(patientsSamplesPerEventType); - Assert.assertEquals(patientsSamplesPerEventType, + assertEquals(patientsSamplesPerEventType, clinicalEventService.getPatientsSamplesPerClinicalEventType(studyIds, sampleIds)); } @@ -158,16 +168,233 @@ public void getClinicalEventTypeCounts() { p.setStableId(PATIENT_ID_1); ClinicalEvent ce = new ClinicalEvent(); - ce.setEventType(CLINICAL_EVENT_TYPE); + ce.setEventType(TEST_CLINICAL_EVENT_TYPE_1); - Mockito.when(patientService.getPatientsOfSamples(anyList(), anyList())) + when(patientService.getPatientsOfSamples(anyList(), anyList())) .thenReturn(Arrays.asList(p)); - Mockito.when(clinicalEventRepository.getPatientsDistinctClinicalEventInStudies(anyList(), anyList())) + when(clinicalEventRepository.getPatientsDistinctClinicalEventInStudies(anyList(), anyList())) .thenReturn(Arrays.asList(ce)); List eventTypeCounts = clinicalEventService.getClinicalEventTypeCounts(studyIds, sampleIds); - Assert.assertEquals(1, eventTypeCounts.size()); + assertEquals(1, eventTypeCounts.size()); int eventTypeCount = eventTypeCounts.get(0).getCount(); - Assert.assertEquals(1, eventTypeCount); + assertEquals(1, eventTypeCount); + } + + @Test + public void getSurvivalDataReturnsCorrectDataWhenEndEventsExist() { + List studyIds = List.of(STUDY_ID); + List patientIds = Arrays.asList(PATIENT_ID_1, PATIENT_ID_2, PATIENT_ID_3); + + List startClinicalEvents = new ArrayList<>(); + ClinicalEvent clinicalEvent1 = new ClinicalEvent(); + clinicalEvent1.setStudyId(STUDY_ID); + clinicalEvent1.setPatientId(PATIENT_ID_1); + clinicalEvent1.setStartDate(0); + clinicalEvent1.setStopDate(500); + + ClinicalEvent clinicalEvent2 = new ClinicalEvent(); + clinicalEvent2.setStudyId(STUDY_ID); + clinicalEvent2.setPatientId(PATIENT_ID_2); + clinicalEvent2.setStartDate(100); + clinicalEvent2.setStopDate(1000); + + ClinicalEvent clinicalEvent3 = new ClinicalEvent(); + clinicalEvent3.setStudyId(STUDY_ID); + clinicalEvent3.setPatientId(PATIENT_ID_3); + clinicalEvent3.setStartDate(1000); + clinicalEvent3.setStopDate(1200); + + startClinicalEvents.add(clinicalEvent1); + startClinicalEvents.add(clinicalEvent2); + startClinicalEvents.add(clinicalEvent3); + + List startEventMetas = new ArrayList<>(); + ClinicalEvent startEventMeta = new ClinicalEvent(); + startEventMeta.setEventType(TEST_CLINICAL_EVENT_TYPE_1); + startEventMetas.add(startEventMeta); + + when(clinicalEventRepository.getTimelineEvents(anyList(), anyList(), eq(startEventMetas))) + .thenReturn(startClinicalEvents); + + List endClinicalEvents = new ArrayList<>(); + ClinicalEvent clinicalEvent4 = new ClinicalEvent(); + clinicalEvent4.setStudyId(STUDY_ID); + clinicalEvent4.setPatientId(PATIENT_ID_1); + clinicalEvent4.setStartDate(500); + clinicalEvent4.setStopDate(1000); + + endClinicalEvents.add(clinicalEvent4); + + List endEventMetas = new ArrayList<>(); + ClinicalEvent endEventMeta = new ClinicalEvent(); + endEventMeta.setEventType(TEST_CLINICAL_EVENT_TYPE_2); + endEventMetas.add(endEventMeta); + + when(clinicalEventRepository.getTimelineEvents(anyList(), anyList(), eq(endEventMetas))) + .thenReturn(endClinicalEvents); + + List censoredClinicalEvents = new ArrayList<>(); + ClinicalEvent clinicalEvent5 = new ClinicalEvent(); + clinicalEvent5.setStudyId(STUDY_ID); + clinicalEvent5.setPatientId(PATIENT_ID_2); + clinicalEvent5.setStartDate(1000); + clinicalEvent5.setStopDate(2000); + + ClinicalEvent clinicalEvent6 = new ClinicalEvent(); + clinicalEvent6.setStudyId(STUDY_ID); + clinicalEvent6.setPatientId(PATIENT_ID_3); + clinicalEvent6.setStartDate(600); + clinicalEvent6.setStopDate(1000); + + censoredClinicalEvents.add(clinicalEvent5); + censoredClinicalEvents.add(clinicalEvent6); + + List censoredEventMetas = new ArrayList<>(); + ClinicalEvent censoredEventMeta = new ClinicalEvent(); + censoredEventMeta.setEventType(TEST_CLINICAL_EVENT_TYPE_3); + censoredEventMetas.add(censoredEventMeta); + + when(clinicalEventRepository.getTimelineEvents(anyList(), anyList(), eq(censoredEventMetas))) + .thenReturn(censoredClinicalEvents); + + SurvivalRequest survivalRequest = new SurvivalRequest(); + + ClinicalEventRequestIdentifier startEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + Set startClinicalEventRequests = new HashSet<>(); + ClinicalEventRequest clinicalEventRequest1 = new ClinicalEventRequest(); + clinicalEventRequest1.setEventType(TEST_CLINICAL_EVENT_TYPE_1); + startClinicalEventRequests.add(clinicalEventRequest1); + startEventRequestIdentifier.setClinicalEventRequests(startClinicalEventRequests); + startEventRequestIdentifier.setPosition(OccurrencePosition.FIRST); + survivalRequest.setStartEventRequestIdentifier(startEventRequestIdentifier); + + ClinicalEventRequestIdentifier endEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + Set endClinicalEventRequests = new HashSet<>(); + ClinicalEventRequest clinicalEventRequest2 = new ClinicalEventRequest(); + clinicalEventRequest2.setEventType(TEST_CLINICAL_EVENT_TYPE_2); + endClinicalEventRequests.add(clinicalEventRequest2); + endEventRequestIdentifier.setClinicalEventRequests(endClinicalEventRequests); + endEventRequestIdentifier.setPosition(OccurrencePosition.LAST); + survivalRequest.setEndEventRequestIdentifier(endEventRequestIdentifier); + + ClinicalEventRequestIdentifier censoredEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + Set censoredClinicalEventRequests = new HashSet<>(); + ClinicalEventRequest clinicalEventRequest3 = new ClinicalEventRequest(); + clinicalEventRequest3.setEventType(TEST_CLINICAL_EVENT_TYPE_3); + censoredClinicalEventRequests.add(clinicalEventRequest3); + censoredEventRequestIdentifier.setClinicalEventRequests(censoredClinicalEventRequests); + censoredEventRequestIdentifier.setPosition(OccurrencePosition.LAST); + survivalRequest.setCensoredEventRequestIdentifier(censoredEventRequestIdentifier); + + List result = clinicalEventService.getSurvivalData(studyIds, patientIds, TEST_SURVIVAL_PREFIX, survivalRequest); + + assertEquals(4, result.size()); + assertEquals(PATIENT_ID_1, result.getFirst().getPatientId()); + assertEquals("survival_prefix_MONTHS", result.get(0).getAttrId()); + assertEquals("32.89473684210527", result.get(0).getAttrValue()); + assertEquals("survival_prefix_STATUS", result.get(1).getAttrId()); + assertEquals("1:EVENT", result.get(1).getAttrValue()); + assertEquals(PATIENT_ID_2, result.get(2).getPatientId()); + assertEquals("survival_prefix_MONTHS", result.get(2).getAttrId()); + assertEquals("62.5", result.get(2).getAttrValue()); + assertEquals("survival_prefix_STATUS", result.get(3).getAttrId()); + assertEquals("0:CENSORED", result.get(3).getAttrValue()); + } + + @Test + public void getSurvivalDataReturnsEmptyListWhenNoEventsExist() { + List studyIds = List.of(STUDY_ID); + List patientIds = Arrays.asList(PATIENT_ID_1, PATIENT_ID_2, PATIENT_ID_3); + + List clinicalEventList = new ArrayList<>(); + ClinicalEvent clinicalEvent1 = new ClinicalEvent(); + clinicalEvent1.setStudyId(STUDY_ID); + clinicalEvent1.setPatientId(PATIENT_ID_1); + clinicalEvent1.setStartDate(0); + clinicalEvent1.setStopDate(500); + + ClinicalEvent clinicalEvent2 = new ClinicalEvent(); + clinicalEvent2.setStudyId(STUDY_ID); + clinicalEvent2.setPatientId(PATIENT_ID_2); + clinicalEvent2.setStartDate(100); + clinicalEvent2.setStopDate(1000); + + clinicalEventList.add(clinicalEvent1); + clinicalEventList.add(clinicalEvent2); + + SurvivalRequest survivalRequest = new SurvivalRequest(); + + ClinicalEventRequestIdentifier startEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + Set startClinicalEventRequests = new HashSet<>(); + ClinicalEventRequest clinicalEventRequest1 = new ClinicalEventRequest(); + clinicalEventRequest1.setEventType(TEST_CLINICAL_EVENT_TYPE_1); + startClinicalEventRequests.add(clinicalEventRequest1); + startEventRequestIdentifier.setClinicalEventRequests(startClinicalEventRequests); + startEventRequestIdentifier.setPosition(OccurrencePosition.FIRST); + survivalRequest.setStartEventRequestIdentifier(startEventRequestIdentifier); + + ClinicalEventRequestIdentifier endEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + Set endClinicalEventRequests = new HashSet<>(); + ClinicalEventRequest clinicalEventRequest2 = new ClinicalEventRequest(); + clinicalEventRequest2.setEventType(TEST_CLINICAL_EVENT_TYPE_2); + endClinicalEventRequests.add(clinicalEventRequest2); + endEventRequestIdentifier.setClinicalEventRequests(endClinicalEventRequests); + endEventRequestIdentifier.setPosition(OccurrencePosition.LAST); + survivalRequest.setEndEventRequestIdentifier(endEventRequestIdentifier); + + ClinicalEventRequestIdentifier censoredEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + Set censoredClinicalEventRequests = new HashSet<>(); + ClinicalEventRequest clinicalEventRequest3 = new ClinicalEventRequest(); + clinicalEventRequest3.setEventType(TEST_CLINICAL_EVENT_TYPE_3); + censoredClinicalEventRequests.add(clinicalEventRequest3); + censoredEventRequestIdentifier.setClinicalEventRequests(censoredClinicalEventRequests); + censoredEventRequestIdentifier.setPosition(OccurrencePosition.LAST); + survivalRequest.setCensoredEventRequestIdentifier(censoredEventRequestIdentifier); + + when(clinicalEventRepository.getTimelineEvents(anyList(), anyList(), anyList())) + .thenReturn(new ArrayList<>()); + + List result = clinicalEventService.getSurvivalData(studyIds, patientIds, TEST_SURVIVAL_PREFIX, survivalRequest); + + assertTrue(result.isEmpty()); + } + + @Test + public void getClinicalEventsMetaReturnsCorrectDataForValidInput() { + List studyIds = List.of(STUDY_ID); + List patientIds = Arrays.asList(PATIENT_ID_1, PATIENT_ID_2); + List clinicalEvents = new ArrayList<>(); + ClinicalEvent event1 = new ClinicalEvent(); + event1.setStudyId(STUDY_ID); + event1.setPatientId(PATIENT_ID_1); + ClinicalEvent event2 = new ClinicalEvent(); + event2.setStudyId(STUDY_ID); + event2.setPatientId(PATIENT_ID_2); + clinicalEvents.add(event1); + clinicalEvents.add(event2); + + when(clinicalEventRepository.getClinicalEventsMeta(anyList(), anyList(), anyList())).thenReturn(clinicalEvents); + + List result = clinicalEventService.getClinicalEventsMeta(studyIds, patientIds, clinicalEvents); + + assertEquals(2, result.size()); + assertEquals("study_id", result.get(0).getStudyId()); + assertEquals("patient_id1", result.get(0).getPatientId()); + assertEquals("study_id", result.get(1).getStudyId()); + assertEquals("patient_id2", result.get(1).getPatientId()); + } + + @Test + public void getClinicalEventsMetaReturnsEmptyListForInvalidInput() { + List studyIds = List.of(STUDY_ID); + List patientIds = Arrays.asList(PATIENT_ID_1, PATIENT_ID_2); + List clinicalEvents = new ArrayList<>(); + + when(clinicalEventRepository.getClinicalEventsMeta(anyList(), anyList(), anyList())).thenReturn(new ArrayList<>()); + + List result = clinicalEventService.getClinicalEventsMeta(studyIds, patientIds, clinicalEvents); + + assertTrue(result.isEmpty()); } } \ No newline at end of file diff --git a/src/test/java/org/cbioportal/web/ClinicalEventControllerTest.java b/src/test/java/org/cbioportal/web/ClinicalEventControllerTest.java index acd87275ada..bdbda3ca306 100644 --- a/src/test/java/org/cbioportal/web/ClinicalEventControllerTest.java +++ b/src/test/java/org/cbioportal/web/ClinicalEventControllerTest.java @@ -1,11 +1,15 @@ package org.cbioportal.web; +import com.fasterxml.jackson.databind.ObjectMapper; import org.cbioportal.model.ClinicalEvent; import org.cbioportal.model.ClinicalEventData; import org.cbioportal.model.meta.BaseMeta; import org.cbioportal.service.ClinicalEventService; import org.cbioportal.web.config.TestConfig; +import org.cbioportal.web.parameter.ClinicalEventAttributeRequest; +import org.cbioportal.web.parameter.ClinicalEventRequest; import org.cbioportal.web.parameter.HeaderKeyConstants; +import org.cbioportal.web.parameter.PatientIdentifier; import org.hamcrest.Matchers; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,7 +26,15 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; @RunWith(SpringJUnit4ClassRunner.class) @WebMvcTest @@ -48,7 +60,11 @@ public class ClinicalEventControllerTest { private static final String TEST_VALUE_3 = "test_value_3"; private static final String TEST_KEY_4 = "test_key_4"; private static final String TEST_VALUE_4 = "test_value_4"; + private static final String TEST_UNIQUE_PATIENT_KEY_1 = "test_unique_patient_key_1"; + private static final String TEST_UNIQUE_PATIENT_KEY_2 = "test_unique_patient_key_2"; + private final ObjectMapper objectMapper = new ObjectMapper(); + @MockBean private ClinicalEventService clinicalEventService; @@ -61,8 +77,8 @@ public void getAllClinicalEventsOfPatientInStudy() throws Exception { List clinicalEventList = createExampleClinicalEventList(); - Mockito.when(clinicalEventService.getAllClinicalEventsOfPatientInStudy(Mockito.any(), Mockito.any(), - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + when(clinicalEventService.getAllClinicalEventsOfPatientInStudy(any(), any(), + any(), any(), any(), any(), any())) .thenReturn(clinicalEventList); mockMvc.perform(MockMvcRequestBuilders.get("/api/studies/test_study_id/patients/test_patient_id/clinical-events") @@ -99,7 +115,7 @@ public void getAllClinicalEventsOfPatientInStudyMetaProjection() throws Exceptio BaseMeta baseMeta = new BaseMeta(); baseMeta.setTotalCount(2); - Mockito.when(clinicalEventService.getMetaPatientClinicalEvents(Mockito.anyString(), Mockito.anyString())) + when(clinicalEventService.getMetaPatientClinicalEvents(Mockito.anyString(), Mockito.anyString())) .thenReturn(baseMeta); mockMvc.perform(MockMvcRequestBuilders.get("/api/studies/test_study_id/patients/test_patient_id/clinical-events") @@ -114,8 +130,8 @@ public void getAllClinicalEventsInStudy() throws Exception { List clinicalEventList = createExampleClinicalEventList(); - Mockito.when(clinicalEventService.getAllClinicalEventsInStudy(Mockito.any(), - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + when(clinicalEventService.getAllClinicalEventsInStudy(any(), + any(), any(), any(), any(), any())) .thenReturn(clinicalEventList); mockMvc.perform(MockMvcRequestBuilders.get("/api/studies/test_study_id/clinical-events") @@ -152,7 +168,7 @@ public void getAllClinicalEventsInStudyMetaProjection() throws Exception { BaseMeta baseMeta = new BaseMeta(); baseMeta.setTotalCount(2); - Mockito.when(clinicalEventService.getMetaClinicalEvents(Mockito.anyString())) + when(clinicalEventService.getMetaClinicalEvents(Mockito.anyString())) .thenReturn(baseMeta); mockMvc.perform(MockMvcRequestBuilders.get("/api/studies/test_study_id/clinical-events") @@ -161,6 +177,58 @@ public void getAllClinicalEventsInStudyMetaProjection() throws Exception { .andExpect(MockMvcResultMatchers.header().string(HeaderKeyConstants.TOTAL_COUNT, "2")); } + @Test + @WithMockUser + public void fetchClinicalEventsMetaReturnsOkForValidRequest() throws Exception { + List clinicalEventList = createExampleClinicalEventMetaList(); + when(clinicalEventService.getClinicalEventsMeta(anyList(), anyList(), anyList())).thenReturn(clinicalEventList); + + PatientIdentifier patientIdentifier1 = new PatientIdentifier(); + ClinicalEventAttributeRequest clinicalEventAttributeRequest = new ClinicalEventAttributeRequest(); + ClinicalEventRequest clinicalEventRequest = new ClinicalEventRequest(); + clinicalEventRequest.setEventType(TEST_EVENT_TYPE_1); + clinicalEventRequest.setAttributes(new ArrayList<>()); + clinicalEventAttributeRequest.setClinicalEventRequests(Set.of(clinicalEventRequest)); + clinicalEventAttributeRequest.setPatientIdentifiers(Collections.singletonList(patientIdentifier1)); + + mockMvc.perform(MockMvcRequestBuilders.post("/api/clinical-events-meta/fetch").with(csrf()) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(clinicalEventAttributeRequest))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].clinicalEventId").doesNotExist()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].eventType").value(TEST_EVENT_TYPE_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].uniquePatientKey").value(TEST_UNIQUE_PATIENT_KEY_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].attributes[0].key").value(TEST_KEY_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].attributes[0].value").value(TEST_VALUE_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].attributes[1].key").value(TEST_KEY_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].attributes[1].value").value(TEST_VALUE_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].clinicalEventId").doesNotExist()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].eventType").value(TEST_EVENT_TYPE_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].uniquePatientKey").value(TEST_UNIQUE_PATIENT_KEY_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].attributes[0].key").value(TEST_KEY_3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].attributes[0].value").value(TEST_VALUE_3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].attributes[1].key").value(TEST_KEY_4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].attributes[1].value").value(TEST_VALUE_4)); + } + + @Test + @WithMockUser + public void fetchClinicalEventsMetaReturnsBadRequestForInvalidRequest() throws Exception { + + ClinicalEventAttributeRequest clinicalEventAttributeRequest = new ClinicalEventAttributeRequest(); + clinicalEventAttributeRequest.setClinicalEventRequests(new HashSet<>()); + clinicalEventAttributeRequest.setPatientIdentifiers(new ArrayList<>()); + + mockMvc.perform(MockMvcRequestBuilders.post("/api/clinical-events-meta/fetch").with(csrf()) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(clinicalEventAttributeRequest))) + .andExpect(MockMvcResultMatchers.status().isBadRequest()); + } + private final List createExampleClinicalEventList() { List clinicalEventList = new ArrayList<>(); ClinicalEvent clinicalEvent1 = new ClinicalEvent(); @@ -205,4 +273,41 @@ private final List createExampleClinicalEventList() { clinicalEventList.add(clinicalEvent2); return clinicalEventList; } + + private final List createExampleClinicalEventMetaList() { + List clinicalEventList = new ArrayList<>(); + ClinicalEvent clinicalEvent1 = new ClinicalEvent(); + clinicalEvent1.setUniquePatientKey(TEST_UNIQUE_PATIENT_KEY_1); + clinicalEvent1.setEventType(TEST_EVENT_TYPE_1); + List clinicalEventDataList1 = new ArrayList<>(); + ClinicalEventData clinicalEventData1 = new ClinicalEventData(); + clinicalEventData1.setClinicalEventId(TEST_CLINICAL_EVENT_ID_1); + clinicalEventData1.setKey(TEST_KEY_1); + clinicalEventData1.setValue(TEST_VALUE_1); + clinicalEventDataList1.add(clinicalEventData1); + ClinicalEventData clinicalEventData2 = new ClinicalEventData(); + clinicalEventData2.setClinicalEventId(TEST_CLINICAL_EVENT_ID_1); + clinicalEventData2.setKey(TEST_KEY_2); + clinicalEventData2.setValue(TEST_VALUE_2); + clinicalEventDataList1.add(clinicalEventData2); + clinicalEvent1.setAttributes(clinicalEventDataList1); + clinicalEventList.add(clinicalEvent1); + ClinicalEvent clinicalEvent2 = new ClinicalEvent(); + clinicalEvent2.setUniquePatientKey(TEST_UNIQUE_PATIENT_KEY_2); + clinicalEvent2.setEventType(TEST_EVENT_TYPE_2); + List clinicalEventDataList2 = new ArrayList<>(); + ClinicalEventData clinicalEventData3 = new ClinicalEventData(); + clinicalEventData3.setClinicalEventId(TEST_CLINICAL_EVENT_ID_2); + clinicalEventData3.setKey(TEST_KEY_3); + clinicalEventData3.setValue(TEST_VALUE_3); + clinicalEventDataList2.add(clinicalEventData3); + ClinicalEventData clinicalEventData4 = new ClinicalEventData(); + clinicalEventData4.setClinicalEventId(TEST_CLINICAL_EVENT_ID_2); + clinicalEventData4.setKey(TEST_KEY_4); + clinicalEventData4.setValue(TEST_VALUE_4); + clinicalEventDataList2.add(clinicalEventData4); + clinicalEvent2.setAttributes(clinicalEventDataList2); + clinicalEventList.add(clinicalEvent2); + return clinicalEventList; + } } diff --git a/src/test/java/org/cbioportal/web/SurvivalControllerTest.java b/src/test/java/org/cbioportal/web/SurvivalControllerTest.java new file mode 100644 index 00000000000..7c8532c515d --- /dev/null +++ b/src/test/java/org/cbioportal/web/SurvivalControllerTest.java @@ -0,0 +1,128 @@ +package org.cbioportal.web; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.cbioportal.model.ClinicalData; +import org.cbioportal.service.ClinicalEventService; +import org.cbioportal.web.config.TestConfig; +import org.cbioportal.web.parameter.ClinicalEventRequest; +import org.cbioportal.web.parameter.ClinicalEventRequestIdentifier; +import org.cbioportal.web.parameter.OccurrencePosition; +import org.cbioportal.web.parameter.PatientIdentifier; +import org.cbioportal.web.parameter.SurvivalRequest; +import org.hamcrest.Matchers; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebMvcTest +@ContextConfiguration(classes = {SurvivalController.class, TestConfig.class}) +public class SurvivalControllerTest { + + private static final String TEST_CANCER_STUDY_IDENTIFIER = "test_study_id"; + private static final String TEST_PATIENT_ID_1 = "test_patient_id_1"; + private static final String TEST_PATIENT_ID_2 = "test_patient_id_2"; + private static final String TEST_ATTRIBUTE_ID_PREFIX = "test_attribute_id_prefix"; + private static final String TEST_CLINICAL_ATTRIBUTE_ID_1 = "test_clinical_attribute_id_1"; + private static final String TEST_CLINICAL_ATTRIBUTE_ID_2 = "test_clinical_attribute_id_2"; + private static final String TEST_CLINICAL_ATTRIBUTE_VALUE_1 = "test_clinical_attribute_value_1"; + private static final String TEST_CLINICAL_ATTRIBUTE_VALUE_2 = "test_clinical_attribute_value_2"; + private static final String TEST_CLINICAL_EVENT_TYPE = "test_clinical_event_type"; + + + private final ObjectMapper objectMapper = new ObjectMapper(); + + @MockBean + private ClinicalEventService clinicalEventService; + + @Autowired + private MockMvc mockMvc; + + @Test + @WithMockUser + public void fetchSurvivalData() throws Exception { + List clinicalDataList = createClinicalDataList(); + when(clinicalEventService.getSurvivalData(anyList(), anyList(), any(), any())) + .thenReturn(clinicalDataList); + + SurvivalRequest survivalRequest = new SurvivalRequest(); + PatientIdentifier patientIdentifier = new PatientIdentifier(); + patientIdentifier.setPatientId(TEST_PATIENT_ID_1); + patientIdentifier.setStudyId(TEST_CANCER_STUDY_IDENTIFIER); + survivalRequest.setPatientIdentifiers(List.of(patientIdentifier)); + survivalRequest.setAttributeIdPrefix(TEST_ATTRIBUTE_ID_PREFIX); + + ClinicalEventRequest clinicalEventRequest = new ClinicalEventRequest(); + clinicalEventRequest.setEventType(TEST_CLINICAL_EVENT_TYPE); + clinicalEventRequest.setAttributes(new ArrayList<>()); + + ClinicalEventRequestIdentifier startEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + startEventRequestIdentifier.setClinicalEventRequests(Set.of(clinicalEventRequest)); + startEventRequestIdentifier.setPosition(OccurrencePosition.FIRST); + survivalRequest.setStartEventRequestIdentifier(startEventRequestIdentifier); + + ClinicalEventRequestIdentifier endEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + endEventRequestIdentifier.setClinicalEventRequests(Set.of(clinicalEventRequest)); + endEventRequestIdentifier.setPosition(OccurrencePosition.LAST); + survivalRequest.setEndEventRequestIdentifier(endEventRequestIdentifier); + + ClinicalEventRequestIdentifier censoredEventRequestIdentifier = new ClinicalEventRequestIdentifier(); + censoredEventRequestIdentifier.setClinicalEventRequests(Set.of(clinicalEventRequest)); + censoredEventRequestIdentifier.setPosition(OccurrencePosition.LAST); + survivalRequest.setCensoredEventRequestIdentifier(censoredEventRequestIdentifier); + + mockMvc.perform(MockMvcRequestBuilders.post("/api/survival-data/fetch").with(csrf()) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(survivalRequest))) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].studyId").value(TEST_CANCER_STUDY_IDENTIFIER)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].patientId").value(TEST_PATIENT_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].clinicalAttributeId").value(TEST_CLINICAL_ATTRIBUTE_ID_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].value").value(TEST_CLINICAL_ATTRIBUTE_VALUE_1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].studyId").value(TEST_CANCER_STUDY_IDENTIFIER)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].patientId").value(TEST_PATIENT_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].clinicalAttributeId").value(TEST_CLINICAL_ATTRIBUTE_ID_2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].value").value(TEST_CLINICAL_ATTRIBUTE_VALUE_2)); + } + + private List createClinicalDataList() { + List clinicalDataList = new ArrayList<>(); + + ClinicalData clinicalData1 = new ClinicalData(); + clinicalData1.setStudyId(TEST_CANCER_STUDY_IDENTIFIER); + clinicalData1.setPatientId(TEST_PATIENT_ID_1); + clinicalData1.setAttrId(TEST_CLINICAL_ATTRIBUTE_ID_1); + clinicalData1.setAttrValue(TEST_CLINICAL_ATTRIBUTE_VALUE_1); + clinicalDataList.add(clinicalData1); + + ClinicalData clinicalData2 = new ClinicalData(); + clinicalData2.setStudyId(TEST_CANCER_STUDY_IDENTIFIER); + clinicalData2.setPatientId(TEST_PATIENT_ID_2); + clinicalData2.setAttrId(TEST_CLINICAL_ATTRIBUTE_ID_2); + clinicalData2.setAttrValue(TEST_CLINICAL_ATTRIBUTE_VALUE_2); + clinicalDataList.add(clinicalData2); + + return clinicalDataList; + } +} diff --git a/src/test/resources/testSql.sql b/src/test/resources/testSql.sql index b5466af0d36..b20a1ecd89b 100644 --- a/src/test/resources/testSql.sql +++ b/src/test/resources/testSql.sql @@ -458,6 +458,7 @@ INSERT INTO clinical_event (CLINICAL_EVENT_ID,PATIENT_ID,START_DATE,STOP_DATE,EV INSERT INTO clinical_event (CLINICAL_EVENT_ID,PATIENT_ID,START_DATE,STOP_DATE,EVENT_TYPE) VALUES (2,1,233,345,'SPECIMEN'); INSERT INTO clinical_event (CLINICAL_EVENT_ID,PATIENT_ID,START_DATE,STOP_DATE,EVENT_TYPE) VALUES (3,2,213,445,'TREATMENT'); INSERT INTO clinical_event (CLINICAL_EVENT_ID,PATIENT_ID,START_DATE,STOP_DATE,EVENT_TYPE) VALUES (4,2,211,441,'SEQENCING'); +INSERT INTO clinical_event (CLINICAL_EVENT_ID,PATIENT_ID,START_DATE,STOP_DATE,EVENT_TYPE) VALUES (5,2,313,543,'TREATMENT'); INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (1,'STATUS','radiographic_progression'); INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (1,'SAMPLE_ID','TCGA-A1-A0SB-01'); @@ -468,6 +469,9 @@ INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (3,'AGENT', INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (3,'AGENT_TARGET','Directly to forehead, Elbow'); INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (3,'SAMPLE_ID','TCGA-A1-A0SD-01'); INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (4,'SAMPLE_ID','TCGA-A1-A0SD-01'); +INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (5,'EVENT_TYPE_DETAILED','AA III Recurrence1'); +INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (5,'AGENT','abc'); +INSERT INTO clinical_event_data (CLINICAL_EVENT_ID,KEY,VALUE) VALUES (5,'AGENT_TARGET','Left arm, Ankle'); INSERT INTO geneset (ID,GENETIC_ENTITY_ID,EXTERNAL_ID,NAME,DESCRIPTION,REF_LINK) VALUES (1,17,'MORF_ATRX','MORF ATRX name','Morf description','https://morf_link'); INSERT INTO geneset (ID,GENETIC_ENTITY_ID,EXTERNAL_ID,NAME,DESCRIPTION,REF_LINK) VALUES (2,18,'HINATA_NFKB_MATRIX','HINATA NFKB MATRIX name','Hinata description','https://hinata_link');