Skip to content

Commit

Permalink
Revert "(feat) O3-2991, support Date type obs on the registration form (
Browse files Browse the repository at this point in the history
#1129)"

This reverts commit f427187.
  • Loading branch information
ibacher committed May 13, 2024
1 parent 68eacab commit 0c79157
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const generateFormatting = (order: Array<string>, separator: string) => {
};

const placeHolder = order.map((x) => (x === 'Y' ? 'YYYY' : x + x)).join(separator);
const dateFormat = order.join(separator).replace('YYYY', 'yyyy');
const dateFormat = order.join(separator);

return { parse, format, placeHolder, dateFormat };
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, { useMemo } from 'react';
import classNames from 'classnames';
import { Field, useField } from 'formik';
import { Field } from 'formik';
import { useTranslation } from 'react-i18next';
import { InlineNotification, Layer, Select, SelectItem, DatePicker, DatePickerInput } from '@carbon/react';
import { InlineNotification, Layer, Select, SelectItem } from '@carbon/react';
import { useConfig } from '@openmrs/esm-framework';
import { type ConceptResponse } from '../../patient-registration.types';
import { type FieldDefinition, type RegistrationConfig } from '../../../config-schema';
import { Input } from '../../input/basic-input/input/input.component';
import { useConcept, useConceptAnswers } from '../field.resource';
import styles from './../field.scss';
import { generateFormatting } from '../../date-util';

export interface ObsFieldProps {
fieldDefinition: FieldDefinition;
Expand All @@ -18,9 +17,6 @@ export interface ObsFieldProps {
export function ObsField({ fieldDefinition }: ObsFieldProps) {
const { t } = useTranslation();
const { data: concept, isLoading } = useConcept(fieldDefinition.uuid);
const [date, dateMeta] = useField('date');

const { format, dateFormat } = generateFormatting(['d', 'm', 'Y'], '/');

const config = useConfig<RegistrationConfig>();

Expand Down Expand Up @@ -55,18 +51,6 @@ export function ObsField({ fieldDefinition }: ObsFieldProps) {
required={fieldDefinition.validation.required}
/>
);
case 'Date':
return (
<DateObsField
concept={concept}
label={fieldDefinition.label}
required={fieldDefinition.validation.required}
dateFormat={dateFormat}
date={date}
dateMeta={dateMeta}
format={format}
/>
);
case 'Coded':
return (
<CodedObsField
Expand Down Expand Up @@ -161,44 +145,6 @@ function NumericObsField({ concept, label, required }: NumericObsFieldProps) {
);
}

interface DateObsFieldProps {
concept: ConceptResponse;
label: string;
required?: boolean;
dateFormat: string;
date: any;
dateMeta: any;
format: any;
}

function DateObsField({ concept, label, required, dateFormat, date, dateMeta, format }: DateObsFieldProps) {
const { t } = useTranslation();
const today = new Date();

const fieldName = `obs.${concept.uuid}`;
return (
<div className={classNames(styles.customField, styles.halfWidthInDesktopView)}>
<Field name={fieldName}>
{({ field, form: { touched, errors }, meta }) => {
return (
<DatePicker dateFormat={dateFormat} datePickerType="single" maxDate={format(today)}>
<DatePickerInput
id={fieldName}
labelText={label ?? concept.display}
required={required}
invalid={errors[fieldName] && touched[fieldName]}
invalidText={dateMeta.error && t(dateMeta.error)}
value={format(date.value)}
{...field}
/>
</DatePicker>
);
}}
</Field>
</div>
);
}

interface CodedObsFieldProps {
concept: ConceptResponse;
answerConceptSetUuid?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useConfig } from '@openmrs/esm-framework';
import { type FieldDefinition } from '../../../config-schema';
import { useConcept, useConceptAnswers } from '../field.resource';
import { ObsField } from './obs-field.component';
import '@testing-library/jest-dom';

const mockUseConfig = useConfig as jest.Mock;

Expand Down Expand Up @@ -43,14 +42,6 @@ const useConceptMockImpl = (uuid: string) => {
],
setMembers: [],
};
} else if (uuid == 'date-uuid') {
data = {
uuid: 'date-uuid',
display: 'Date',
datatype: { display: 'Date', uuid: 'dt' },
answers: [],
setMembers: [],
};
} else {
throw Error(`Programming error, you probably didn't mean to do this: unknown concept uuid '${uuid}'`);
}
Expand Down Expand Up @@ -127,21 +118,6 @@ const numberFieldDef: FieldDefinition = {
customConceptAnswers: [],
};

const dateFieldDef: FieldDefinition = {
id: 'date',
type: 'obs',
label: '',
placeholder: '',
showHeading: false,
uuid: 'date-uuid',
validation: {
required: false,
matches: null,
},
answerConceptSetUuid: null,
customConceptAnswers: [],
};

const codedFieldDef: FieldDefinition = {
id: 'nationality',
type: 'obs',
Expand Down Expand Up @@ -187,12 +163,6 @@ describe('ObsField', () => {
expect(screen.getByRole('spinbutton')).toBeInTheDocument();
});

it('renders a date picker for date concept', async () => {
render(<ObsField fieldDefinition={dateFieldDef} />);
// expect(screen.getByLabelText("Date")).toBeInTheDocument();
expect(screen.getByRole('textbox')).toBeInTheDocument();
});

it('renders a select for a coded concept', () => {
render(<ObsField fieldDefinition={codedFieldDef} />);
// expect(screen.getByLabelText("Nationality")).toBeInTheDocument();
Expand Down

0 comments on commit 0c79157

Please sign in to comment.