-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
231 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import moment from 'moment'; | ||
import { CACHING, PAGES } from '../../../constants'; | ||
import * as actionTypes from '../../types'; | ||
import { getAll } from '../../../views/Shared/Api'; | ||
|
||
export const loadAlhivOnArtByAgeSex = () => async (dispatch, getState) => { | ||
const diffInMinutes = moment().diff( | ||
moment(getState().otzAlhivOnArtByAgeSex.lastFetch), | ||
'minutes' | ||
); | ||
if (getState().ui.ctTab !== 'otz' && | ||
getState().ui.currentPage !== PAGES.ct) { | ||
return; | ||
} | ||
else if ((diffInMinutes < CACHING.LONG) && getState().filters.filtered === false) { | ||
return; | ||
} else { | ||
await dispatch(fetchAlhivOnArtByAgeSex()); | ||
} | ||
} | ||
|
||
export const fetchAlhivOnArtByAgeSex = () => async (dispatch, getState) => { | ||
dispatch({ type: actionTypes.CT_OTZ_ALHIV_ON_ART_BY_AGE_SEX_REQUEST }); | ||
const params = { | ||
county: getState().filters.counties, | ||
subCounty: getState().filters.subCounties, | ||
facility: getState().filters.facilities, | ||
partner: getState().filters.partners, | ||
agency: getState().filters.agencies, | ||
project: getState().filters.projects, | ||
gender: getState().filters.genders, | ||
datimAgeGroup: getState().filters.datimAgeGroups, | ||
}; | ||
const response = await getAll('care-treatment/getAlhivOnArtByAgeSex', params); | ||
dispatch({ type: actionTypes.CT_OTZ_ALHIV_ON_ART_BY_AGE_SEX_FETCH, payload: { filtered: getState().filters.filtered, list: response }}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as actionTypes from "../../../actions/types"; | ||
|
||
const initialState = { | ||
lastFetch: null, | ||
loading: false, | ||
listUnfiltered: [], | ||
listFiltered: [], | ||
}; | ||
|
||
export default (state = initialState, action) => { | ||
let newState = { ...state }; | ||
switch (action.type) { | ||
case actionTypes.CT_OTZ_ALHIV_ON_ART_BY_AGE_SEX_REQUEST: | ||
newState.loading = true; | ||
return newState; | ||
case actionTypes.CT_OTZ_ALHIV_ON_ART_BY_AGE_SEX_FETCH: | ||
if (action.payload.filtered === true) { | ||
newState.listFiltered = action.payload.list; | ||
} else { | ||
newState.listUnfiltered = action.payload.list; | ||
newState.lastFetch = Date.now(); | ||
} | ||
newState.loading = false; | ||
return newState; | ||
case actionTypes.CT_OTZ_ALHIV_ON_ART_BY_AGE_SEX_FAILED: | ||
newState.loading = false; | ||
return newState; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export let childrenAgeGroups = [' Under 1', '01 to 04','05 to 09','10 to 14']; | ||
export let adultAgeGroups = ['15 to 19','20 to 24','25 to 29','30 to 34','35 to 39','40 to 44','45 to 49','50 to 54','55 to 59','60 to 64','65+']; | ||
export let ovcAgeGroups = [' Under 1', '01 to 04','05 to 09','10 to 14', '15 to 19']; | ||
export let otzAgeGroups = ['10 to 14', '15 to 19']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createSelector } from 'reselect'; | ||
import * as ageGroups from '../../AgeGroupsArray'; | ||
import _ from 'lodash'; | ||
|
||
const filtered = state => state.filters.filtered; | ||
const listFiltered = state => state.otzAlhivOnArtByAgeSex.listFiltered; | ||
const listUnfiltered = state => state.otzAlhivOnArtByAgeSex.listUnfiltered; | ||
|
||
export const getOtzAlhivOnArtByAgeSex = createSelector( | ||
[listUnfiltered, listFiltered, filtered], | ||
(listUnfiltered, listFiltered, filtered) => { | ||
const list = filtered ? listFiltered : listUnfiltered; | ||
let otzAgeGroups = ageGroups.otzAgeGroups; | ||
|
||
let distributionMale = []; | ||
let distributionFemale = []; | ||
|
||
for (const ageGroup of otzAgeGroups) { | ||
const ageGroupMaleFilter = list?.filter(obj => obj.AgeGroup === ageGroup && (obj.Gender.toLowerCase() === "M".toLowerCase() || obj.Gender.toLowerCase() === "Male".toLowerCase())); | ||
const ageGroupFemaleFilter = list.filter(obj => obj.AgeGroup === ageGroup && (obj.Gender.toLowerCase() === "F".toLowerCase() || obj.Gender.toLowerCase() === "Female".toLowerCase())); | ||
if (ageGroupMaleFilter.length > 0) { | ||
distributionMale.push(ageGroupMaleFilter[0].CALHIVonART); | ||
} else { | ||
distributionMale.push(0); | ||
} | ||
|
||
if (ageGroupFemaleFilter.length > 0) { | ||
distributionFemale.push(ageGroupFemaleFilter[0].CALHIVonART); | ||
} else { | ||
distributionFemale.push(0); | ||
} | ||
} | ||
|
||
let max = _.max([_.max(distributionMale), _.max(distributionFemale)]); | ||
distributionMale = distributionMale.map(x => x * -1); | ||
|
||
return { max, otzAgeGroups, distributionMale, distributionFemale }; | ||
// return filtered ? listFiltered : listUnfiltered; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Card, CardBody, CardHeader } from 'reactstrap'; | ||
import HighchartsReact from 'highcharts-react-official'; | ||
import Highcharts from 'highcharts'; | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import * as otzDistributionOfCALHIVByAgeSexSelector from '../../../selectors/CT/OTZ/otzAlhivOnArtByAgeSex'; | ||
|
||
const OTZDistributionOfCALHIVByAgeSex = () => { | ||
const [ovcDistributionOfALHIVByAgeSex, setOvcDistributionOfALHIVByAgeSex] = useState({}); | ||
const distributionOfALHIVByAgeSex = useSelector(otzDistributionOfCALHIVByAgeSexSelector.getOtzAlhivOnArtByAgeSex); | ||
|
||
const loadOvcDistributionOfALHIVByAgeSex = useCallback(async () => { | ||
setOvcDistributionOfALHIVByAgeSex({ | ||
chart: { type: 'bar' }, | ||
title: { text: '' }, | ||
xAxis: [ | ||
{ | ||
categories: [ | ||
'15 to 19', | ||
'10 to 14', | ||
], | ||
title: { text: '' }, | ||
reversed: false, | ||
}, | ||
{ | ||
categories: [ | ||
'15 to 19', | ||
'10 to 14', | ||
], | ||
title: { text: '' }, | ||
reversed: false, | ||
linkedTo: 0, | ||
opposite: true, | ||
}, | ||
], | ||
yAxis: [ | ||
{ | ||
min: -distributionOfALHIVByAgeSex.max, | ||
max: distributionOfALHIVByAgeSex.max, | ||
title: { text: 'Number Of Patients' }, | ||
labels: { | ||
formatter: function () { | ||
return Math.abs(this.value); | ||
}, | ||
}, | ||
}, | ||
], | ||
plotOptions: { | ||
series: { stacking: 'normal' }, | ||
}, | ||
tooltip: { | ||
formatter: function () { | ||
return ( | ||
'<b>' + | ||
this.series.name + | ||
', Age Group ' + | ||
this.point.category + | ||
'</b><br/>' + | ||
'Number Of Patients: ' + | ||
Highcharts.numberFormat(Math.abs(this.point.y), 1) | ||
); | ||
}, | ||
}, | ||
legend: { align: 'left', verticalAlign: 'top', y: 0, x: 80 }, | ||
series: [ | ||
{ | ||
name: 'Female', | ||
data: distributionOfALHIVByAgeSex.distributionFemale.reverse(), | ||
color: '#EA4C8B', | ||
}, | ||
{ | ||
name: 'Male', | ||
data: distributionOfALHIVByAgeSex.distributionMale.reverse(), | ||
color: '#14084D', | ||
}, | ||
], | ||
}); | ||
}, [distributionOfALHIVByAgeSex]); | ||
|
||
useEffect(() => { | ||
loadOvcDistributionOfALHIVByAgeSex(); | ||
}, [loadOvcDistributionOfALHIVByAgeSex]); | ||
|
||
return ( | ||
<Card className="trends-card"> | ||
<CardHeader className="trends-header" style={{textTransform: 'none'}}> | ||
DISTRIBUTION OF ALHIV PATIENTS BY AGE AND SEX | ||
</CardHeader> | ||
<CardBody className="trends-body"> | ||
<div className="col-12"> | ||
<HighchartsReact highcharts={Highcharts} options={ovcDistributionOfALHIVByAgeSex} /> | ||
</div> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default OTZDistributionOfCALHIVByAgeSex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.