Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DHIS2-17192] show related stages widget on registration page #3880

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ba81d9c
feat: show related stages Widget on registration page
simonadomnisoru Nov 14, 2024
293c359
feat: add enableLinkExistingEvent prop
simonadomnisoru Nov 18, 2024
0bd5fa9
Merge branch 'master' into DHIS2-17192
simonadomnisoru Nov 18, 2024
d88b9c2
Merge branch 'master' into DHIS2-17192
simonadomnisoru Nov 20, 2024
ddb3f0e
chore: improve wording
simonadomnisoru Nov 27, 2024
3eb3c93
feat: show related stages widget when adding a new relationship
simonadomnisoru Dec 2, 2024
c1a1edb
Merge branch 'master' into DHIS2-17192
simonadomnisoru Dec 2, 2024
32c824f
Merge branch 'master' into DHIS2-17192
simonadomnisoru Dec 5, 2024
9b2d205
Merge branch 'master' into DHIS2-17192
simonadomnisoru Dec 9, 2024
2a27f57
chore: typo
simonadomnisoru Dec 9, 2024
9ecf999
chore: fix PR comments
simonadomnisoru Dec 11, 2024
28e26b8
chore: correct the variable name to match its format
simonadomnisoru Dec 17, 2024
d137e8e
chore: move helpers files to DataEntries/EnrollmentRegistrationEntry
simonadomnisoru Dec 17, 2024
0dc2f01
chore: use action naming throughout the code
simonadomnisoru Dec 17, 2024
6b97817
chore: rename helper file to getRelationshipNewTeiName
simonadomnisoru Dec 17, 2024
d643dd6
Merge branch 'master' into DHIS2-17192
simonadomnisoru Dec 17, 2024
743bcbf
feat: simplify how we determine what event to redirect to
simonadomnisoru Dec 18, 2024
8366d23
Merge branch 'master' into DHIS2-17192
simonadomnisoru Jan 7, 2025
e4a16ca
fix: simplify how we determine what event to redirect to
simonadomnisoru Jan 13, 2025
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
14 changes: 10 additions & 4 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ msgstr "Save {{trackedEntityTypeName}}"
msgid "Save {{trackedEntityName}}"
msgstr "Save {{trackedEntityName}}"

msgid "Enter details now is not available when creating a relationship"
msgstr "Enter details now is not available when creating a relationship"

msgid "Save new {{trackedEntityTypeName}} and link"
msgstr "Save new {{trackedEntityTypeName}} and link"

Expand Down Expand Up @@ -1376,8 +1379,8 @@ msgstr "{{trackedEntityTypeName}} profile"
msgid "tracked entity instance"
msgstr "tracked entity instance"

msgid "Link to an existing {{linkableStageLabel}}"
msgstr "Link to an existing {{linkableStageLabel}}"
msgid "Choose a {{linkableStageLabel}} event"
msgstr "Choose a {{linkableStageLabel}} event"

msgid "Choose a {{linkableStageLabel}}"
msgstr "Choose a {{linkableStageLabel}}"
Expand All @@ -1388,14 +1391,17 @@ msgstr "{{ linkableStageLabel }} is not repeatable"
msgid "{{ linkableStageLabel }} has no linkable events"
msgstr "{{ linkableStageLabel }} has no linkable events"

msgid "Actions - {{relationshipName}}"
msgstr "Actions - {{relationshipName}}"

msgid "Ambiguous relationships, contact system administrator"
msgstr "Ambiguous relationships, contact system administrator"

msgid "Enter details now"
msgstr "Enter details now"

msgid "Link to an existing"
msgstr "Link to an existing"
msgid "Link to an existing event"
msgstr "Link to an existing event"

msgid "Scheduled date"
msgstr "Scheduled date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
withAOCFieldBuilder,
withDataEntryFields,
} from '../../DataEntryDhis2Helpers';
import type { RelatedStageRefPayload } from '../../WidgetRelatedStages';

