I'm pulling lab values from a hospital DB. They are stored in a table like this.
Table: LABS
Columns: LAB_ID, PATIENT_ID, LAB_TYPE, DATE, RESULT, UNITS
Example: 123456, 654321, "WBC", 1/1/2000, 10.2, "K/uL"
I have a list of PATIENT_IDs and certain LAB_TYPES from certain dates that I want to look at.
Ultimately I want to compile this into a table like this:
Table: Results
Columns: PATIENT_ID, DATE, WBC, WBC_UNITS, RBC, RBC_UNITS, HCT, HCT_UNITS, HGB, HGB_UNITS
Example: 123456, 1/1/2000, 10.2, "K/uL", 4.8, "M/uL", 45.2, "%", 15.9, "g/dL"
I want to group results by patient and get the once closest to a specified date. I.E. If a patient had multiple WBC tests done, I only want the result from the one closest to a specific date. If RBC was tested on different days than WBC, give me the result closest to the specified date.
Table: LABS
Columns: LAB_ID, PATIENT_ID, LAB_TYPE, DATE, RESULT, UNITS
Example: 123456, 654321, "WBC", 1/1/2000, 10.2, "K/uL"
I have a list of PATIENT_IDs and certain LAB_TYPES from certain dates that I want to look at.
Ultimately I want to compile this into a table like this:
Table: Results
Columns: PATIENT_ID, DATE, WBC, WBC_UNITS, RBC, RBC_UNITS, HCT, HCT_UNITS, HGB, HGB_UNITS
Example: 123456, 1/1/2000, 10.2, "K/uL", 4.8, "M/uL", 45.2, "%", 15.9, "g/dL"
I want to group results by patient and get the once closest to a specified date. I.E. If a patient had multiple WBC tests done, I only want the result from the one closest to a specific date. If RBC was tested on different days than WBC, give me the result closest to the specified date.