Skip to content

Commit ede2c47

Browse files
authored
Bug fixes for birthdate changes and acquisition date selection (#361)
* 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 * missed file in last commit * 1. don't allow future acquisition dates 2. fixed parameter passing bug in HandleBirthDateChange 3. code clean up 4. updated jest tests 5. updated snapshots
1 parent 15d612e commit ede2c47

7 files changed

Lines changed: 156 additions & 71 deletions

File tree

snprc_ehr/resources/queries/study/PotentialSires.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PARAMETERS
44
selectedOptionParm VARCHAR DEFAULT 'Birth' -- Birth or Acquisition
55
)
66
-- TODO: Do we want to limit selection to animals that were co-located with dam?
7-
SELECT d.id as Sire,
7+
SELECT distinct d.id as Sire,
88
d.species as Species,
99
d.species.arc_species_code as ArcSpeciesCode,
1010
d.gender as Gender,
@@ -39,7 +39,7 @@ FROM study.demographics AS d
3939
UNION ALL
4040
SELECT 185 as gestation, timestampadd('SQL_TSI_DAY', -185, birthdateParm ) as minConceptionDate, 'O' as species
4141
) 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
42-
INNER JOIN study.acq_disp as ad on d.id = ad.id
42+
INNER JOIN study.acq_disp as ad on d.id = ad.id
4343
WHERE d.gender = 'M'
4444
-- age at conception is greater or equal to minimum adult age
4545
-- LK has trouble matching parameters correctly using the code below, so minConceptionDate was added to the y result set

snprc_ehr/src/client/NewAnimalPage/NewAnimalPage.jsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ loadListsForSpecies = selectedSpecies => {
107107
const lists = {}
108108

109109
async function loadListsAW(species) {
110-
// lists.potentialDamList = await fetchPotentialDams(species)
111-
// lists.potentialSireList = await fetchPotentialSires(species)
112110
lists.locationList = await fetchLocations(species)
113111
lists.colonyList = await fetchColonies(species)
114112
lists.iacucList = await fetchProtocols(species)
@@ -119,8 +117,6 @@ loadListsForSpecies = selectedSpecies => {
119117
.then(() => {
120118
this.setState(prevState => ({
121119
...prevState,
122-
// potentialDamList: lists.potentialDamList,
123-
// potentialSireList: lists.potentialSireList,
124120
locationList: lists.locationList,
125121
colonyList: lists.colonyList,
126122
iacucList: lists.iacucList,
@@ -439,7 +435,6 @@ reloadDamsAndSires = (selectedSpecies, birthdate, selectedOption) => {
439435
lists.potentialDamList = await fetchPotentialDams(speciesValue, birthdateValue, selectedOptionValue)
440436
lists.potentialSireList = await fetchPotentialSires(speciesValue, birthdateValue, selectedOptionValue)
441437
}
442-
443438
loadListsAW(selectedSpecies.arcSpeciesCode, birthdate.date, selectedOption)
444439
.then(() => {
445440
this.setState(prevState => ({
@@ -508,6 +503,7 @@ render() {
508503
acquisitionTypeList={
509504
this.state.acquisitionTypeList
510505
}
506+
debug={ this.debug }
511507
disabled={ this.disableFirstPanel() }
512508
handleDataChange={ this.handleDataChange }
513509
handleNumAnimalChange={ this.handleNumAnimalChange }
@@ -535,6 +531,7 @@ render() {
535531
>
536532
<DemographicsPanel
537533
bdStatusList={ this.state.bdStatusList }
534+
debug={ this.debug }
538535
disabled={ this.disablePanels() }
539536
handleDataChange={ this.handleDataChange }
540537
newAnimalData={ this.state.newAnimalData }

snprc_ehr/src/client/NewAnimalPage/components/AcquisitionPanel.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import Select from 'react-select'
33
import moment from 'moment'
44
import WrappedDatePicker from '../../Shared/components/WrappedDatePicker'
55
import InfoPanel from '../../Shared/components/InfoPanel'
6-
import { validateNumAnimals } from '../services/validation'
6+
import { validateNumAnimals, isFutureDate } from '../services/validation'
77
import constants from '../constants/index'
88

99
export default class AcquisitionPanel extends React.Component {
10+
dateErrorMessageText = 'Future dates are not allowed.'
1011
state = {
1112
errorMessage: undefined,
1213
infoMessage: undefined
@@ -18,7 +19,14 @@ handleAcquisitionChange = option => {
1819
this.props.handleDataChange('acquisitionType', option)
1920
}
2021
handleAcquisitionDateChange = date => {
21-
this.props.handleDataChange('acqDate', { date: moment(date) })
22+
const acqDate = moment(date)
23+
const dateStatus = isFutureDate(acqDate) || this.props.debug // debug is triggered by test suite
24+
if (dateStatus) {
25+
this.props.handleDataChange('acqDate', { date: acqDate })
26+
}
27+
this.setState(() => ({
28+
errorMessage: dateStatus ? undefined : this.dateErrorMessageText
29+
}))
2230
}
2331
handleSourceLocationChange = sourceLocation => {
2432
this.props.handleDataChange('sourceLocation', sourceLocation)
@@ -102,6 +110,7 @@ render() {
102110
className="shared-dropdown"
103111
classNamePrefix="shared-select"
104112
id="location-select"
113+
isClearable
105114
isDisabled={ this.props.disabled }
106115
isLoading={ this.props.sourceLocationList.length === 0 }
107116
onChange={ this.handleSourceLocationChange }

snprc_ehr/src/client/NewAnimalPage/components/DemographicsPanel.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ handleGenderChange = option => {
3737
handleBirthDateChange = date => {
3838
const { selectedOption } = this.props
3939
const { species, acqDate } = this.props.newAnimalData
40-
const birthdate = moment(date)
41-
42-
this.props.handleDataChange('birthDate', { date: birthdate })
40+
const birthDate = moment(date)
41+
const bdStatus = isBirthdateValid(birthDate, acqDate.date) || this.props.debug // debug is triggered by test suite
42+
if (bdStatus) {
43+
this.props.handleDataChange('birthDate', { date: birthDate })
44+
this.props.reloadDamsAndSires(species, { date: birthDate }, selectedOption)
45+
}
4346
this.setState(() => ({
44-
errorMessage: isBirthdateValid(birthdate, acqDate.date) ? undefined : this.dateErrorMessageText
45-
}), () => { this.props.reloadDamsAndSires(species, birthdate, selectedOption) })
47+
errorMessage: bdStatus ? undefined : this.dateErrorMessageText
48+
}))
4649
}
4750
handleBirthDateSelect = () => {
4851
// do nothing

snprc_ehr/src/client/NewAnimalPage/services/validation.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import moment from 'moment'
22

33
export const isBirthdateValid = (birthdate, acqDate) => {
44
return (
5-
moment(birthdate).isSameOrBefore(moment(acqDate))
5+
birthdate.isSameOrBefore(acqDate)
6+
)
7+
}
8+
9+
export const isFutureDate = date => {
10+
return (
11+
date.isSameOrBefore(moment())
612
)
713
}
814

0 commit comments

Comments
 (0)