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 date error on form edit #140

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
38 changes: 19 additions & 19 deletions src/submission-handlers/base-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ export const ObsSubmissionHandler: SubmissionHandler = {
assignedObsIds.push(matchedObs[0].obsGroup?.uuid);
}
if (rendering == 'checkbox') {
assignedObsIds.push(...matchedObs.map(obs => obs.uuid));
assignedObsIds.push(...matchedObs.map((obs) => obs.uuid));
field.value = matchedObs;
return field.value.map(o => o.value.uuid);
return field.value.map((o) => o.value.uuid);
}
const obs = matchedObs[0];
field.value = JSON.parse(JSON.stringify(obs));
assignedObsIds.push(obs.uuid);
if (rendering == 'radio' || rendering == 'content-switcher') {
getConcept(field.questionOptions.concept, 'custom:(uuid,display,datatype:(uuid,display,name))').subscribe(
result => {
(result) => {
if (result.datatype.name == 'Boolean') {
field.value.value = obs.value.uuid;
}
Expand All @@ -75,7 +75,7 @@ export const ObsSubmissionHandler: SubmissionHandler = {
if (typeof obs.value == 'string' || typeof obs.value == 'number') {
if (rendering.startsWith('date')) {
const dateObject = parseToLocalDateTime(field.value.value);
field.value.value = formatDate(dateObject, { mode: 'wide' });
field.value.value = dayjs(dateObject).format('YYYY-MM-DD HH:mm');
return dateObject;
}
return obs.value;
Expand All @@ -98,15 +98,15 @@ export const ObsSubmissionHandler: SubmissionHandler = {
}
if (field.questionOptions.rendering == 'checkbox') {
return value.map(
chosenOption => field.questionOptions.answers.find(option => option.concept == chosenOption)?.label,
(chosenOption) => field.questionOptions.answers.find((option) => option.concept == chosenOption)?.label,
);
}
if (rendering == 'content-switcher' || rendering == 'select' || rendering == 'toggle') {
const concept = typeof field.value.value === 'object' ? field.value.value.uuid : field.value.value;
return field.questionOptions.answers.find(option => option.concept == concept)?.label;
return field.questionOptions.answers.find((option) => option.concept == concept)?.label;
}
if (rendering == 'radio') {
return field.questionOptions.answers.find(option => option.concept == value)?.label;
return field.questionOptions.answers.find((option) => option.concept == value)?.label;
}
return value;
},
Expand All @@ -122,13 +122,13 @@ export const ObsSubmissionHandler: SubmissionHandler = {
if (typeof obs.value == 'string' || typeof obs.value == 'number') {
if (rendering == 'date' || rendering == 'datetime') {
const dateObj = parseToLocalDateTime(`${obs.value}`);
return { value: dateObj, display: formatDate(dateObj, { mode: 'wide' }) };
return { value: dateObj, display: dayjs(dateObj).format('YYYY-MM-DD HH:mm') };
}
return { value: obs.value, display: obs.value };
}
return {
value: obs.value?.uuid,
display: field.questionOptions.answers.find(option => option.concept == obs.value?.uuid)?.label,
display: field.questionOptions.answers.find((option) => option.concept == obs.value?.uuid)?.label,
};
}
return null;
Expand Down Expand Up @@ -187,12 +187,12 @@ export const findObsByFormField = (
claimedObsIds: string[],
field: OHRIFormField,
): OpenmrsObs[] => {
const obs = obsList.filter(o => o.formFieldPath == `ohri-forms-${field.id}`);
const obs = obsList.filter((o) => o.formFieldPath == `ohri-forms-${field.id}`);
// We shall fall back to mapping by the associated concept
// That being said, we shall find all matching obs and pick the one that wasn't previously claimed.
if (!obs?.length) {
const obsByConcept = obsList.filter(obs => obs.concept.uuid == field.questionOptions.concept);
return claimedObsIds?.length ? obsByConcept.filter(obs => !claimedObsIds.includes(obs.uuid)) : obsByConcept;
const obsByConcept = obsList.filter((obs) => obs.concept.uuid == field.questionOptions.concept);
return claimedObsIds?.length ? obsByConcept.filter((obs) => !claimedObsIds.includes(obs.uuid)) : obsByConcept;
}
return obs;
};
Expand All @@ -201,8 +201,8 @@ const multiSelectObsHandler = (field: OHRIFormField, values: Array<string>, cont
if (!field.value) {
field.value = [];
}
values.forEach(value => {
const obs = field.value.find(o => {
values.forEach((value) => {
const obs = field.value.find((o) => {
if (typeof o.value == 'string') {
return o.value == value;
}
Expand All @@ -217,9 +217,9 @@ const multiSelectObsHandler = (field: OHRIFormField, values: Array<string>, cont

// void or remove unchecked options
field.questionOptions.answers
.filter(opt => !values.some(v => v == opt.concept))
.forEach(opt => {
const observations = field.value.filter(o => {
.filter((opt) => !values.some((v) => v == opt.concept))
.forEach((opt) => {
const observations = field.value.filter((o) => {
if (typeof o.value == 'string') {
return o.value == opt.concept;
}
Expand All @@ -228,11 +228,11 @@ const multiSelectObsHandler = (field: OHRIFormField, values: Array<string>, cont
if (!observations.length) {
return;
}
observations.forEach(obs => {
observations.forEach((obs) => {
if (context.sessionMode == 'edit' && obs.uuid) {
obs.voided = true;
} else {
field.value = field.value.filter(o => o.value !== opt.concept);
field.value = field.value.filter((o) => o.value !== opt.concept);
}
});
});
Expand Down
Loading