Skip to content

Commit

Permalink
Merge branch 'main' into POLIO-1807-Adapt-calendar-xlsx-with-nOPV2-bO…
Browse files Browse the repository at this point in the history
…PV-colors
  • Loading branch information
hakifran committed Dec 20, 2024
2 parents 68a2ac9 + 91c977e commit d46101a
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 59 deletions.
4 changes: 2 additions & 2 deletions hat/assets/js/apps/Iaso/domains/app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@
"iaso.snackBar.copyVersionSuccessMessage": "The task has been created",
"iaso.snackBar.createDataSourceError": "Error occurred while saving the data source.",
"iaso.snackBar.createExportRequestError": "An error occured while creating export request",
"iaso.snackBar.createExportRequestErrorNoFormMappingError": "The form doesn't a form mapping to export to dhis2",
"iaso.snackBar.createExportRequestErrorNoFormMappingError": "The form is not configured for DHIS2 export",
"iaso.snackBar.createExportRequestErrorNothingToExportError": "We found nothing to export, change your filter or force the re-export",
"iaso.snackBar.createExportRequestErrorNotSupportedError": "Forcing export isn't supported for event tracker",
"iaso.snackBar.createExportRequestErrorNoVersionError": "One of the instance had no version specified",
Expand Down Expand Up @@ -1577,4 +1577,4 @@
"trypelim.permissions.zones": "Zones",
"trypelim.permissions.zones_edit": "Edit zones",
"trypelim.permissions.zones_shapes_edit": "Edit zone shapes"
}
}
4 changes: 2 additions & 2 deletions hat/assets/js/apps/Iaso/domains/app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@
"iaso.snackBar.copyVersionSuccessMessage": "La tâche a été créé avec succès",
"iaso.snackBar.createDataSourceError": "Une erreur est survenue en sauvant la source de donnée",
"iaso.snackBar.createExportRequestError": "Une erreur est survenue en créant une demande d'export",
"iaso.snackBar.createExportRequestErrorNoFormMappingError": "Le formulaire n'est pas encore configuré pour l'export vers dhis2",
"iaso.snackBar.createExportRequestErrorNoFormMappingError": "Le formulaire n'est pas encore configuré pour l'export vers DHIS2",
"iaso.snackBar.createExportRequestErrorNothingToExportError": "Nous n'avons trouvé aucune soumission à exporter, vous pouvez modifier vos critères ou forcer le re-export",
"iaso.snackBar.createExportRequestErrorNotSupportedError": "L'exportation forcée n'est pas prise en charge pour le suivi des événements",
"iaso.snackBar.createExportRequestErrorNoVersionError": "L'export ne peut être créé, une des soumission ne spécifie pas la version du form",
Expand Down Expand Up @@ -1576,4 +1576,4 @@
"trypelim.permissions.zones": "Zones",
"trypelim.permissions.zones_edit": "Edit zones",
"trypelim.permissions.zones_shapes_edit": "Editer les contours géographiques des zones de santé"
}
}
5 changes: 4 additions & 1 deletion hat/assets/js/apps/Iaso/utils/usersUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LangOptions } from 'bluesquare-components';
import { LangOptions, textPlaceholder } from 'bluesquare-components';
import { useQueryClient } from 'react-query';
import { OrgUnitStatus } from '../domains/orgUnits/types/orgUnit';
import { Project } from '../domains/projects/types/project';
Expand Down Expand Up @@ -89,6 +89,9 @@ export type User = {
export const getDisplayName = (
user: Partial<User> | Partial<Profile>,
): string => {
if(!user){
return textPlaceholder
}
// Some endpoint have user_name and some username (without the _, fun)
const userName = user.user_name ?? user?.username;
if (!user.first_name && !user.last_name) {
Expand Down
19 changes: 11 additions & 8 deletions plugins/polio/api/campaigns/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ class CampaignSerializer(serializers.ModelSerializer):
account: Field = serializers.PrimaryKeyRelatedField(default=CurrentAccountDefault(), read_only=True)
has_data_in_budget_tool = serializers.SerializerMethodField(read_only=True)
campaign_types = serializers.PrimaryKeyRelatedField(many=True, queryset=CampaignType.objects.all(), required=False)
# Vaccines with real scope
vaccines = serializers.SerializerMethodField(read_only=True)
single_vaccines = serializers.SerializerMethodField(read_only=True)

def get_vaccines(self, obj):
if obj.vaccines:
return ",".join([vaccine.strip() for vaccine in obj.vaccines.split(",")])
return ""

def get_single_vaccines(self, obj):
return obj.vaccines_extended

def get_top_level_org_unit_name(self, campaign):
if campaign.country:
Expand Down Expand Up @@ -410,14 +421,6 @@ def update(self, instance: Campaign, validated_data):
log_campaign_modification(campaign, old_campaign_dump, self.context["request"].user)
return campaign

# Vaccines with real scope
vaccines = serializers.SerializerMethodField(read_only=True)

def get_vaccines(self, obj):
if obj.vaccines:
return ",".join([vaccine.strip() for vaccine in obj.vaccines.split(",")])
return ""

class Meta:
model = Campaign
# TODO in the future specify the fields that need to be returned so we can remove the deprecated fields
Expand Down
4 changes: 4 additions & 0 deletions plugins/polio/api/rounds/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Meta:

# Vaccines from real scopes, from property, separated by ,
vaccine_names = serializers.CharField(read_only=True)
vaccine_names_extended = serializers.SerializerMethodField(read_only=True)

def get_vaccine_names_extended(self, obj):
return obj.vaccine_names_extended

@atomic
def create(self, validated_data):
Expand Down
6 changes: 3 additions & 3 deletions plugins/polio/api/vaccines/repository_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from rest_framework.filters import OrderingFilter, SearchFilter
from rest_framework.mixins import ListModelMixin
from rest_framework.viewsets import GenericViewSet

from django.db.models import Q
from iaso.api.common import Paginator
from plugins.polio.models import VaccineStock, DestructionReport, IncidentReport
from plugins.polio.models import VaccineStock


class VaccineReportingFilterBackend(filters.BaseFilterBackend):
Expand Down Expand Up @@ -118,7 +118,7 @@ def get_queryset(self):
if self.request.user and self.request.user.is_authenticated:
base_qs = base_qs.filter(account=self.request.user.iaso_profile.account)

return base_qs
return base_qs.filter(Q(destructionreport__isnull=False) | Q(incidentreport__isnull=False))

@swagger_auto_schema(
manual_parameters=[
Expand Down
2 changes: 2 additions & 0 deletions plugins/polio/js/src/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export type RoundDateHistoryEntry = {

export type Round = {
id: number;
vaccine_names_extended:string;
started_at: Nullable<string>;
ended_at: Nullable<string>;
mop_up_started_at: Nullable<string>; // date
Expand Down Expand Up @@ -308,6 +309,7 @@ export type Campaign = {
created_at: string;
updated_at: string;
deleted_at: Nullable<string>;
single_vaccines?: string;
rounds: Round[];
org_unit: {
id: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import MESSAGES from '../../../../constants/messages';
import { useGetCountries } from '../../../../hooks/useGetCountries';

import { appId } from '../../../../constants/app';
import { defaultVaccineOptions } from '../../SupplyChain/constants';
import { singleVaccinesList } from '../../SupplyChain/constants';
import { useGetFileTypes } from '../hooks/useGetFileTypes';
import { VaccineRepositoryParams } from '../types';

Expand Down Expand Up @@ -101,7 +101,7 @@ export const Filters: FunctionComponent<Props> = ({ params, redirectUrl }) => {
}}
value={vaccineName}
type="select"
options={defaultVaccineOptions}
options={singleVaccinesList}
label={MESSAGES.vaccine}
/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import MESSAGES from '../../../../constants/messages';
import { useGetCountries } from '../../../../hooks/useGetCountries';

import { appId } from '../../../../constants/app';
import { defaultVaccineOptions } from '../../SupplyChain/constants';
import { singleVaccinesList } from '../../SupplyChain/constants';
import { useGetReportFileTypes } from '../hooks/useGetFileTypes';
import { VaccineRepositoryParams } from '../types';

Expand All @@ -30,7 +30,9 @@ export const Filters: FunctionComponent<Props> = ({ params, redirectUrl }) => {

const [filtersUpdated, setFiltersUpdated] = useState(false);
const [countries, setCountries] = useState(params.reportCountries);
const [fileType, setFileType] = useState(params.reportFileType || 'INCIDENT,DESTRUCTION');
const [fileType, setFileType] = useState(
params.reportFileType || 'INCIDENT,DESTRUCTION',
);
const [vaccineName, setVaccineName] = useState(params.reportVaccineName);
const [countryBlocks, setCountryBlocks] = useState(
params.reportCountryBlock,
Expand Down Expand Up @@ -133,7 +135,7 @@ export const Filters: FunctionComponent<Props> = ({ params, redirectUrl }) => {
}}
value={vaccineName}
type="select"
options={defaultVaccineOptions}
options={singleVaccinesList}
label={MESSAGES.vaccine}
/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { useMemo } from 'react';
import { DocumentsCells } from '../../components/DocumentsCell';
import MESSAGES from '../../messages';

export const useVaccineRepositoryReportsColumns = (): Column[] => {
export const useVaccineRepositoryReportsColumns = (
params: Record<string, any>,
): Column[] => {
const { formatMessage } = useSafeIntl();
return useMemo(
() => [
const { reportFileType } = params;
return useMemo(() => {
const columns: Column[] = [
{
Header: formatMessage(MESSAGES.country),
id: 'country__name',
Expand All @@ -19,19 +22,24 @@ export const useVaccineRepositoryReportsColumns = (): Column[] => {
accessor: 'vaccine',
width: 20,
},
{
];

if (reportFileType !== 'DESTRUCTION') {
columns.push({
Header: formatMessage(MESSAGES.incidentReports),
accessor: 'incident_report_data',
Cell: DocumentsCells,
sortable: false,
},
{
});
}
if (reportFileType !== 'INCIDENT') {
columns.push({
Header: formatMessage(MESSAGES.destructionReports),
accessor: 'destruction_report_data',
Cell: DocumentsCells,
sortable: false,
},
],
[formatMessage],
);
});
}
return columns;
}, [reportFileType, formatMessage]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Reports: FunctionComponent<Props> = ({ params }) => {
const redirectUrl = isEmbedded ? embeddedVaccineRepositoryUrl : baseUrl;

const { data, isFetching } = useGetVaccineRepositoryReports(reportParams);
const columns = useVaccineRepositoryReportsColumns();
const columns = useVaccineRepositoryReportsColumns(reportParams);
return (
<>
<Filters params={params} redirectUrl={redirectUrl} />
Expand All @@ -59,6 +59,7 @@ export const Reports: FunctionComponent<Props> = ({ params }) => {
extraProps={{
loading: isFetching,
defaultPageSize: tableDefaults.limit,
columns,
}}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SingleSelect } from '../../../../components/Inputs/SingleSelect';
import MESSAGES from '../messages';
import { useSaveVaccineStock } from '../hooks/api';
import { useGetCountriesOptions } from '../../SupplyChain/hooks/api/vrf';
import { defaultVaccineOptions } from '../../SupplyChain/constants';
import { singleVaccinesList } from '../../SupplyChain/constants';

type Props = {
isOpen: boolean;
Expand Down Expand Up @@ -71,7 +71,7 @@ const CreateVaccineStock: FunctionComponent<Props> = ({
name="vaccine"
component={SingleSelect}
required
options={defaultVaccineOptions}
options={singleVaccinesList}
withMarginTop
// isLoading={isFetchingCountries}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { FilterButton } from '../../../../../../../../hat/assets/js/apps/Iaso/co
import { useFilterState } from '../../../../../../../../hat/assets/js/apps/Iaso/hooks/useFilterState';
import InputComponent from '../../../../../../../../hat/assets/js/apps/Iaso/components/forms/InputComponent';
import MESSAGES from '../messages';
import { polioVaccines } from '../../../../constants/virus';
import { useGetCountriesOptions } from '../../SupplyChain/hooks/api/vrf';
import { StockManagementListParams } from '../types';
import { baseUrls } from '../../../../constants/urls';
import { singleVaccinesList } from '../../SupplyChain/constants';

const baseUrl = baseUrls.stockManagement;
type Props = { params: StockManagementListParams };
Expand Down Expand Up @@ -46,10 +46,7 @@ export const VaccineStockManagementFilters: FunctionComponent<Props> = ({
keyValue="vaccine_type"
value={filters.vaccine_type}
onChange={handleChange}
options={polioVaccines.map(vaccine => ({
label: vaccine.label,
value: vaccine.value,
}))}
options={singleVaccinesList}
labelString={formatMessage(MESSAGES.vaccine)}
/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { FilterButton } from '../../../../../../../../hat/assets/js/apps/Iaso/co
import { useFilterState } from '../../../../../../../../hat/assets/js/apps/Iaso/hooks/useFilterState';
import InputComponent from '../../../../../../../../hat/assets/js/apps/Iaso/components/forms/InputComponent';
import MESSAGES from '../messages';
import { polioVaccines } from '../../../../constants/virus';
import { apiDateFormat } from '../../../../../../../../hat/assets/js/apps/Iaso/utils/dates';
import { useGetCountriesOptions } from '../hooks/api/vrf';
import { useGetGroupDropdown } from '../../../../../../../../hat/assets/js/apps/Iaso/domains/orgUnits/hooks/requests/useGetGroups';
import { singleVaccinesList } from '../constants';

type Props = { params: any };

Expand Down Expand Up @@ -83,10 +83,7 @@ export const VaccineSupplyChainFilters: FunctionComponent<Props> = ({
keyValue="vaccine_type"
value={filters.vaccine_type}
onChange={handleChange}
options={polioVaccines.map(vaccine => ({
label: vaccine.label,
value: vaccine.value,
}))}
options={singleVaccinesList}
labelString={formatMessage(MESSAGES.vaccine)}
/>
<InputComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ export const defaultVaccineOptions = [
value: 'nOPV2 & bOPV',
},
];

export const singleVaccinesList = [
{
label: 'nOPV2',
value: 'nOPV2',
},
{
label: 'mOPV2',
value: 'mOPV2',
},
{
label: 'bOPV',
value: 'bOPV',
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
CampaignCategory,
useGetCampaigns,
} from '../../../../Campaigns/hooks/api/useGetCampaigns';
import { apiUrl, defaultVaccineOptions } from '../../constants';
import { apiUrl, defaultVaccineOptions, singleVaccinesList } from '../../constants';
import MESSAGES from '../../messages';
import {
CampaignDropdowns,
Expand Down Expand Up @@ -133,15 +133,15 @@ export const useCampaignDropDowns = (
label: c.obr_name,
value: c.obr_name,
}));
const vaccines = selectedCampaign?.vaccines
? selectedCampaign.vaccines.split(',').map(vaccineName => ({
label: vaccineName,
value: vaccineName,
const vaccines = selectedCampaign?.single_vaccines
? selectedCampaign.single_vaccines.split(',').map(vaccineName => ({
label: vaccineName.trim(),
value: vaccineName.trim(),
}))
: defaultVaccineOptions;
: singleVaccinesList;
const rounds = vaccine
? (selectedCampaign?.rounds ?? [])
.filter(round => round.vaccine_names.includes(vaccine))
.filter(round => round.vaccine_names_extended.includes(vaccine))
.map(round => ({
label: `Round ${round.number}`,
value: `${round.number}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.17 on 2024-12-19 13:58

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("polio", "0212_alter_vaccinerequestform_vaccine_type"),
]

operations = [
migrations.AlterField(
model_name="vaccinerequestform",
name="vaccine_type",
field=models.CharField(choices=[("mOPV2", "mOPV2"), ("nOPV2", "nOPV2"), ("bOPV", "bOPV")], max_length=30),
),
]
Loading

0 comments on commit d46101a

Please sign in to comment.