Skip to content
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
4 changes: 2 additions & 2 deletions snprc_ehr/resources/queries/study/PotentialSires.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions snprc_ehr/src/client/NewAnimalPage/NewAnimalPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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 => ({
Expand Down Expand Up @@ -508,6 +503,7 @@ render() {
acquisitionTypeList={
this.state.acquisitionTypeList
}
debug={ this.debug }
disabled={ this.disableFirstPanel() }
handleDataChange={ this.handleDataChange }
handleNumAnimalChange={ this.handleNumAnimalChange }
Expand Down Expand Up @@ -535,6 +531,7 @@ render() {
>
<DemographicsPanel
bdStatusList={ this.state.bdStatusList }
debug={ this.debug }
disabled={ this.disablePanels() }
handleDataChange={ this.handleDataChange }
newAnimalData={ this.state.newAnimalData }
Expand Down
13 changes: 11 additions & 2 deletions snprc_ehr/src/client/NewAnimalPage/components/AcquisitionPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import Select from 'react-select'
import moment from 'moment'
import WrappedDatePicker from '../../Shared/components/WrappedDatePicker'
import InfoPanel from '../../Shared/components/InfoPanel'
import { validateNumAnimals } from '../services/validation'
import { validateNumAnimals, isFutureDate } from '../services/validation'
import constants from '../constants/index'

export default class AcquisitionPanel extends React.Component {
dateErrorMessageText = 'Future dates are not allowed.'
state = {
errorMessage: undefined,
infoMessage: undefined
Expand All @@ -18,7 +19,14 @@ handleAcquisitionChange = option => {
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)
Expand Down Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion snprc_ehr/src/client/NewAnimalPage/services/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
}

Expand Down
Loading