I have a table that contains codes (i.e. 8202-6) and has a resulting value in a different column. I used the "Case When" function to take the codes out a single column and place them in separate columns based on the code number. However, now I end up with a bunch of null values in the rows and one code with one result. I would like to replace the actual code with it's corresponding value (i.e. 8206-6 = Height, result 75). So in the Height column I get the LOINC code instead of the Height value of 75. Can anyone help me figure out the right code to use. Below is an example of the code that I'm using just to get the columns separated.
Select Distinct
p.PatientID,
Convert(varchar, fs.obsdate, 101) as Date_of_Service,
p.LASTNAME,
p.FIRSTNAME,
CONVERT(varchar, "p"."DATEOFBIRTH", 101) as DOB,
Case When fs.loinccode='8302-2' Then fs.loinccode end as Height,
Case When fs.loinccode='3141-9' Then fs.loinccode end as Weight,
Case When fs.loinccode='8310-5' Then fs.loinccode end as Temperature,
Case When fs.loinccode='8287-5' Then fs.loinccode end as HeadCircumf,
Case When fs.loinccode='8867-4' Then fs.loinccode end as Pulse,
Case When fs.loinccode='9279-1' Then fs.loinccode end as Respiration,
Case When fs.loinccode='8480-6' Then fs.loinccode end as BPSystolic,
Case When fs.loinccode='8462-4' Then fs.loinccode end as BPDiastolic,
fs.obsvalue as Test_Results,
fs.units as Test_Units
From
PERSON as p
Left Outer join flowsheet_observation fs on fs.pid=p.pid
Result:
Height Weight Temperature HeadCircumf Pulse Respiration BPSystolic BPDiastolic Test_Results Test_Units
NULL NULL NULL NULL NULL NULL NULL NULL + history of lef tshoulder dislocation 10 years ago Current Meds: NULL
NULL NULL NULL NULL NULL NULL NULL NULL never NULL
NULL NULL NULL NULL NULL NULL NULL NULL regular NULL
NULL NULL NULL NULL NULL NULL NULL NULL tympanic NULL
NULL NULL NULL NULL NULL NULL NULL 8462-4 100 mm Hg
NULL NULL NULL NULL NULL NULL 8480-6 NULL 140 mm Hg
NULL NULL NULL NULL 8867-4 NULL NULL NULL 82 /min
NULL NULL 8310-5 NULL NULL NULL NULL NULL 99.1 deg F
NULL 3141-9 NULL NULL NULL NULL NULL NULL 283 lb
8302-2 NULL NULL NULL NULL NULL NULL NULL 72.5 in
NULL NULL NULL NULL NULL NULL NULL NULL 37.72 NULL
NULL NULL NULL NULL NULL NULL NULL NULL regular NULL
NULL NULL NULL NULL NULL NULL NULL NULL tympanic NULL
NULL NULL NULL NULL NULL NULL NULL 8462-4 100 mm Hg
NULL NULL NULL NULL NULL NULL 8480-6 NULL 142 mm Hg
NULL NULL NULL NULL 8867-4 NULL NULL NULL 86 /min
NULL NULL 8310-5 NULL NULL NULL NULL NULL 99.4 deg F
NULL 3141-9 NULL NULL NULL NULL NULL NULL 281 lb
Any help with this would be greatly appreciated.