1 Introduction

This lab will focus on reporting on lab orders and results. medications and medication orders. We will use admissions for COPD exacerbations as a sample case, building on code from prior labs.

2 WBC

How many times does the term “WBC” show up in the LabComponentResultFact table? Look at the ComponentName column and use “LIKE” to identify them. The percent sign (%) is a wildcard.

2.1 Answer

SELECT count(*)
FROM deid_uf.LabComponentResultFact
WHERE ComponentName LIKE '%WBC%'

3 Relevant WBCs

How many different ways can a patient’s serum white blood cell count be measured (the WBC count measured in a patient’s blood, not any other body fluids, such as urine, CSF, etc, and not descriptions of the white blood cells themselves)? You should be able to narrow it down to a small-ish list with a query, and from that list, pick the relevant ones. Show your query for the near-final list, and then enter your final number.

There are many tests where SpecimenSource is *Unspecified, so to have a comprehensive query, I would recommend looking through all labs that

WHERE SpecimenSource = ‘Blood’

OR SpecimenSource = ‘Whole Blood’

OR SpecimenSource = ‘Serum’

OR SpecimenSource = ’*Unspecified’

OR SpecimenSouce IS NULL

3.1 Answer

SELECT DISTINCT LabComponentKey,
                ComponentName
FROM deid_uf.LabTestFact
         LEFT JOIN deid_uf.LabTestComponentResultMappingFact
         ON LabTestFact.LabTestKey = LabTestComponentResultMappingFact.LabTestKey
         LEFT JOIN deid_uf.LabComponentResultFact
         ON LabComponentResultFact.LabComponentResultKey = LabTestComponentResultMappingFact.LabComponentResultKey
WHERE (ComponentName LIKE '%white blood%' OR ComponentName LIKE '%WBC%')
  AND (SpecimenSource = 'Blood'
        OR SpecimenSource = 'Whole Blood'
        OR SpecimenSource = 'Serum'
        OR SpecimenSource = '*Unspecified'
        OR SpecimenSource IS NULL)
## [1] 4

4 Top 4 WBC

List the top 4 most common serum WBC tests for ALL patients? If there is something in the top of your list that you dont think belongs, you can exclude it using a WHERE clause. ## Answer


SELECT TOP 4
           LabComponentKey,
           ComponentName,
           count(*) AS N
FROM deid_uf.LabTestFact
         LEFT JOIN deid_uf.LabTestComponentResultMappingFact
         ON LabTestFact.LabTestKey = LabTestComponentResultMappingFact.LabTestKey
         LEFT JOIN deid_uf.LabComponentResultFact
         ON LabComponentResultFact.LabComponentResultKey = LabTestComponentResultMappingFact.LabComponentResultKey
WHERE (ComponentName LIKE '%white blood%' OR ComponentName LIKE '%WBC%')
  AND ComponentName != 'Morphology (WBC,MISC)'
  AND (SpecimenSource = 'Blood'
        OR SpecimenSource = 'Whole Blood'
        OR SpecimenSource = '*Unspecified')
GROUP BY LabComponentKey, ComponentName
ORDER BY N DESC

5 WBC in COPD

How many WBC tests (for this exercise, use LabComponentKey 994 and 6482) were done during the admissions for patient with a COPD Exacerbation (ICD-10 J44.1) since 2016?

5.1 Answer

SELECT count(*)
FROM deid_uf.EncounterFact e
         LEFT JOIN deid_uf.DiagnosisTerminologyDim d ON d.DiagnosisKey = e.PrimaryDiagnosisKey
         LEFT JOIN deid_uf.LabComponentResultFact r ON r.PatientDurableKey = e.PatientDurableKey
WHERE year(e.DateKeyValue) >= 2016
  AND d.Type = 'ICD-10-CM'
  AND d.Value = 'J44.1'
  AND e.IsHospitalAdmission = 1
  AND DischargeDisposition <> '*Unspecified'
  AND (r.CollectionDateKeyValue >= e.AdmissionDateKeyValue AND r.CollectionDateKeyValue <= e.DischargeDateKeyValue)
  AND (r.LabComponentKey = 994 OR r.LabComponentKey = 6482)

6 WBC Per Patient

