From 11e7532b03a8263d7d55f5ca9a5f79ff4dd90413 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Mon, 23 Sep 2024 15:08:13 -0700 Subject: [PATCH 1/4] Update assignment matching --- nirc_ehr/resources/queries/study/assignment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nirc_ehr/resources/queries/study/assignment.js b/nirc_ehr/resources/queries/study/assignment.js index 370ca47d..52a24d70 100644 --- a/nirc_ehr/resources/queries/study/assignment.js +++ b/nirc_ehr/resources/queries/study/assignment.js @@ -60,14 +60,14 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even } - var projectName = row.projectName.split(' ')[0]; + var projectName = row.projectName.split(' ' + row.Id)[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) { + if (pName == projectName) { projectId = projectData[projectNames[i]]; } } From 8af5ec9a9c1a696eee2a940630b5375e0fef3a03 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Mon, 23 Sep 2024 15:22:21 -0700 Subject: [PATCH 2/4] Put project name in description --- nirc_ehr/resources/queries/study/assignment.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nirc_ehr/resources/queries/study/assignment.js b/nirc_ehr/resources/queries/study/assignment.js index 52a24d70..cfa2bab5 100644 --- a/nirc_ehr/resources/queries/study/assignment.js +++ b/nirc_ehr/resources/queries/study/assignment.js @@ -76,7 +76,8 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even row.project = projectId; } else { - console.log("project can not be found - ", projectName); + row.description = projectName; + console.log("project can not be found: " + projectName + " for Id: " + row.Id); } prevAnimalId = row.Id; if (!(!row.endDate || row.endDate === 'undefined')) { From d4c988143e3d39bc5026b36b4383c5b64af6e47a Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Mon, 23 Sep 2024 20:23:16 -0700 Subject: [PATCH 3/4] Remove second check, now redundant --- nirc_ehr/resources/queries/study/assignment.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/nirc_ehr/resources/queries/study/assignment.js b/nirc_ehr/resources/queries/study/assignment.js index cfa2bab5..fbff697a 100644 --- a/nirc_ehr/resources/queries/study/assignment.js +++ b/nirc_ehr/resources/queries/study/assignment.js @@ -62,16 +62,7 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even var projectName = row.projectName.split(' ' + row.Id)[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 == projectName) { - projectId = projectData[projectNames[i]]; - } - } - } + if (projectId) { row.project = projectId; } From 6f7620f09c6b87c805ba6ea4dfac7b32c49baa8d Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Mon, 14 Oct 2024 15:38:01 -0700 Subject: [PATCH 4/4] Update project name parsing --- .../resources/queries/dbo/q_assignment.sql | 5 ++++- nirc_ehr/resources/queries/dbo/q_project.sql | 16 +++++++++------ .../resources/queries/study/assignment.js | 20 +++++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/nirc_ehr/resources/queries/dbo/q_assignment.sql b/nirc_ehr/resources/queries/dbo/q_assignment.sql index 44636c12..767b569f 100644 --- a/nirc_ehr/resources/queries/dbo/q_assignment.sql +++ b/nirc_ehr/resources/queries/dbo/q_assignment.sql @@ -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 diff --git a/nirc_ehr/resources/queries/dbo/q_project.sql b/nirc_ehr/resources/queries/dbo/q_project.sql index ad8f1022..02a79915 100644 --- a/nirc_ehr/resources/queries/dbo/q_project.sql +++ b/nirc_ehr/resources/queries/dbo/q_project.sql @@ -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 \ No newline at end of file diff --git a/nirc_ehr/resources/queries/study/assignment.js b/nirc_ehr/resources/queries/study/assignment.js index fbff697a..55dd710e 100644 --- a/nirc_ehr/resources/queries/study/assignment.js +++ b/nirc_ehr/resources/queries/study/assignment.js @@ -59,16 +59,20 @@ EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Even } } - - var projectName = row.projectName.split(' ' + row.Id)[0]; - var projectId = projectData[projectName]; - - if (projectId) { - row.project = projectId; + if (!row.projectName) { + console.log("project name is missing for Id: " + row.Id); } else { - row.description = projectName; - console.log("project can not be found: " + projectName + " for Id: " + row.Id); + 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')) {