Skip to content

Commit

Permalink
Add organization group sets to allow more disaggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
ccxzhang committed Jul 28, 2024
1 parent 8bba34d commit 3e8107a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/renderer/src/pages/MainPage/CategoryCombo.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { useEffect, useRef } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { fetchCategoryCombinations, setSelectedCategory } from '../../reducers/categoryReducer'
import {
fetchCategoryCombinations,
fetchOrgUnitGroupSets,
setSelectedCategory
} from '../../reducers/categoryReducer'
import { mouseClick, mouseToggle } from '../../reducers/mouseReducer'

const CategoryDropdownMenu = () => {
Expand All @@ -13,6 +17,7 @@ const CategoryDropdownMenu = () => {

useEffect(() => {
dispatch(fetchCategoryCombinations({ dhis2Url, username, password }))
dispatch(fetchOrgUnitGroupSets({ dhis2Url, username, password }))
}, [dhis2Url, username, password, dispatch])

const handleClickOutside = (event) => {
Expand Down
20 changes: 16 additions & 4 deletions src/renderer/src/reducers/categoryReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getCategoryCombination } from '../service/useApi'
import { getCategoryCombination, getOrganizationUnitGroupSets } from '../service/useApi'

export const fetchCategoryCombinations = createAsyncThunk(
'category/fetchCategoryCombinations',
Expand All @@ -9,6 +9,14 @@ export const fetchCategoryCombinations = createAsyncThunk(
}
)

export const fetchOrgUnitGroupSets = createAsyncThunk(
'category/fetchOrgUnitGroupSets',
async ({ dhis2Url, username, password }) => {
const response = await getOrganizationUnitGroupSets(dhis2Url, username, password)
return response.organisationUnitGroupSets
}
)

const categorySlice = createSlice({
name: 'category',
initialState: {
Expand All @@ -26,9 +34,13 @@ const categorySlice = createSlice({
}
},
extraReducers: (builder) => {
builder.addCase(fetchCategoryCombinations.fulfilled, (state, action) => {
state.category = action.payload
})
builder
.addCase(fetchCategoryCombinations.fulfilled, (state, action) => {
state.category = [...state.category, ...action.payload]
})
.addCase(fetchOrgUnitGroupSets.fulfilled, (state, action) => {
state.category = [...state.category, ...action.payload]
})
}
})

Expand Down
10 changes: 8 additions & 2 deletions src/renderer/src/reducers/statusReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ const statusSlice = createSlice({
state.errorMessage = action.payload
},
setNotification: (state, action) => {
state.notification = action.payload
state.notification = { ...state.notification, ...action.payload }
},
abortDownload: (state) => {
state.isLoading = false
state.notification.message = 'Download aborted'
state.notification.type = 'info'
},
handleExit: (state) => {
return initialState
}
}
})

export const { setLoading, setError, setNotification, handleExit } = statusSlice.actions
export const { setLoading, setError, setNotification, abortDownload, handleExit } =
statusSlice.actions
export default statusSlice.reducer
5 changes: 5 additions & 0 deletions src/renderer/src/service/useApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ export const getCategoryOptionCombos = (dhis2Url, username, password) => {
const catComboOptionUrl = `${dhis2Url}/api/categoryOptionCombos?fields=id,displayName&paging=false`
return fetchData(catComboOptionUrl, username, password)
}

export const getOrganizationUnitGroupSets = (dhis2Url, username, password) => {
const orgUnitGroupSetsUrl = `${dhis2Url}/api/organisationUnitGroupSets?fields=id,displayName&paging=false`
return fetchData(orgUnitGroupSetsUrl, username, password)
}
6 changes: 3 additions & 3 deletions src/renderer/src/utils/downloadUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export const generateDownloadingUrl = (dhis2Url, ou, dx, pe, co, format = 'csv')
'&displayProperty=NAME&ignoreLimit=TRUE&hierarchyMeta=true&hideEmptyRows=TRUE&showHierarchy=true&rows=ou;pe;dx'

if (co.length !== 0) {
let coString = co.join(';')
parameters += `&dimension=co:${coString}`
defaultFormat += `;co`
parameters += co.map((el) => `&dimension=${el}`).join('')
let rowString = co.join(';')
defaultFormat += `;${rowString}`
}

const url = `${dhis2Url}/${parameters}${defaultFormat}`
Expand Down

0 comments on commit 3e8107a

Please sign in to comment.