Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project assignment ETL trigger #396

Merged
merged 5 commits into from
Oct 15, 2024
Merged
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
5 changes: 4 additions & 1 deletion nirc_ehr/resources/queries/dbo/q_assignment.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
SELECT alt.ALTERNATE_ID AS "objectId",
anm.ANIMAL_ID,
anm.ANIMAL_ID_NUMBER AS "Id",
alt.NAME AS "projectName",
CASE WHEN (SUBSTRING(trim(alt.NAME),3,1) = '-' OR SUBSTRING(trim(alt.NAME),5,1) = '-')
THEN trim(SUBSTRING(trim(alt.NAME),0,11))
ELSE trim(SUBSTRING(trim(alt.NAME), 0, 8))
END as "projectName",
alt.NAME AS "description",
ae.EVENT_DATETIME AS assignmentDate, -- Set to arrival/birth then updated by trigger
CASE WHEN alt.DESCRIPTION IS NULL OR length(trim(alt.DESCRIPTION)) != 11 THEN NULL
Expand Down
16 changes: 10 additions & 6 deletions nirc_ehr/resources/queries/dbo/q_project.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
SELECT min(alt.ALTERNATE_ID) as project,
alt.project as name
FROM
(
SELECT trim(substring(NAME, 0, locate(' ', NAME,8))) as project,
ALTERNATE_ID
FROM ALTERNATE
WHERE ALTERNATE_TYPE_ID = 6
) alt
(
SELECT
CASE WHEN (SUBSTRING(trim(NAME),3,1) = '-' OR SUBSTRING(trim(NAME),5,1) = '-')
THEN trim(SUBSTRING(trim(NAME),0,11))
ELSE trim(SUBSTRING(trim(NAME), 0, 8))
END as project,
ALTERNATE_ID
FROM ALTERNATE
WHERE ALTERNATE_TYPE_ID = 6
) alt
GROUP BY alt.project
28 changes: 12 additions & 16 deletions nirc_ehr/resources/queries/study/assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,20 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even
}
}


var projectName = row.projectName.split(' ')[0];
var projectId = projectData[projectName];
if (!projectId) {
var projectNames = Object.keys(projectData);
for (var i = 0; i < projectNames.length; i++) {

var pName = projectNames[i];
if (pName.toString().indexOf(projectName) === 0) {
projectId = projectData[projectNames[i]];
}
}
}
if (projectId) {
row.project = projectId;
if (!row.projectName) {
console.log("project name is missing for Id: " + row.Id);
}
else {
console.log("project can not be found - ", projectName);
var projectName = row.projectName.split(' ' + row.Id)[0];
var projectId = projectData[projectName];

if (projectId) {
row.project = projectId;
}
else {
row.description = projectName;
console.log("project cannot be found: " + projectName + " for Id: " + row.Id);
}
}
prevAnimalId = row.Id;
if (!(!row.endDate || row.endDate === 'undefined')) {
Expand Down