Skip to content

Commit b1dcd93

Browse files
authored
Fb new animal wizard - user feedback updates (#349)
* Added EventsWidget HTML page * 1. Corrected adult age by gender in PotentialDams.sql 2. Closed AcqCodes that haven't been used in the past five years (in tsv file) 3. Added missing acquisition codes to tsv file 4. Filtered acq code 97 from fetchAcquisitionTypes API 5. Removed the join on the v_demographics view from arrivals and departures ETL source queries - if animal is removed from the colony before the ETL runs, then the deletion will be missed 6. Started refactoring retrieval of dams and sires to use a birthdate parameter * 1. Refactored PotentialDams.sql and PotentialSires.sql to use selectedOptionParm parameter to account for differences in how potential sires and dams are handled depending on whether a birth or other acquisition is being recorded 2. fetchLocations.js API updated to filter based on acquisiton codes for offsite acquisitions 3. fetchPotentialDams.js and fetchPotentialSires.js APIs updated to handle SQL parameters 4. Changes to AccountPanel.jsx to allow non-birth acquisitions to have null accounts 5. Changes to AcquisitionPanel.js to reload location codes when acquisition type changes 6. Changes made to DemographicsPanel.js to reload dams and sires after birth date is entered 7. Added new constant offSiteAcqCodes to track acquisition of animals not being added to the colony 8. Updated request API to handle parameters 9. UpdateAnimalData.js to allow null animal accounts 10. Updated ANPRC_EHRValidator.java to permit null accounts in certain conditions 11. Updated Jest tests * Updated Jest test and snapshots * 1. added source location to New Animal Wizard UI - AcquisitionPanel.jsx 2. changed how ehr_lookups.source is being populated - went from TSV file to ETL 3. added source query for source locations - labkey_etl.v_sourceLocations 4. added location description to lookup list 5. added sourceLocation to the updateAnimalData.js API 6. added sourceLocation to SummaryPanel.jsx - also tweaked hover text locations 7. added sourceLocation to default state - NewAnimalState.js 8. added sourceLocation jest tests, test data, mock API 9. updated snapshots 10. many lint fixes including files outside the scope of this feature branch * removed ehr_lookups.source from populateData page * 1. updates related to sourceLocation for updating newAnimalData table 2. added query meta data for sourceLocation
1 parent e5d18b6 commit b1dcd93

66 files changed

Lines changed: 1328 additions & 986 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

snprc_ehr/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"LABKEY": "readonly"
3434
},
3535
"rules": {
36+
"linebreak-style": ["error", "windows"],
3637
"arrow-body-style": 0,
3738
"arrow-parens": [
3839
"warn",
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
title value category description sort_order date_disabled
2-
0 Acquisition Unknown 0
3-
1 Birth Colony-born, Vaginal delivery (at TBRI) 1
4-
2 Birth Colony-born, Cesarean delivery (at TBRI) 2
5-
3 Birth Stillbirth/Abortion 3
6-
4 Acquisition Trapped by TBRI 4
7-
5 Acquisition Received by trade 5
8-
6 Birth Surgical Removal of dead fetus 6
9-
7 Acquisition New Purchase 7
10-
8 Acquisition Gift (from outside source) 8
11-
9 Acquisition Return of TBRI Loan 9
12-
10 Acquisition Outside Loan to TBRI 10
13-
11 Acquisition Re-Purchase 11
14-
12 Acquisition Admission to TBRI for treatment 12
15-
13 Acquisition Admission to TBRI for boarding 13
16-
14 Acquisition Purchase, wild-born, known provenance 14
17-
15 Acquisition Purchase, wild-born, unknown provenance 15
18-
16 Acquisition Purchase, colony-born, other colony 16
19-
17 Acquisition Gift, wild-born 17
20-
18 Acquisition Gift, colony-born 18
21-
19 Acquisition Loan, wild-born 19
22-
20 Acquisition Loan, colony-born 20
23-
21 Acquisition Returned to TBRI (inadequate model) 21
24-
22 Birth Colony-born, other colony, by Cesarean Section (dam resides or intending to be returned to SFBR) 22
25-
23 Birth Colony-born, other colony, by Vaginal delivery (dam resides or intending to be returned to SFBR) 23
26-
24 Acquisition Admit to TBRI for quarantine period (tether, surgery...prior to release) 24
27-
25 Acquisition NON TxBiomed data acquisition 25
28-
26 Acquisition Research related (return to TBRI) 26
29-
27 Acquisition Reacquired to complete medical history 27
30-
28 Birth euthanized in utero, colony management 28
31-
29 Acquisition UTHS - Animal returned from UT Health Sciences Center 29
32-
50 Acquisition Re-IDed (DBA addition, not physical addition to colony) 50
33-
97 Acquisition Parental data only, animal never at TBRI 97
2+
0 Acquisition Unknown 0 03-10-2021
3+
1 Birth Colony-born, Vaginal delivery (at TBRI) 1
4+
2 Birth Colony-born, Cesarean delivery (at TBRI) 2
5+
3 Birth Stillbirth/Abortion 3
6+
4 Acquisition Trapped by TBRI 4 03-10-2021
7+
5 Acquisition Received by trade 5
8+
6 Birth Surgical Removal of dead fetus 6
9+
7 Acquisition New Purchase 7
10+
8 Acquisition Gift (from outside source) 8
11+
9 Acquisition Return of TBRI Loan 9 03-10-2021
12+
10 Acquisition Outside Loan to TBRI 10 03-10-2021
13+
11 Acquisition Re-Purchase 11 03-10-2021
14+
12 Acquisition Admission to TBRI for treatment 12
15+
13 Acquisition Admission to TBRI for boarding 13 03-10-2021
16+
14 Acquisition Purchase, wild-born, known provenance 14 03-10-2021
17+
15 Acquisition Purchase, wild-born, unknown provenance 15 03-10-2021
18+
16 Acquisition Purchase, colony-born, other colony 16
19+
17 Acquisition Gift, wild-born 17 03-10-2021
20+
18 Acquisition Gift, colony-born 18
21+
19 Acquisition Loan, wild-born 19 03-10-2021
22+
20 Acquisition Loan, colony-born 20 03-10-2021
23+
21 Acquisition Returned to TBRI (inadequate model) 21 03-10-2021
24+
22 Birth Colony-born, other colony, by Cesarean Section (dam resides or intending to be returned to SFBR) 22
25+
23 Birth Colony-born, other colony, by Vaginal delivery (dam resides or intending to be returned to SFBR) 23
26+
24 Acquisition Admit to TBRI for quarantine period (tether, surgery...prior to release) 24 03-10-2021
27+
25 Acquisition NON TxBiomed data acquisition 25
28+
26 Acquisition Research related (return to TBRI) 26 03-10-2021
29+
27 Acquisition Reacquired to complete medical history 27 03-10-2021
30+
28 Birth euthanized in utero, colony management 28
31+
29 Acquisition UTHS - Animal returned from UT Health Sciences Center 29 03-10-2021
32+
30 Acquisition Admission to TBRI for research treatment 30
33+
50 Acquisition Re-IDed (DBA addition, not physical addition to colony) 50 03-10-2021
34+
97 Acquisition Parental data only, animal never at TBRI 97
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<etl xmlns="http://labkey.org/etl/xml">
3+
<name>Source Locations lookup</name>
4+
<description>Places from which an animal can be acquired</description>
5+
<transforms>
6+
<transform id="step1" type="org.labkey.di.pipeline.TransformTask">
7+
<description>Copy to target</description>
8+
<source schemaName="snprcSrc" queryName="v_sourceLocations" />
9+
<destination schemaName="ehr_lookups" queryName="source" bulkLoad="true" targetOption="truncate" />
10+
</transform>
11+
</transforms>
12+
<schedule>
13+
<cron expression="0 15 7 ? * *"/>
14+
</schedule>
15+
</etl>

snprc_ehr/resources/queries/ehr_lookups/AcquisitionTypesLookup.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ SELECT a.value as AcqCode,
22
a.category as Category,
33
rtrim(a.value) + ' - ' + a.description as DisplayValue,
44
a.sort_order as SortOrder
5-
from ehr_lookups.AcquisitionType as a
5+
from ehr_lookups.AcquisitionType as a
6+
where a.date_disabled is null
Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,56 @@
1-
1+
PARAMETERS
2+
(
3+
birthdateParm TIMESTAMP DEFAULT '01/01/1900',
4+
selectedOptionParm VARCHAR DEFAULT 'Birth' -- Birth or Acquisition
5+
)
26
-- TODO: Do we want to limit selection to animals that were co-located with dam?
37
SELECT d.id as Dam,
48
d.species as Species,
59
d.species.arc_species_code as ArcSpeciesCode,
610
d.gender as Gender,
711
d.birth as BirthDate,
8-
d.id.age.ageInYears as Age
12+
d.id.age.ageInYears as Age,
13+
ROUND(CAST(age_in_months(d.birth, y.minConceptionDate ) AS DOUBLE) / 12.0, 1) as AgeOnConceptionDate,
14+
x.minAdultAge as MinAdultAge,
15+
x.maxAdultAge as MaxAdultAge,
16+
x.ageClass
917

1018
FROM study.demographics AS d
1119
INNER JOIN (
12-
SELECT "min" AS minAdultAge, species, gender, label
13-
FROM ehr_lookups.ageclass AS ac1
14-
) as x ON d.species.arc_species_code = x.species and x.label = 'Adult' AND (x.gender = 'M' OR x.gender is NULL)
20+
SELECT "min" AS minAdultAge,
21+
coalesce("max", 10) AS maxAdultAge, -- some species may be missing maxAdultAge
22+
species,
23+
gender,
24+
label,
25+
ageClass
26+
FROM ehr_lookups.ageclass AS ac
27+
) as x ON d.species.arc_species_code = x.species and x.label = 'Adult' AND (x.gender = 'F' OR x.gender is NULL)
1528

1629
-- hard code until the gestation data is available in LK - use 185 if we don't have a value
1730
INNER JOIN (
18-
SELECT 173 as gestation, 'PC' as species
31+
SELECT 173 as gestation, timestampadd('SQL_TSI_DAY', -173, birthdateParm ) as minConceptionDate, 'PC' as species
1932
UNION ALL
20-
SELECT 143 as gestation, 'CJ' as species
33+
SELECT 143 as gestation, timestampadd('SQL_TSI_DAY', -143, birthdateParm ) as minConceptionDate, 'CJ' as species
2134
UNION ALL
22-
SELECT 160 as gestation, 'MM' as species
35+
SELECT 160 as gestation, timestampadd('SQL_TSI_DAY', -160, birthdateParm ) as minConceptionDate, 'MM' as species
2336
UNION ALL
24-
SELECT 155 as gestation, 'MF' as species
37+
SELECT 155 as gestation, timestampadd('SQL_TSI_DAY', -155, birthdateParm ) as minConceptionDate, 'MF' as species
2538
UNION ALL
26-
SELECT 223 as gestation, 'PT' as species
39+
SELECT 223 as gestation, timestampadd('SQL_TSI_DAY', -223, birthdateParm ) as minConceptionDate, 'PT' as species
2740
UNION ALL
28-
SELECT 22 as gestation, 'MA' as species
41+
SELECT 22 as gestation, timestampadd('SQL_TSI_DAY', -22, birthdateParm ) as minConceptionDate, 'MA' as species
2942
UNION ALL
30-
SELECT 185 as gestation, 'O' as species
43+
SELECT 185 as gestation, timestampadd('SQL_TSI_DAY', -185, birthdateParm ) as minConceptionDate, 'O' as species
3144
) AS y ON CASE WHEN d.species.arc_species_code IN ('PC', 'CJ', 'MM', 'MF', 'PT','MA') then d.species.arc_species_code ELSE 'O' END = y.species
32-
3345
INNER JOIN study.acq_disp as ad on d.id = ad.id
34-
3546
WHERE d.gender = 'F'
36-
-- age at conception is greater or equal to minimum adult age
37-
AND x.minAdultAge <= ROUND(CONVERT(age_in_months(d.birth, timestampadd('SQL_TSI_DAY', -y.gestation, curdate())), DOUBLE) / 12.0, 1)
38-
-- ensure animal was at txbiomed on date of conception
39-
AND timestampadd('SQL_TSI_DAY', -y.gestation, curdate()) BETWEEN ad.acq_date AND COALESCE(ad.disp_date, curdate())
40-
-- make sure animal was alive (at center) on conception date
41-
AND COALESCE(d.lastDayAtCenter, curdate()) > timestampadd('SQL_TSI_DAY', -y.gestation, curdate())
47+
-- age at conception is greater or equal to minimum adult age and less than or equal to maximum adult age
48+
-- LK has trouble matching parameters correctly using the code below, so minConceptionDate was added to the y result set
49+
--AND x.minAdultAge <= ROUND(CAST(age_in_months(d.birth, timestampadd('SQL_TSI_DAY', -y.gestation, coalesce(birthdateParm, curdate()) ) ) AS DOUBLE) / 12.0, 1)
50+
AND ROUND(CAST(age_in_months(d.birth, y.minConceptionDate ) AS DOUBLE) / 12.0, 1) between x.minAdultAge and x.maxAdultAge
51+
-- ensure animal was at txbiomed on date of conception for birth type acquisitions
52+
AND (timestampadd('SQL_TSI_DAY', -y.gestation, birthdateParm) BETWEEN ad.acq_date AND COALESCE(ad.disp_date, birthdateParm) OR selectedOptionParm = 'Acquisition')
53+
-- make sure animal was alive (at center) on conception date for birth type acquisitions
54+
AND (COALESCE(d.lastDayAtCenter, birthdateParm) >= timestampadd('SQL_TSI_DAY', -y.gestation, birthdateParm) OR selectedOptionParm = 'Acquisition')
55+
-- drop off animals that were not alive on the conception date
56+
AND d.id.age.ageInYears >= ROUND(CAST(age_in_months(d.birth, y.minConceptionDate ) AS DOUBLE) / 12.0, 1)
Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,53 @@
1-
1+
PARAMETERS
2+
(
3+
birthdateParm TIMESTAMP DEFAULT '01/01/1900',
4+
selectedOptionParm VARCHAR DEFAULT 'Birth' -- Birth or Acquisition
5+
)
26
-- TODO: Do we want to limit selection to animals that were co-located with dam?
37
SELECT d.id as Sire,
48
d.species as Species,
59
d.species.arc_species_code as ArcSpeciesCode,
6-
d.gender,
7-
d.birth,
8-
d.id.age.ageInYears as Age
10+
d.gender as Gender,
11+
d.birth as BirthDate,
12+
d.id.age.ageInYears as Age,
13+
ROUND(CAST(age_in_months(d.birth, y.minConceptionDate ) AS DOUBLE) / 12.0, 1) as AgeOnConceptionDate,
14+
x.minAdultAge as MinAdultAge
915

1016
FROM study.demographics AS d
1117
INNER JOIN (
12-
SELECT "min" AS minAdultAge, species, gender, label
13-
FROM ehr_lookups.ageclass AS ac1
18+
SELECT "min" AS minAdultAge,
19+
coalesce("max", 10) AS maxAdultAge, -- some species may be missing maxAdultAge
20+
species,
21+
gender,
22+
label
23+
FROM ehr_lookups.ageclass AS ac
1424
) as x ON d.species.arc_species_code = x.species and x.label = 'Adult' AND (x.gender = 'M' OR x.gender is NULL)
1525

1626
-- hard code until the gestation data is available in LK - use 185 if we don't have a value
1727
INNER JOIN (
18-
SELECT 173 as gestation, 'PC' as species
28+
SELECT 173 as gestation, timestampadd('SQL_TSI_DAY', -173, birthdateParm ) as minConceptionDate, 'PC' as species
1929
UNION ALL
20-
SELECT 143 as gestation, 'CJ' as species
30+
SELECT 143 as gestation, timestampadd('SQL_TSI_DAY', -143, birthdateParm ) as minConceptionDate, 'CJ' as species
2131
UNION ALL
22-
SELECT 160 as gestation, 'MM' as species
32+
SELECT 160 as gestation, timestampadd('SQL_TSI_DAY', -160, birthdateParm ) as minConceptionDate, 'MM' as species
2333
UNION ALL
24-
SELECT 155 as gestation, 'MF' as species
34+
SELECT 155 as gestation, timestampadd('SQL_TSI_DAY', -155, birthdateParm ) as minConceptionDate, 'MF' as species
2535
UNION ALL
26-
SELECT 223 as gestation, 'PT' as species
36+
SELECT 223 as gestation, timestampadd('SQL_TSI_DAY', -223, birthdateParm ) as minConceptionDate, 'PT' as species
2737
UNION ALL
28-
SELECT 22 as gestation, 'MA' as species
38+
SELECT 22 as gestation, timestampadd('SQL_TSI_DAY', -22, birthdateParm ) as minConceptionDate, 'MA' as species
2939
UNION ALL
30-
SELECT 185 as gestation, 'O' as species
31-
) AS y ON CASE WHEN d.species.arc_species_code IN ('PC', 'CJ', 'MM', 'MF', 'PT', 'MA') then d.species.arc_species_code ELSE 'O' END = y.species
32-
40+
SELECT 185 as gestation, timestampadd('SQL_TSI_DAY', -185, birthdateParm ) as minConceptionDate, 'O' as species
41+
) AS y ON CASE WHEN d.species.arc_species_code IN ('PC', 'CJ', 'MM', 'MF', 'PT','MA') then d.species.arc_species_code ELSE 'O' END = y.species
3342
INNER JOIN study.acq_disp as ad on d.id = ad.id
34-
3543
WHERE d.gender = 'M'
3644
-- age at conception is greater or equal to minimum adult age
37-
AND x.minAdultAge <= ROUND(CONVERT(age_in_months(d.birth, timestampadd('SQL_TSI_DAY', -y.gestation, curdate())), DOUBLE) / 12.0, 1)
38-
-- ensure animal was at txbiomed on date of conception
39-
AND timestampadd('SQL_TSI_DAY', -y.gestation, curdate()) BETWEEN ad.acq_date AND COALESCE(ad.disp_date, curdate())
40-
-- make sure animal was alive (at center) on conception date
41-
AND COALESCE(d.lastDayAtCenter, curdate()) > timestampadd('SQL_TSI_DAY', -y.gestation, curdate())
45+
-- LK has trouble matching parameters correctly using the code below, so minConceptionDate was added to the y result set
46+
--AND x.minAdultAge <= ROUND(CAST(age_in_months(d.birth, timestampadd('SQL_TSI_DAY', -y.gestation, coalesce(birthdateParm, curdate()) ) ) AS DOUBLE) / 12.0, 1)
47+
AND ROUND(CAST(age_in_months(d.birth, y.minConceptionDate ) AS DOUBLE) / 12.0, 1) between x.minAdultAge and x.maxAdultAge
48+
-- ensure animal was at txbiomed on date of conception for birth type acquisitions
49+
AND (timestampadd('SQL_TSI_DAY', -y.gestation, birthdateParm) BETWEEN ad.acq_date AND COALESCE(ad.disp_date, birthdateParm) OR selectedOptionParm = 'Acquisition')
50+
-- make sure animal was alive (at center) on conception date for birth type acquisitions
51+
AND (COALESCE(d.lastDayAtCenter, birthdateParm) >= timestampadd('SQL_TSI_DAY', -y.gestation, birthdateParm) OR selectedOptionParm = 'Acquisition')
52+
-- drop off animals that were not alive on the conception date
53+
AND d.id.age.ageInYears >= ROUND(CAST(age_in_months(d.birth, y.minConceptionDate ) AS DOUBLE) / 12.0, 1)

