2016-10-17 156 views
1

我的報告顯示,根據每個病人只有最新診斷其date_of_diagnosis - 所有其他記錄被抑制:忽略交叉抑制記錄

Records after suppression

我在交叉表診斷和年齡組的總結。交叉表在打印之前進行評估,所以任何試圖抑制,共享變量或總結之後會填充交叉表。這意味着總在各年齡組是正確的,因爲每個病人只有一歲 - 但如果患者有一個以上的診斷,即使他們壓制,他們獲得多次計算:

Crosstab (Much larger in real life. Simplified/cropped for screenshot)

我絕對是必須由於涉及大量的診斷和年齡組,因此使用交叉表。我怎樣才能讓交叉表忽略被壓制的記錄?或者,如果我需要使用自定義的SQL命令表,我如何重寫現有的SQL以忽略過時的記錄?


水晶的自動生成的SQL(通過ODBC):

SELECT "Codes"."diagnosis_code", 
     "Codes"."diagnosis_value", 
     "Codes"."PATID", 
     "Codes"."FACILITY", 
     "Codes"."EPISODE_NUMBER", 
     "Record"."date_of_diagnosis" 

FROM "SYSTEM"."Codes" "Codes", 
     "SYSTEM"."Entry" "Entry", 
     "SYSTEM"."Record" "Record" 

WHERE "Codes"."DiagnosisEntry"="Entry"."ID" AND 
     "Codes"."EPISODE_NUMBER"="Entry"."EPISODE_NUMBER" AND 
     "Codes"."FACILITY"="Entry"."FACILITY" AND 
     "Codes"."PATID"="Entry"."PATID" AND 
     "Entry"."DiagnosisRecord"="Record"."ID" AND 
     "Entry"."EPISODE_NUMBER"="Record"."EPISODE_NUMBER" AND 
     "Entry"."FACILITY"="Record"."FACILITY" AND 
     "Entry"."PATID"="Record"."PATID" 
+0

只是說:如果你不會使用抑制數據,那麼也許你可以添加一個條件到你的查詢:'AND Date_Of_Diagnosis IS NOT NULL' – Zeina

+0

只是一個注意:這不是一個實際的方式來加入你的你應該嘗試使用LEFT或INNER JOIN – Zeina

+0

@Zeina(我知道,這只是Crystal自動生成的查詢,如果我需要重寫查詢來解決這個問題,我將使用Joins。)問題不是當診斷日期爲空時,診斷日期不是每位患者的最新*診斷時。交叉表忽略任何抑制。 – 4444

回答

0

大廈關閉Muffaddal沙基爾的回答,我能寫這個查詢來執行正確的過濾器:

SELECT "Codes"."PATID", 
     "Codes"."diagnosis_code", 
     "Codes"."diagnosis_value", 
     "Codes"."FACILITY", 
     "Codes"."EPISODE_NUMBER", 
     "Record"."date_of_diagnosis" 

FROM "SYSTEM"."codes" "Codes", 
    "SYSTEM"."entry" "Entry", 
    "SYSTEM"."record" "Record" 

WHERE "Codes"."DiagnosisEntry"="Entry"."ID" AND 
     "Codes"."EPISODE_NUMBER"="Entry"."EPISODE_NUMBER" AND 
     "Codes"."FACILITY"="Entry"."FACILITY" AND 
     "Codes"."PATID"="Entry"."PATID" AND 
     "Entry"."DiagnosisRecord"="Record"."ID" AND 
     "Entry"."EPISODE_NUMBER"="Record"."EPISODE_NUMBER" AND 
     "Entry"."FACILITY"="Record"."FACILITY" AND 
     "Entry"."PATID"="Record"."PATID" 

AND "Record"."date_of_diagnosis" = ( 
    SELECT MAX("Record2"."date_of_diagnosis") 

    FROM "SYSTEM"."entry" "Entry2", 
     "SYSTEM"."record" "Record2" 

    WHERE "Entry2"."DiagnosisRecord"="Record2"."ID" AND 
      "Entry2"."EPISODE_NUMBER"="Record2"."EPISODE_NUMBER" AND 
      "Entry2"."FACILITY"="Record2"."FACILITY" AND 
      "Entry2"."PATID"="Record2"."PATID" AND 
      "Record"."PATID"="Record2"."PATID" 
) 

的主要區別是:

  1. 子查詢使用唯一的別名從主查詢。
  2. 最後一行"Record"."PATID"="Record2"."PATID" - 如果沒有這個,查詢只拉回一個診斷(最新一個在整個系統中)。但現在檢查每人最近診斷
1

你只需要一套診斷中的最新診斷。所以我建議:

SELECT "Codes"."PATID", 
    "Codes"."diagnosis_code", 
    "Codes"."diagnosis_value", 
    "Codes"."FACILITY", 
    "Codes"."EPISODE_NUMBER", 
    "Record"."date_of_diagnosis" 

FROM "SYSTEM"."Codes" "Codes", 
    "SYSTEM"."Entry" "Entry", 
    "SYSTEM"."Record" "Record" 

WHERE "Codes"."DiagnosisEntry"="Entry"."ID" AND 
    "Codes"."EPISODE_NUMBER"="Entry"."EPISODE_NUMBER" AND 
    "Codes"."FACILITY"="Entry"."FACILITY" AND 
    "Codes"."PATID"="Entry"."PATID" AND 
    "Entry"."DiagnosisRecord"="Record"."ID" AND 
    "Entry"."EPISODE_NUMBER"="Record"."EPISODE_NUMBER" AND 
    "Entry"."FACILITY"="Record"."FACILITY" AND 
    "Entry"."PATID"="Record"."PATID" 
    AND "Entry"."date_of_diagnosis" = (SELECT MAX("date_of_diagnosis") FROM  
    "DiagonsisRecord" "A" WHERE "A"."DiagnosisRecord"="Entry"."DiagnosisRecord" ) 

這應該讓每個病人的最大Date_of_Diagnosis並通過濾波器參數來獲取患者的最後診斷。