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

fix: DHIS2-10723 completes for all cases #1634

Merged
merged 3 commits into from
Apr 23, 2021
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: 3 additions & 1 deletion cypress/integration/NewEventThroughAddRelationship/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ When('you fill in the registration details', () => {
.type('Gonz');
cy.get('[data-test="form-field-cejWyOfXge6"]')
.find('input')
.type('Female{enter}', { force: true });
.type('Female', { force: true })
.wait(500)
.type('{enter}', { force: true });
cy.get('[data-test="dataentry-field-incidentDate"]')
.find('input')
.type('2020-01-01')
Expand Down
4 changes: 3 additions & 1 deletion cypress/integration/SearchPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ When('there is not enrollment tag', () => {
When('you select gender', () => {
cy.get('[data-test="form-field-cejWyOfXge6"]')
.find('input')
.type('Female{enter}', { force: true });
.type('Female', { force: true })
.wait(500)
.type('{enter}', { force: true });
});

When('you see that in the search terms there is no gender displayed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,36 @@ const geometryType = (key) => {
const types = ['Point', 'None', 'Polygon'];
return types.find(type => key.toLowerCase().includes(type.toLowerCase()));
};

const standardGeoJson = (geometry) => {
if (!geometry) {
return undefined;
}
if (Array.isArray(geometry)) {
return {
type: 'Polygon',
coordinates: geometry,
};
} else if (geometry.longitude && geometry.latitude) {
return {
type: 'Point',
coordinates: [geometry.longitude, geometry.latitude],
};
}
return undefined;
};


const deriveAttributesFromFormValues = (formValues = {}) =>
Object.keys(formValues)
.filter(key => !geometryType(key))
.map(key => ({ attribute: key, value: formValues[key] }));

const deriveGeometryFromFormValues = (formValues = {}) => {
const geoJSON = Object.keys(formValues)
const deriveGeometryFromFormValues = (formValues = {}) =>
Object.keys(formValues)
.filter(key => geometryType(key))
.reduce((acc, currentKey) => ({ type: geometryType(currentKey), coordinates: formValues[currentKey] }), {});
.reduce((acc, currentKey) => (standardGeoJson(formValues[currentKey])), undefined);

return geoJSON.type ? geoJSON : undefined;
};

const deriveEvents = ({ stages, enrollmentDate, incidentDate, programId, orgUnitId }) => {
// in case we have a program that does not have an incident date, such as Malaria case diagnosis,
Expand Down Expand Up @@ -110,17 +128,19 @@ export const startSavingNewTrackedEntityInstanceWithEnrollmentEpic: Epic = (acti
ofType(registrationFormActionTypes.NEW_TRACKED_ENTITY_INSTANCE_WITH_ENROLLMENT_SAVE_START),
map(() => {
const { currentSelections: { orgUnitId, programId }, formsValues, dataEntriesFieldsValue } = store.value;
const { incidentDate, enrollmentDate } = dataEntriesFieldsValue['newPageDataEntryId-newEnrollment'] || { };
const { incidentDate, enrollmentDate, geometry } = dataEntriesFieldsValue['newPageDataEntryId-newEnrollment'] || { };
const { trackedEntityType, stages } = getTrackerProgramThrowIfNotFound(programId);
const values = formsValues['newPageDataEntryId-newEnrollment'] || {};
const events = deriveEvents({ stages, enrollmentDate, incidentDate, programId, orgUnitId });


return saveNewTrackedEntityInstanceWithEnrollment(
{
attributes: deriveAttributesFromFormValues(values),
geometry: deriveGeometryFromFormValues(values),
enrollments: [
{
geometry: standardGeoJson(geometry),
incidentDate,
enrollmentDate,
program: programId,
Expand Down