From 9995add75f06a5b9d4fce445fb602e6c35fdaba3 Mon Sep 17 00:00:00 2001
From: "Hubbell, Harrison Taylor" <hhubbell@partners.org>
Date: Mon, 8 Jul 2019 14:03:19 -0400
Subject: [PATCH] Closes #9; closes #13. See log for details.

This commit resolves two outstanding issues where non-inpatient events
were being included in the EncounterInpatientEncounters view. We believe
this occurred because of certain types of contacts that happened during
the encounter, such as surgeries and imaging. These contacts would also
spawn a new PatientEncounterID.

To resolve both of these issues, we will exclude
ADTPatientStatusDSC = 'Hospital Outpatient Visit'.
---
 encounter_inpatient_encounters/README.md                    | 4 ++++
 .../encounter_inpatient_encounters.sql                      | 6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/encounter_inpatient_encounters/README.md b/encounter_inpatient_encounters/README.md
index 0d53599..f53f079 100755
--- a/encounter_inpatient_encounters/README.md
+++ b/encounter_inpatient_encounters/README.md
@@ -16,6 +16,10 @@ Identifies encounters with an inpatient event at all available institutions.
 
 Inpatient encounters are defined as encounters with a contact in an inpatient department. All completed and in-progress encounters are included. Encounters that began in the emergency department are included, and there will be overlap between this view and the [EncounterEDEncounters](/encounter_ed_encounters/) view.
 
+Specific exclusions are:
+1. Non-inpatient `ADTPatientClassification` records are removed. These include encounter types such as "Observation."
+2. Hospital outpatient visit `ADTPatientStatus` records are removed. If a patient is admitted, this will change to "Admission." Some encounter types of this nature are imaging and radiation.
+
 ### Encounter Type Calculation
 
 Encounters that began as an emergency encounter are classified as "ED-to-Inpatient." Otherwise, the encounter type is "Inpatient."
diff --git a/encounter_inpatient_encounters/encounter_inpatient_encounters.sql b/encounter_inpatient_encounters/encounter_inpatient_encounters.sql
index 56a34a4..952ab80 100755
--- a/encounter_inpatient_encounters/encounter_inpatient_encounters.sql
+++ b/encounter_inpatient_encounters/encounter_inpatient_encounters.sql
@@ -62,5 +62,7 @@ from Epic.Encounter.PatientEncounterHospital_Enterprise peh
     left join Epic.Reference.DRG drg_ref on drg.DRGRecordID = drg_ref.DRGRecordID
 where peh.InpatientAdmitDTS is not null
     and peh.InpatientAdmitEventID is not null
-    -- Removes "Observation" inpatient encounters
-    and peh.ADTPatientClassificationDSC = 'Inpatient';
+    -- Removes non-"Inpatient" encounters, such as observation
+    and peh.ADTPatientClassificationCD = '101'
+    -- Removes "Outpatient Hospital Visit" encounters, such as imaging
+    and peh.ADTPatientStatusCD <> 6;
-- 
GitLab