|
| 1 | +-- ================================================================================================= |
| 2 | +-- Add MPA Clinical remarks: By, Lakshmi Kolli |
| 3 | +-- Created on: 1/25/2024 |
| 4 | +/* Description: Created 1 temp table to store the clinical remarks records. |
| 5 | + The stored proc manages the addition and deleting clinical remarks data from the temp table |
| 6 | + at the time of execution via ETL process. |
| 7 | + */ |
| 8 | +-- ================================================================================================= |
| 9 | + |
| 10 | +--Drop table if exists |
| 11 | +EXEC core.fn_dropifexists 'Temp_ClnRemarks','onprc_ehr','TABLE'; |
| 12 | +--Drop Stored proc if exists |
| 13 | +EXEC core.fn_dropifexists '[onprc_ehr].[MPA_ClnRemarkAddition]', 'onprc_ehr', 'PROCEDURE'; |
| 14 | +GO |
| 15 | + |
| 16 | +-- Create the temp table |
| 17 | +CREATE TABLE onprc_ehr.Temp_ClnRemarks |
| 18 | +( |
| 19 | + date datetime, |
| 20 | + qcstate int, |
| 21 | + participantid nvarchar(32), |
| 22 | + project int, |
| 23 | + remark nvarchar(250) , |
| 24 | + p nvarchar(250) , |
| 25 | + performedby nvarchar(250) , |
| 26 | + category nvarchar(250) , |
| 27 | + taskid nvarchar(4000), |
| 28 | + createdby int, |
| 29 | + modifiedby int |
| 30 | +) |
| 31 | +; |
| 32 | + |
| 33 | +GO |
| 34 | + |
| 35 | +-- Create the stored proc |
| 36 | +/****** Object: StoredProcedure [onprc_ehr].[MPA_ClnRemarkAddition] Script Date: 1/25/2024 *****/ |
| 37 | +-- ================================================================================= |
| 38 | + -- Author: Lakshmi Kolli |
| 39 | + -- Create date: 1/25/2024 |
| 40 | + -- Description: This procedure identifies if an animal received an MPA injection |
| 41 | + -- and inserts a clinical remark into animal's record. |
| 42 | +-- ================================================================================= |
| 43 | + |
| 44 | +CREATE PROCEDURE [onprc_ehr].[MPA_ClnRemarkAddition] |
| 45 | +AS |
| 46 | + |
| 47 | +DECLARE |
| 48 | +@MPACount Int, |
| 49 | + @taskId nvarchar(4000) |
| 50 | + |
| 51 | +BEGIN |
| 52 | + --Delete all rows from the temp_Drug table |
| 53 | + Delete From onprc_ehr.Temp_ClnRemarks |
| 54 | + |
| 55 | + --Check if the MPA injection E-85760 was administered today |
| 56 | + Select @MPACount = COUNT(*) From studyDataset.c6d178_drug |
| 57 | + Where code = 'E-85760' And CONVERT(DATE, date) = CONVERT(DATE, GETDATE()) And qcstate = 18 |
| 58 | + |
| 59 | + --Found entries, so, enter the clinical remarks now |
| 60 | + If @MPACount > 0 |
| 61 | + Begin |
| 62 | + -- Create a Task entry in ehr.tasks table |
| 63 | + Set @taskid = NEWID() -- creating taskid |
| 64 | + Insert Into ehr.tasks |
| 65 | + (taskid, category, title, formtype, qcstate, assignedto, duedate, createdby, created, |
| 66 | + container, modifiedby, modified, description, datecompleted) |
| 67 | + Values |
| 68 | + (@taskid, 'Task', 'Bulk Clinical Entry', 'Bulk Clinical Entry', 18, 1003, GETDATE(), 1003, GETDATE(), |
| 69 | + 'CD17027B-C55F-102F-9907-5107380A54BE', 1003, GETDATE(), 'Created by the ETL process', GETDATE()) |
| 70 | + |
| 71 | + --Insert the clinical remark into the temp clinical remarks table. |
| 72 | + /* Get all the Animals who had MPA injection today from studyDataset.c6d178_drug |
| 73 | + and INSERT the data into the studyDataset.c6d185_clinremarks table */ |
| 74 | + Insert Into onprc_ehr.Temp_ClnRemarks ( |
| 75 | + date, qcstate, participantid, project, remark, p, performedby, category, taskid, createdby, modifiedby |
| 76 | + ) |
| 77 | + Select GETDATE(), 18, participantid, project, 'Remark entered by the ETL process', 'MPA injection administered', 'onprcitsupport@ohsu.edu', 'Clinical', @taskId, 1003, 1003 |
| 78 | + From studyDataset.c6d178_drug |
| 79 | + Where code = 'E-85760' And CONVERT(DATE, date) = CONVERT(DATE, GETDATE()) And qcstate = 18 |
| 80 | + End |
| 81 | + |
| 82 | +END |
| 83 | + |
| 84 | +GO |
0 commit comments