const overrideMessagePropNames = {
errorMessage: 'validationError',
Expand Down Expand Up @@ -333,6 +334,7 @@ type FinalTeiDataEntryProps = {
onUpdateFormFieldAsync: Function,
onUpdateFormField: Function,
firstStageMetaData?: ?{ stage: ProgramStage },
relatedStageRef?: { current: ?RelatedStageRefPayload },
formFoundation: RenderFoundation,
};
// final step before the generic dataEntry is inserted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import type { Props } from './EnrollmentWithFirstStageDataEntry.types';
import { FirstStageDataEntry } from './EnrollmentWithFirstStageDataEntry.component';
import { useDataEntrySections } from './hooks';
import { Section } from '../../../../metaData';
import { WidgetRelatedStages } from '../../../WidgetRelatedStages';

const getSectionId = sectionId =>
(sectionId === Section.MAIN_SECTION_ID ? `${Section.MAIN_SECTION_ID}-stage` : sectionId);

export const EnrollmentWithFirstStageDataEntry = (props: Props) => {
const { firstStageMetaData, ...passOnProps } = props;
const { firstStageMetaData, relatedStageRef, relatedStageActionsOptions, ...passOnProps } = props;
const {
stage: { stageForm: firstStageFormFoundation, name: stageName },
} = firstStageMetaData;
Expand All @@ -19,10 +20,18 @@ export const EnrollmentWithFirstStageDataEntry = (props: Props) => {
const dataEntrySections = useDataEntrySections(stageName, beforeSectionId);

return (
<FirstStageDataEntry
{...passOnProps}
firstStageMetaData={firstStageMetaData}
dataEntrySections={dataEntrySections}
/>
<>
<FirstStageDataEntry
{...passOnProps}
firstStageMetaData={firstStageMetaData}
dataEntrySections={dataEntrySections}
/>
<WidgetRelatedStages
ref={relatedStageRef}
programId={passOnProps.programId}
programStageId={firstStageMetaData.stage?.id}
actionsOptions={relatedStageActionsOptions}
/>
</>
);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
// @flow
import type { ProgramStage, RenderFoundation } from '../../../../metaData';
import type { RelatedStageRefPayload } from '../../../WidgetRelatedStages';
import { relatedStageActions } from '../../../WidgetRelatedStages';

export type Props = {
firstStageMetaData: {
stage: ProgramStage,
},
formFoundation: RenderFoundation,
programId: string,
relatedStageRef?: { current: ?RelatedStageRefPayload },
relatedStageActionsOptions?: {
[key: $Keys<typeof relatedStageActions>]: {
hidden?: boolean,
disabled?: boolean,
disabledMessage?: string
},
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import React from 'react';
import React, { useRef } from 'react';
import type { ComponentType } from 'react';
import { useSelector } from 'react-redux';
import { EnrollmentRegistrationEntryComponent } from './EnrollmentRegistrationEntry.component';
Expand All @@ -10,6 +10,7 @@ import { dataEntryHasChanges } from '../../DataEntry/common/dataEntryHasChanges'
import {
useBuildEnrollmentPayload,
} from './hooks/useBuildEnrollmentPayload';
import type { RelatedStageRefPayload } from '../../WidgetRelatedStages';

export const EnrollmentRegistrationEntry: ComponentType<OwnProps> = ({
selectedScopeId,
Expand All @@ -22,6 +23,7 @@ export const EnrollmentRegistrationEntry: ComponentType<OwnProps> = ({
onCancel,
...passOnProps
}) => {
const relatedStageRef = useRef<?RelatedStageRefPayload>(null);
const { orgUnit, error } = useCoreOrgUnit(orgUnitId);
const {
ready,
Expand Down Expand Up @@ -57,13 +59,15 @@ export const EnrollmentRegistrationEntry: ComponentType<OwnProps> = ({
}

const onSaveWithEnrollment = () => {
const teiWithEnrollment = buildTeiWithEnrollment();
onSave(teiWithEnrollment);
const { teiWithEnrollment, formHasError, redirect } =
buildTeiWithEnrollment(relatedStageRef);
!formHasError && onSave(teiWithEnrollment, redirect);
};

return (
<EnrollmentRegistrationEntryComponent
{...passOnProps}
relatedStageRef={relatedStageRef}
firstStageMetaData={firstStageMetaData}
selectedScopeId={selectedScopeId}
formId={formId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { SaveForDuplicateCheck } from '../common/TEIAndEnrollment/Duplicate
import type { ExistingUniqueValueDialogActionsComponent } from '../withErrorMessagePostProcessor';
import type { InputAttribute } from './hooks/useFormValues';
import { RenderFoundation, ProgramStage } from '../../../metaData';
import type { RelatedStageRefPayload } from '../../WidgetRelatedStages';
import { relatedStageActions } from '../../WidgetRelatedStages';

type TrackedEntityAttributes = Array<{
attribute: string,
Expand All @@ -32,6 +34,21 @@ export type EnrollmentPayload = {|
attributes: TrackedEntityAttributes,
geometry: any,
|}
],
relationships?: [
{
relationshipType: string,
from: {
event: {
event: string,
},
},
to: {
event: {
event: string,
},
},
}
]
|}

Expand All @@ -51,6 +68,14 @@ export type OwnProps = $ReadOnly<{|
trackedEntityInstanceAttributes?: Array<InputAttribute>,
saveButtonText: (trackedEntityName: string) => string,
firstStageMetaData?: ?{ stage: ?ProgramStage },
relatedStageRef?: { current: ?RelatedStageRefPayload },
relatedStageActionsOptions?: {
[key: $Keys<typeof relatedStageActions>]: {
hidden?: boolean,
disabled?: boolean,
disabledMessage?: string
},
},
|}>;

type ContainerProps = {|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// @flow
import moment from 'moment';
import { dataElementTypes, ProgramStage } from '../../../../../metaData';
import { convertClientToServer } from '../../../../../converters';
import { convertCategoryOptionsToServer } from '../../../../../converters/clientToServer';
import { dataElementTypes, ProgramStage } from '../../../../metaData';
import { convertClientToServer } from '../../../../converters';
import { convertCategoryOptionsToServer } from '../../../../converters/clientToServer';
import type { RequestEvent, LinkedRequestEvent } from '../../../DataEntries';
import { generateUID } from '../../../../utils/uid/generateUID';

const ignoreAutoGenerateIfApplicable = (stage, firstStageDuringRegistrationEvent) =>
!firstStageDuringRegistrationEvent || firstStageDuringRegistrationEvent.id !== stage.id;
const ignoreAutoGenerateIfApplicable = (stage, stageToSkip) =>
!stageToSkip || stageToSkip.programStage !== stage.id;

export const deriveAutoGenerateEvents = ({
stages,
enrolledAt,
occurredAt,
programId,
orgUnitId,
firstStageMetadata,
firstStageDuringRegistrationEvent,
relatedStageLinkedEvent,
attributeCategoryOptions,
serverMinorVersion,
}: {
Expand All @@ -22,7 +25,8 @@ export const deriveAutoGenerateEvents = ({
occurredAt: string,
programId: string,
orgUnitId: string,
firstStageMetadata: ?ProgramStage,
firstStageDuringRegistrationEvent: ?RequestEvent,
relatedStageLinkedEvent: ?LinkedRequestEvent,
attributeCategoryOptions: { [categoryId: string]: string } | string,
serverMinorVersion: number,
}) => {
Expand All @@ -33,7 +37,8 @@ export const deriveAutoGenerateEvents = ({
// $FlowFixMe[missing-annot]
return [...stages.values()]
.filter(({ autoGenerateEvent }) => autoGenerateEvent)
.filter(stage => ignoreAutoGenerateIfApplicable(stage, firstStageMetadata))
.filter(stage => ignoreAutoGenerateIfApplicable(stage, firstStageDuringRegistrationEvent))
.filter(stage => ignoreAutoGenerateIfApplicable(stage, relatedStageLinkedEvent))
.map(
({
id: programStage,
Expand Down Expand Up @@ -71,6 +76,7 @@ export const deriveAutoGenerateEvents = ({
return {
...eventInfo,
...eventAttributeCategoryOptions,
event: generateUID(),
programStage,
program: programId,
orgUnit: orgUnitId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @flow
import { pipe } from 'capture-core-utils';
import { dataElementTypes, ProgramStage } from '../../../../../metaData';
import { convertFormToClient, convertClientToServer } from '../../../../../converters';
import { convertCategoryOptionsToServer } from '../../../../../converters/clientToServer';
import { convertStatusOut } from '../../../../DataEntries';
import { generateUID } from '../../../../utils/uid/generateUID';
import { dataElementTypes, ProgramStage } from '../../../../metaData';
import { convertFormToClient, convertClientToServer } from '../../../../converters';
import { convertCategoryOptionsToServer } from '../../../../converters/clientToServer';
import { convertStatusOut } from '../../../DataEntries';
import { standardGeoJson } from './standardGeoJson';

const convertFn = pipe(convertFormToClient, convertClientToServer);
Expand Down Expand Up @@ -37,6 +38,7 @@ export const deriveFirstStageDuringRegistrationEvent = ({
: {};

const event: any = {
event: generateUID(),
status: convertStatusOut(stageComplete),
geometry: standardGeoJson(stageGeometry),
occurredAt: convertFn(stageOccurredAt, dataElementTypes.DATE),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// @flow
import { ProgramStage } from '../../../../metaData';
import { getConvertedRelatedStageEvent } from '../../../DataEntries';
import type { RequestEvent } from '../../../DataEntries';
import type { RelatedStageRefPayload } from '../../../WidgetRelatedStages';

export const deriveRelatedStageEvent = ({
serverRequestEvent,
relatedStageRef,
firstStageMetaData,
programId,
teiId,
}: {
serverRequestEvent: ?RequestEvent,
relatedStageRef?: { current: ?RelatedStageRefPayload},
firstStageMetaData: ?{ stage: ?ProgramStage},
programId: string,
teiId?: ?string,
}) => {
if (relatedStageRef?.current && relatedStageRef.current.eventHasLinkableStageRelationship()) {
const isValid = relatedStageRef.current.formIsValidOnSave();
const currentProgramStageId = firstStageMetaData?.stage?.id;
if (
!isValid ||
!relatedStageRef.current?.getLinkedStageValues ||
!currentProgramStageId ||
!serverRequestEvent
) {
return {
formHasError: true,
linkedEvent: null,
relationship: null,
linkMode: null,
};
}

const { selectedRelationshipType, relatedStageDataValues, linkMode } =
relatedStageRef.current.getLinkedStageValues();

if (!linkMode) {
return {
formHasError: false,
linkedEvent: null,
relationship: null,
linkMode: null,
};
}

const { linkedEvent, relationship } = getConvertedRelatedStageEvent({
linkMode,
relatedStageDataValues,
serverRequestEvent,
relatedStageType: selectedRelationshipType,
programId,
currentProgramStageId,
teiId,
});

return {
formHasError: false,
linkedEvent,
relationship,
linkMode,
};
}
return {
formHasError: false,
linkedEvent: null,
relationship: null,
linkMode: null,
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
export { deriveFirstStageDuringRegistrationEvent } from './deriveFirstStageDuringRegistrationEvent';
export { deriveRelatedStageEvent } from './deriveRelatedStageEvent';
export { deriveAutoGenerateEvents } from './deriveAutoGenerateEvents';
export { getStageWithOpenAfterEnrollment, PAGES } from './getStageWithOpenAfterEnrollment';
export { standardGeoJson } from './standardGeoJson';
Loading
Loading