snprc_ehr/resources/source_queries/create_v_delete_arrival.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ ALTER VIEW [labkey_etl].[V_DELETE_ARRIVAL] AS
3333
-- Create date: 4/3/2015
3434
-- Description: Selects the ETL records for LabKey study.arrival dataset which need to be deleted
3535
-- Changes:
36-
--
36+
-- 3/10/2021 Removed the join on the v_demographics view - if animal is removed from the colony
37+
-- before the arrivals ETL runs, then the arrivals deletion will be missed
3738
--
3839
-- ==========================================================================================
3940

40-
SELECT
41+
SELECT
4142
ad.object_id,
4243
ad.audit_date_tm
4344
FROM audit.audit_acq_disp AS ad
44-
-- select primates only from the TxBiomed colony
45-
INNER JOIN Labkey_etl.V_DEMOGRAPHICS AS d ON d.id = ad.id
45+
4646
WHERE ad.audit_action = 'D' AND ad.object_id IS NOT NULL
4747

4848
GO
4949

50-
GRANT SELECT ON Labkey_etl.v_delete_arrival TO z_labkey
50+
GRANT SELECT ON Labkey_etl.v_delete_arrival TO z_labkey
5151
GRANT SELECT ON audit.audit_acq_disp TO z_labkey
5252