How many WBC tests were ordered for each patient above? Your result should have one row per patient per admission (the same patient may have been admitted multiple times), with one column that counts the total number of WBC that patient had.

6.1 Answer

SELECT DISTINCT e.PatientDurableKey,
                e.EncounterKey,
                count(e.encounterKey),
                count(LabComponentKey) AS WBCNumber
FROM deid_uf.EncounterFact e
         LEFT JOIN deid_uf.DiagnosisTerminologyDim d ON d.DiagnosisKey = e.PrimaryDiagnosisKey
         LEFT JOIN deid_uf.LabComponentResultFact r ON r.PatientDurableKey = e.PatientDurableKey
WHERE year(e.DateKeyValue) >= 2016
  AND d.Type = 'ICD-10-CM'
  AND d.Value = 'J44.1'
  AND e.IsHospitalAdmission = 1
  AND DischargeDisposition <> '*Unspecified'
  AND (r.CollectionDateKeyValue >= e.AdmissionDateKeyValue AND r.CollectionDateKeyValue <= e.DischargeDateKeyValue)
  AND (r.LabComponentKey = 994 OR r.LabComponentKey = 6842)
GROUP BY e.PatientDurableKey, e.EncounterKey

7 WBC Results

Generate a table that shows the result of all of the WBC results for the patients in the previous question, along with the units, expected ranges, if it was abnormal, and any flags

7.1 Answer

SELECT e.PatientDurableKey,
       e.AdmissionDateKeyValue,
       e.DischargeDateKeyValue,
       r.CollectionDateKeyValue,
       r.ResultDateKeyValue,
       r.ProcedureName,
       r.ComponentName,
       r.Value,
       r.Unit,
       r.ReferenceValues,
       r.Abnormal,
       r.Flag
FROM deid_uf.EncounterFact e
         LEFT JOIN deid_uf.DiagnosisTerminologyDim d ON d.DiagnosisKey = e.PrimaryDiagnosisKey
         LEFT JOIN deid_uf.LabComponentResultFact r ON r.PatientDurableKey = e.PatientDurableKey
WHERE year(e.DateKeyValue) >= 2016
  AND d.Type = 'ICD-10-CM'
  AND d.Value = 'J44.1'
  AND e.IsHospitalAdmission = 1
  AND DischargeDisposition <> '*Unspecified'
  AND (r.CollectionDateKeyValue >= e.AdmissionDateKeyValue AND r.CollectionDateKeyValue <= e.DischargeDateKeyValue)
  AND (r.LabComponentKey = 994 OR r.LabComponentKey = 6842)

8 Lab Counts

Count the number of each type of lab (using ComponentName) that was performed for patients admitted with a COPD exacerbation during their admission.

8.1 Answer

SELECT r.ComponentName, count(*) as N
FROM deid_uf.EncounterFact e
         LEFT JOIN deid_uf.DiagnosisTerminologyDim d ON d.DiagnosisKey = e.PrimaryDiagnosisKey
         LEFT JOIN deid_uf.LabComponentResultFact r ON r.PatientDurableKey = e.PatientDurableKey
WHERE year(e.DateKeyValue) >= 2016
  AND d.Type = 'ICD-10-CM'
  AND d.Value = 'J44.1'
  AND e.IsHospitalAdmission = 1
  AND DischargeDisposition <> '*Unspecified'
  AND (r.CollectionDateKeyValue >= e.AdmissionDateKeyValue AND r.CollectionDateKeyValue <= e.DischargeDateKeyValue)
group By r.ComponentName
order by N desc

9 Own Project

9.1 Writing

Modify the Measurements section to include at least two different lab-related measurements, and specify how they relate to your project observations in terms of a date range, encounter linkage, etc. In the exercise, the admission and discharge dates were used as the date range for lab values of interest; you’ll need to try something different if you are working with outpatient data.

9.2 Planning/Presenting Results

Before you start coding, modify your Table 1 design to include rows for the two or more lab-related measurements. Decide whether you want to dichotomize the lab results (e.g., “LDL > 130 mg/dl, n(%)”) or present the mean+-SD or median IQR, or both, etc.

9.3 Coding

Refine your Table 1 SQL/R/Stata code to obtain the results needed to fill in the new lab-related rows in your Table 1.