From dabbdb32c2df7fa8dc0331c0b38dcb9e0c9d7e63 Mon Sep 17 00:00:00 2001 From: paschalidi Date: Wed, 21 Apr 2021 14:17:53 +0300 Subject: [PATCH 1/3] fix: DHIS2-10723 port on 2.36.0 (#1630) * fix: DHIS2-10723 (#1622) * fix: geometry * chore: returns the magic * chore: covers all cases --- .../RegistrationDataEntry.epics.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.epics.js b/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.epics.js index b0ff2ab94c..fbda28192c 100644 --- a/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.epics.js +++ b/src/core_modules/capture-core/components/Pages/New/RegistrationDataEntry/RegistrationDataEntry.epics.js @@ -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, @@ -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, From 3185a41cf29907df1b2c9b6b6e2f499fdfadc4cf Mon Sep 17 00:00:00 2001 From: paschalidi Date: Wed, 21 Apr 2021 15:16:57 +0300 Subject: [PATCH 2/3] chore: passes the tests --- cypress/integration/NewEventThroughAddRelationship/index.js | 4 +++- cypress/integration/SearchPage/index.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cypress/integration/NewEventThroughAddRelationship/index.js b/cypress/integration/NewEventThroughAddRelationship/index.js index 774b7e5ef6..8ef9af7e1d 100644 --- a/cypress/integration/NewEventThroughAddRelationship/index.js +++ b/cypress/integration/NewEventThroughAddRelationship/index.js @@ -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(300) + .type('{enter}', { force: true }); cy.get('[data-test="dataentry-field-incidentDate"]') .find('input') .type('2020-01-01') diff --git a/cypress/integration/SearchPage/index.js b/cypress/integration/SearchPage/index.js index 09bcf916b1..e341da043b 100644 --- a/cypress/integration/SearchPage/index.js +++ b/cypress/integration/SearchPage/index.js @@ -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(300) + .type('{enter}', { force: true }); }); When('you see that in the search terms there is no gender displayed', () => { From 0f1d67b23644ab84df22a9d9ba6e685c8855f6d2 Mon Sep 17 00:00:00 2001 From: paschalidi Date: Fri, 23 Apr 2021 12:15:07 +0300 Subject: [PATCH 3/3] chore: 500 --- cypress/integration/NewEventThroughAddRelationship/index.js | 2 +- cypress/integration/SearchPage/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/integration/NewEventThroughAddRelationship/index.js b/cypress/integration/NewEventThroughAddRelationship/index.js index 8ef9af7e1d..5ffd42d615 100644 --- a/cypress/integration/NewEventThroughAddRelationship/index.js +++ b/cypress/integration/NewEventThroughAddRelationship/index.js @@ -51,7 +51,7 @@ When('you fill in the registration details', () => { cy.get('[data-test="form-field-cejWyOfXge6"]') .find('input') .type('Female', { force: true }) - .wait(300) + .wait(500) .type('{enter}', { force: true }); cy.get('[data-test="dataentry-field-incidentDate"]') .find('input') diff --git a/cypress/integration/SearchPage/index.js b/cypress/integration/SearchPage/index.js index e341da043b..df613e00e6 100644 --- a/cypress/integration/SearchPage/index.js +++ b/cypress/integration/SearchPage/index.js @@ -316,7 +316,7 @@ When('you select gender', () => { cy.get('[data-test="form-field-cejWyOfXge6"]') .find('input') .type('Female', { force: true }) - .wait(300) + .wait(500) .type('{enter}', { force: true }); });