5353
GO

snprc_ehr/resources/source_queries/create_v_delete_departure.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ ALTER VIEW [labkey_etl].[V_DELETE_DEPARTURE] AS
3333
-- Create date: 6/26/2015
3434
-- Description: Selects the ETL records for LabKey study.departure dataset for deletes
3535
-- Changes:
36-
--
36+
-- 3/10/2021 Removed the join on the v_demographics view - if animal is removed from the colony
37+
-- before the departures ETL runs, then the departure deletion will be missed
3738
--
3839
-- ==========================================================================================
3940

4041
SELECT ad.object_id,
4142
ad.audit_date_tm
4243
FROM audit.audit_acq_disp AS ad
43-
-- select primates only from the TxBiomed colony
44-
INNER JOIN Labkey_etl.V_DEMOGRAPHICS AS d ON d.id = ad.id
44+
4545
WHERE ad.audit_action = 'D' AND ad.object_id IS NOT NULL
4646

4747
GO
4848

49-
GRANT SELECT ON Labkey_etl.v_delete_departure TO z_labkey
49+
GRANT SELECT ON Labkey_etl.v_delete_departure TO z_labkey
5050
GRANT SELECT ON audit.audit_acq_disp TO z_labkey
5151
GO
5252

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ALTER VIEW [labkey_etl].[v_sourceLocations]
2+
AS
3+
-- ==========================================================================================
4+
-- Author: Terry Hawkins
5+
-- Create date: 4/1/2021
6+
-- Description: returns a list of places from which an animal can be acquired.
7+
-- NOTE: these are regular location codes
8+
-- Changes:
9+
--
10+
-- ==========================================================================================
11+
12+
SELECT vl.location AS code,
13+
LTRIM(RTRIM([dbo].[f_split](vl.description, ',', 1))) AS meaning,
14+
LTRIM(RTRIM([dbo].[f_split](vl.description, ',', 2))) AS SourceCity,
15+
LTRIM(RTRIM([dbo].[f_split]([dbo].[f_split](vl.description, ',', 3),'(', 1))) AS SourceState,
16+
s.country AS SourceCountry,
17+
LTRIM(RTRIM([dbo].[f_split]([dbo].[f_split](vl.description, '(', 2), ')', 1))) AS description
18+
FROM dbo.valid_locations AS vl
19+
LEFT OUTER JOIN dbo.CountryCodeLookup AS s ON s.code = LTRIM(RTRIM([dbo].[f_split]([dbo].[f_split](vl.description, ',', 3),'(', 1)))
20+
WHERE vl.location >= 800 AND vl.description NOT LIKE '%mono birth%'
21+
GO
22+
23+
GRANT SELECT ON labkey_etl.v_sourceLocations TO z_labkey;
24+
GO

0 commit comments

Comments
 (0)