diff --git a/snprc_ehr/resources/queries/study/PotentialSires.sql b/snprc_ehr/resources/queries/study/PotentialSires.sql index 6b6c2bc6c..07c43939c 100644 --- a/snprc_ehr/resources/queries/study/PotentialSires.sql +++ b/snprc_ehr/resources/queries/study/PotentialSires.sql @@ -4,7 +4,7 @@ PARAMETERS selectedOptionParm VARCHAR DEFAULT 'Birth' -- Birth or Acquisition ) -- TODO: Do we want to limit selection to animals that were co-located with dam? -SELECT d.id as Sire, +SELECT distinct d.id as Sire, d.species as Species, d.species.arc_species_code as ArcSpeciesCode, d.gender as Gender, @@ -39,7 +39,7 @@ FROM study.demographics AS d UNION ALL SELECT 185 as gestation, timestampadd('SQL_TSI_DAY', -185, birthdateParm ) as minConceptionDate, 'O' as species ) 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 - INNER JOIN study.acq_disp as ad on d.id = ad.id +INNER JOIN study.acq_disp as ad on d.id = ad.id WHERE d.gender = 'M' -- age at conception is greater or equal to minimum adult age -- LK has trouble matching parameters correctly using the code below, so minConceptionDate was added to the y result set diff --git a/snprc_ehr/src/client/NewAnimalPage/NewAnimalPage.jsx b/snprc_ehr/src/client/NewAnimalPage/NewAnimalPage.jsx index 13ec3c4d4..1a58c2f9c 100644 --- a/snprc_ehr/src/client/NewAnimalPage/NewAnimalPage.jsx +++ b/snprc_ehr/src/client/NewAnimalPage/NewAnimalPage.jsx @@ -107,8 +107,6 @@ loadListsForSpecies = selectedSpecies => { const lists = {} async function loadListsAW(species) { - // lists.potentialDamList = await fetchPotentialDams(species) - // lists.potentialSireList = await fetchPotentialSires(species) lists.locationList = await fetchLocations(species) lists.colonyList = await fetchColonies(species) lists.iacucList = await fetchProtocols(species) @@ -119,8 +117,6 @@ loadListsForSpecies = selectedSpecies => { .then(() => { this.setState(prevState => ({ ...prevState, - // potentialDamList: lists.potentialDamList, - // potentialSireList: lists.potentialSireList, locationList: lists.locationList, colonyList: lists.colonyList, iacucList: lists.iacucList, @@ -439,7 +435,6 @@ reloadDamsAndSires = (selectedSpecies, birthdate, selectedOption) => { lists.potentialDamList = await fetchPotentialDams(speciesValue, birthdateValue, selectedOptionValue) lists.potentialSireList = await fetchPotentialSires(speciesValue, birthdateValue, selectedOptionValue) } - loadListsAW(selectedSpecies.arcSpeciesCode, birthdate.date, selectedOption) .then(() => { this.setState(prevState => ({ @@ -508,6 +503,7 @@ render() { acquisitionTypeList={ this.state.acquisitionTypeList } + debug={ this.debug } disabled={ this.disableFirstPanel() } handleDataChange={ this.handleDataChange } handleNumAnimalChange={ this.handleNumAnimalChange } @@ -535,6 +531,7 @@ render() { > { this.props.handleDataChange('acquisitionType', option) } handleAcquisitionDateChange = date => { - this.props.handleDataChange('acqDate', { date: moment(date) }) + const acqDate = moment(date) + const dateStatus = isFutureDate(acqDate) || this.props.debug // debug is triggered by test suite + if (dateStatus) { + this.props.handleDataChange('acqDate', { date: acqDate }) + } + this.setState(() => ({ + errorMessage: dateStatus ? undefined : this.dateErrorMessageText + })) } handleSourceLocationChange = sourceLocation => { this.props.handleDataChange('sourceLocation', sourceLocation) @@ -102,6 +110,7 @@ render() { className="shared-dropdown" classNamePrefix="shared-select" id="location-select" + isClearable isDisabled={ this.props.disabled } isLoading={ this.props.sourceLocationList.length === 0 } onChange={ this.handleSourceLocationChange } diff --git a/snprc_ehr/src/client/NewAnimalPage/components/DemographicsPanel.jsx b/snprc_ehr/src/client/NewAnimalPage/components/DemographicsPanel.jsx index 86b47f358..8fe7600f9 100644 --- a/snprc_ehr/src/client/NewAnimalPage/components/DemographicsPanel.jsx +++ b/snprc_ehr/src/client/NewAnimalPage/components/DemographicsPanel.jsx @@ -37,12 +37,15 @@ handleGenderChange = option => { handleBirthDateChange = date => { const { selectedOption } = this.props const { species, acqDate } = this.props.newAnimalData - const birthdate = moment(date) - - this.props.handleDataChange('birthDate', { date: birthdate }) + const birthDate = moment(date) + const bdStatus = isBirthdateValid(birthDate, acqDate.date) || this.props.debug // debug is triggered by test suite + if (bdStatus) { + this.props.handleDataChange('birthDate', { date: birthDate }) + this.props.reloadDamsAndSires(species, { date: birthDate }, selectedOption) + } this.setState(() => ({ - errorMessage: isBirthdateValid(birthdate, acqDate.date) ? undefined : this.dateErrorMessageText - }), () => { this.props.reloadDamsAndSires(species, birthdate, selectedOption) }) + errorMessage: bdStatus ? undefined : this.dateErrorMessageText + })) } handleBirthDateSelect = () => { // do nothing diff --git a/snprc_ehr/src/client/NewAnimalPage/services/validation.js b/snprc_ehr/src/client/NewAnimalPage/services/validation.js index 1c62f543f..0a991224a 100644 --- a/snprc_ehr/src/client/NewAnimalPage/services/validation.js +++ b/snprc_ehr/src/client/NewAnimalPage/services/validation.js @@ -2,7 +2,13 @@ import moment from 'moment' export const isBirthdateValid = (birthdate, acqDate) => { return ( - moment(birthdate).isSameOrBefore(moment(acqDate)) + birthdate.isSameOrBefore(acqDate) + ) +} + +export const isFutureDate = date => { + return ( + date.isSameOrBefore(moment()) ) } diff --git a/snprc_ehr/src/client/NewAnimalPage/tests/__snapshots__/NewAnimalPage.test.jsx.snap b/snprc_ehr/src/client/NewAnimalPage/tests/__snapshots__/NewAnimalPage.test.jsx.snap index 864996d60..1657ec817 100644 --- a/snprc_ehr/src/client/NewAnimalPage/tests/__snapshots__/NewAnimalPage.test.jsx.snap +++ b/snprc_ehr/src/client/NewAnimalPage/tests/__snapshots__/NewAnimalPage.test.jsx.snap @@ -103,6 +103,7 @@ exports[`NewAnimalPage tests Should render Species/Acquisition page after lists >

Demographics @@ -416,7 +417,7 @@ exports[`NewAnimalPage tests Should render demographics page 1`] = `

-

Account, Colony, and Ownership @@ -811,7 +803,7 @@ exports[`Should render Account page 1`] = `

-

Diet @@ -1139,7 +1193,7 @@ exports[`Should render Diet page 1`] = `

-

Location @@ -1448,13 +1492,40 @@ exports[`Should render Location page 1`] = `

-