Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions onprc_ehr/resources/etls/ClinicalObservation_TestScores.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>

<etl xmlns="http://labkey.org/etl/xml">

<name>Clinical_Observation_TestScores_Process</name>

<description>Create new sets of Clinical Observation Test Scores</description>


<transforms>

<transform id="Stored_ClinicalObservationScores" type="StoredProcedure">
<description>Runs a stored procedure that generates Clinical Observation Test Scores</description>
<procedure schemaName="onprc_ehr" procedureName="p_Create_TB_Observationrecords">
</procedure>
</transform>


<transform id="step1a">

<description>Transfer ehr_task temp to EHR Tasks</description>

<source schemaName="onprc_ehr" queryName="Observation_EHRTasks"/>

<destination schemaName="EHR" queryName="tasks" />

</transform>

<transform id="step2a">

<description>Transfer temp data to Study Clinical Observations</description>

<source schemaName="onprc_ehr" queryName="Temp_Clinical_Observations"/>

<destination schemaName="study" queryName="clinical_observations" />

</transform>


</transforms>

<schedule>
<!--Scheduled to execute once 9Pm daily -->
<cron expression="0 0 21 * * ?"/>

</schedule>


</etl>




Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@

EXEC core.fn_dropifexists 'TB_TestTemp', 'onprc_ehr', 'TABLE', NULL;
GO
EXEC core.fn_dropifexists 'Temp_Clinical_Observations', 'onprc_ehr', 'TABLE', NULL;
GO
EXEC core.fn_dropifexists 'Temp_Clinical_Observations_Master', 'onprc_ehr', 'TABLE', NULL;

EXEC core.fn_dropifexists 'Observation_EHRTasks', 'onprc_ehr', 'TABLE', NULL;
GO





CREATE TABLE [onprc_ehr].[TB_TestTemp](
[rowid] [int] IDENTITY(100,1) NOT NULL,
animalid varchar(200) NULL,
date datetime NULL,
objectid ENTITYID NOT NULL,
created datetime NULL,
createdby integer NULL,
performedby varchar(200) NULL,
modifiedby integer NULL


)
GO


CREATE TABLE [onprc_ehr].[Temp_Clinical_Observations](
[rowid] [int] IDENTITY(100,1) NOT NULL,
Id varchar(200) NULL,
date smalldatetime NULL,
category varchar(500) NULL,
area varchar(500) NULL,
observation varchar(500) NULL,
createdby integer NULL,
performedby varchar(500) NULL,
taskid varchar(4000) NULL,
qcstate integer NULL,
modifiedby integer NULL

)
GO

CREATE TABLE [onprc_ehr].[Temp_Clinical_Observations_Master](
[rowid] [int] IDENTITY(100,1) NOT NULL,
searchid integer NULL,
Id varchar(200) NULL,
date smalldatetime NULL,
category varchar(500) NULL,
area varchar(500) NULL,
observation varchar(500) NULL,
createdby integer NULL,
performedby varchar(500) NULL,
taskid varchar(4000) NULL,
qcstate smallint NULL,
modifiedby smalldatetime NULL,
Posted_date smalldatetime

)
GO

CREATE TABLE [onprc_ehr].[Observation_EHRTasks](
[rowid] [int] IDENTITY(100,1) NOT NULL,
taskid varchar(4000) NULL,
description varchar(500)NULL,
qcstate smallint NULL,
formtype varchar(500) NULL,
category varchar(500) NULL,
assignedto smallint NULL,
createdby smallint NULL,
modifiedby smallint NULL


)
GO


EXEC core.fn_dropifexists 'p_Create_TB_Observationrecords', 'onprc_ehr', 'PROCEDURE', NULL;
GO


/*
**
** Created by
** R. Blasa 6-5-2024 A Program Process that reviews all TB Test entries on a given date, and creates a
** new TB Test Clinical Observation record based on
** having the same monkey id, date, and to be assigned to a Data Admin for reviews.
**
** R. Blasa Modified program so that each Clinical Observation entries generated by the program is assigned
** only a single task id when the program executes daily.
**
**
*/

CREATE Procedure onprc_ehr.p_Create_TB_Observationrecords



AS



DECLARE
@SearchKey Int,
@TempsearchKey Int,
@TaskId varchar(4000),
@AnimalID varchar(100),
@date datetime,
@createdby integer,
@performedby varchar(200),
@modifiedby integer,
@RunID varchar(4000)




