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 port on 2.36.0 #1630

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ import { navigateToTrackedEntityDashboard } from '../../../../utils/navigateToTr
import { getTrackerProgramThrowIfNotFound, scopeTypes } from '../../../../metaData';


const geometryType = (key) => {
const types = ['Point', 'None', 'Polygon'];
return types.find(type => key.toLowerCase().includes(type.toLowerCase()));
};
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)
.filter(key => geometryType(key))
.reduce((acc, currentKey) => ({ type: geometryType(currentKey), coordinates: formValues[currentKey] }), {});

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,
// we want the incident to default to enrollmentDate
Expand Down Expand Up @@ -65,6 +78,7 @@ export const startSavingNewTrackedEntityInstanceEpic: Epic = (action$: InputObse
return saveNewTrackedEntityInstance(
{
attributes: deriveAttributesFromFormValues(values),
geometry: deriveGeometryFromFormValues(values),
enrollments: [],
orgUnit: orgUnitId,
trackedEntityType: trackedEntityTypeId,
Expand Down Expand Up @@ -98,12 +112,13 @@ export const startSavingNewTrackedEntityInstanceWithEnrollmentEpic: Epic = (acti
const { currentSelections: { orgUnitId, programId }, formsValues, dataEntriesFieldsValue } = store.value;
const { incidentDate, enrollmentDate } = dataEntriesFieldsValue['newPageDataEntryId-newEnrollment'] || { };
const { trackedEntityType, stages } = getTrackerProgramThrowIfNotFound(programId);
const values = formsValues['newPageDataEntryId-newEnrollment'];
const values = formsValues['newPageDataEntryId-newEnrollment'] || {};
const events = deriveEvents({ stages, enrollmentDate, incidentDate, programId, orgUnitId });

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