Skip to content

Commit cf13b3e

Browse files
committed
restore accidentally deleted ClinicalEventMapper SQL
1 parent 9c3468d commit cf13b3e

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

src/main/resources/org/cbioportal/legacy/persistence/mybatis/ClinicalEventMapper.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,110 @@
172172
GROUP BY clinical_event.event_type, patient.stable_id
173173
</select>
174174

175+
<select id="getTimelineEvents" resultType="org.cbioportal.legacy.model.ClinicalEvent">
176+
SELECT
177+
ANY_VALUE(patient.stable_id) AS patientId,
178+
cancer_study.cancer_study_identifier AS studyId,
179+
MIN(clinical_event.start_date) AS startDate,
180+
GREATEST(MAX(clinical_event.start_date), COALESCE(MAX(clinical_event.stop_date),0)) AS stopDate
181+
FROM clinical_event
182+
INNER JOIN patient ON clinical_event.patient_id = patient.internal_id
183+
INNER JOIN clinical_event_data ON clinical_event.clinical_event_id = clinical_event_data.clinical_event_id
184+
INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id
185+
<where>
186+
<if test="patientIds == null and studyIds != null">
187+
cancer_study.cancer_study_identifier IN
188+
<if test="studyIds.isEmpty()">(NULL)</if>
189+
<if test="!studyIds.isEmpty()"><foreach item="item" collection="studyIds" open="(" separator="," close=")">#{item}</foreach></if>
190+
</if>
191+
<if test="patientIds != null">
192+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() == 1">
193+
<bind name="patientArray" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@listToArray(patientIds)" />
194+
cancer_study.cancer_study_identifier = #{studyIds[0]} AND
195+
patient.stable_id IN (
196+
#{patientArray, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
197+
)
198+
</if>
199+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() > 1">
200+
<bind name="patientUniqueKeys" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@combineStudyAndPatientIds(studyIds, patientIds)" />
201+
CONCAT(cancer_study.cancer_study_identifier, ':', patient.stable_id) IN (
202+
#{patientUniqueKeys, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
203+
)
204+
</if>
205+
</if>
206+
<if test="!clinicalEvents.isEmpty()">
207+
AND
208+
<foreach item="element" collection="clinicalEvents" open="(" separator="OR " close=")">
209+
<if test="element.attributes == null || element.attributes.isEmpty()">
210+
clinical_event.event_type = #{element.eventType}
211+
</if>
212+
<if test="element.attributes != null and !element.attributes.isEmpty()">
213+
(CONCAT(clinical_event.event_type, '_', clinical_event_data.key, '_', clinical_event_data.value)) IN
214+
<foreach item="attribute" collection="element.attributes" open="(" separator="," close=")">
215+
CONCAT(#{element.eventType}, '_', #{attribute.key}, '_', #{attribute.value})
216+
</foreach>
217+
</if>
218+
</foreach>
219+
</if>
220+
</where>
221+
GROUP BY
222+
clinical_event.patient_id, cancer_study.cancer_study_identifier;
223+
</select>
224+
225+
<resultMap id="clinicalEventsResultMap" type="org.cbioportal.legacy.model.ClinicalEvent">
226+
<result property="eventType" column="eventType"/>
227+
<collection property="attributes" ofType="org.cbioportal.legacy.model.ClinicalEventData">
228+
<result property="key" column="key"/>
229+
<result property="value" column="value"/>
230+
</collection>
231+
</resultMap>
232+
233+
<select id="getClinicalEventsMeta" resultMap="clinicalEventsResultMap">
234+
SELECT
235+
LOWER(clinical_event.event_type) AS eventType,
236+
LOWER(clinical_event_data.key) AS "key",
237+
LOWER(clinical_event_data.value) AS value
238+
FROM clinical_event
239+
INNER JOIN patient ON clinical_event.patient_id = patient.internal_id
240+
INNER JOIN clinical_event_data ON clinical_event.clinical_event_id = clinical_event_data.clinical_event_id
241+
INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id
242+
<where>
243+
<if test="patientIds == null and studyIds != null">
244+
cancer_study.cancer_study_identifier IN
245+
<if test="studyIds.isEmpty()">(NULL)</if>
246+
<if test="!studyIds.isEmpty()"><foreach item="item" collection="studyIds" open="(" separator="," close=")">#{item}</foreach></if>
247+
</if>
248+
<if test="patientIds != null">
249+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() == 1">
250+
<bind name="patientArray" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@listToArray(patientIds)" />
251+
cancer_study.cancer_study_identifier = #{studyIds[0]} AND
252+
patient.stable_id IN (
253+
#{patientArray, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
254+
)
255+
</if>
256+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() > 1">
257+
<bind name="patientUniqueKeys" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@combineStudyAndPatientIds(studyIds, patientIds)" />
258+
CONCAT(cancer_study.cancer_study_identifier, ':', patient.stable_id) IN (
259+
#{patientUniqueKeys, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
260+
)
261+
</if>
262+
</if>
263+
<if test="!clinicalEvents.isEmpty()">
264+
AND
265+
<foreach item="element" collection="clinicalEvents" open="(" separator="OR " close=")">
266+
<if test="element.attributes == null || element.attributes.isEmpty()">
267+
clinical_event.event_type = #{element.eventType}
268+
</if>
269+
<if test="element.attributes != null and !element.attributes.isEmpty()">
270+
(CONCAT(clinical_event.event_type, '_', clinical_event_data.key)) IN
271+
<foreach item="attribute" collection="element.attributes" open="(" separator="," close=")">
272+
CONCAT(#{element.eventType}, '_', #{attribute.key})
273+
</foreach>
274+
</if>
275+
</foreach>
276+
</if>
277+
</where>
278+
GROUP BY clinical_event.event_type , clinical_event_data.key, clinical_event_data.value;
279+
</select>
280+
175281
</mapper>

0 commit comments

Comments
 (0)