BEGIN



---- Reset temp table

Truncate table onprc_ehr.TB_TestTemp


If @@Error <> 0
GoTo Err_Proc


--- Generate a list TB test monkeys )

Insert into onprc_ehr.TB_TestTemp

select
a.participantid,
a.date,
a.objectid,
a.created,
a.createdBy,
a.performedby,
a.modifiedby




from studydataset.c6d214_encounters a
Where a.participantid not in (select b.participantid from studydataset.c6d171_clinical_observations b
where a.participantid = b.participantid
And cast(b.date as date) = dateadd(day,3,cast(a.date as date))
And b.category = 'TB TST Score (72 hr)'
And a.modified >= cast(getdate() as date)
And a.type = 'Procedure' And a.qcstate = 18 And a.procedureid = 802 )

And a.type = 'Procedure' And a.qcstate = 18 And a.procedureid = 802 -----'TB Test Intradermal'
And a.modified >= cast(getdate() as date)
And a.participantid in ( select k.participantid from studydataset.c6d203_demographics k
where k.calculated_status = 'alive')

order by a.participantid, a.date desc


If @@Error <> 0
GoTo Err_Proc

---- When there are no records to process, exit immediately from the program.

If (Select count(*) from onprc_ehr.TB_TestTemp) = 0
BEGIN
GOTO No_Records
END


---- Reset temp variables

Set @SearchKey = 0
Set @TempSearchKey = 0
Set @Date = NULL
Set @modifiedby = NULL
Set @createdby =NULL
Set @performedby = NULL
Set @TaskID = NULL
Set @Animalid = Null
Set @RunID = Null



----- extract initial row id

Select Top 1 @Searchkey = rowid from onprc_ehr.TB_TestTemp
Order by rowid


Set @TaskID = NEWID() ----- Task Record Object ID

----Create a single task for each daily process


Insert into onprc_ehr.Observation_EHRTasks
(
taskid,
description,
title,
qcstate,
formType,
category,
assignedto,
createdby,
modifiedby

)

Values (

@TaskID,
'TB TST Scores ' + cast(@Date as varchar(50)) , ------ Title consist of animal id and Clinical procedure date
'TB TST Scores',
20, --- Qc State (In Progress)
'TB TST Scores', ------ FormType
'task', ----- category,
1822, ------- Assigned To Data Admins
1042, -------- Created By IS
1042 ----- Modified by IS

)

If @@Error <> 0
GoTo Err_Proc



While @TempSearchKey < @SearchKey
BEGIN

-----Begin entry Tb observation process

Select @Animalid =animalid, @date = date, @modifiedby=modifiedby, @createdby =createdby,@performedby= performedby from onprc_ehr.TB_TestTemp Where rowid = @Searchkey


----- Initialize data entries
Set @date = dateadd(day, 3,@date) ----- Add three days from TB Test date



--- Create a Clinical Observation Record

Insert into Temp_Clinical_Observations
(
Id,
date,
category,
area,
observation,
createdby,
performedby,
taskid,
qcstate,
modifiedby


)
values (
@animalid,
@date,
'TB TST Score (72 hr)',
'Right Eyelid',
'Grade: Negative',
@createdby,
@performedby,
@TaskID,
20 , ---- In Progress QCState
@modifiedby -----modified


)

If @@Error <> 0
GoTo Err_Proc



----- Proceed and fetch the next record

Set @TempSearchKey = @SearchKey

Select Top 1 @SearchKey = rowid from onprc_ehr.TB_TestTemp
Where rowid > @TempSearchKey
Order by rowid


END ---- While @TempSearchKey


----- Create a master copy of the completed transaction

Insert into onprc_ehr.Temp_Clinical_Observations_Master
Select *, getdate()
from onprc_ehr.Temp_Clinical_Observations

If @@Error <> 0
GoTo Err_Proc



No_Records:

RETURN 0


Err_Proc:
-------Error Generated, program processed stopped
RETURN 1


END

GO











2 changes: 1 addition & 1 deletion onprc_ehr/src/org/labkey/onprc_ehr/ONPRC_EHRModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public String getName()
@Override
public @Nullable Double getSchemaVersion()
{
return 25.005;
return 25.006;
}

@Override
Expand Down