| 76 | 16. Because modifiers are now being used, the Instance_Num column of the Observation_Fact table becomes very important. Therefore we need to create instance numbers for observation facts that didn't have them before using this script: |
| 77 | |
| 78 | {{{#!sql |
| 79 | BEGIN TRANSACTION |
| 80 | |
| 81 | UPDATE o |
| 82 | SET INSTANCE_NUM = a.rnum |
| 83 | FROM Observation_Fact o |
| 84 | JOIN ( |
| 85 | SELECT row_number() OVER(PARTITION BY encounter_num, patient_num, concept_cd, provider_id, start_date, modifier_cd ORDER BY encounter_num, patient_num, concept_cd, provider_id, start_date, modifier_cd ) as rnum, |
| 86 | obf.* |
| 87 | FROM Observation_Fact obf |
| 88 | ) a ON a.Encounter_Num = o.Encounter_Num |
| 89 | AND a.Concept_Cd = o.Concept_Cd |
| 90 | AND a.Provider_Id = o.Provider_Id |
| 91 | AND a.Start_Date = o.Start_Date |
| 92 | AND a.Modifier_Cd = o.Modifier_Cd |
| 93 | |
| 94 | -- COMMIT |
| 95 | }}} |