Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pirupius committed Mar 20, 2024
1 parent 85071c9 commit 209bdbb
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 61 deletions.
13 changes: 5 additions & 8 deletions src/components/extension/ohri-extension-parcel.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import { OHRIFormFieldProps } from '../../api/types';

const OHRIExtensionParcel: React.FC<OHRIFormFieldProps> = ({ question }) => {
const { encounterContext, isSubmitting } = useContext(OHRIFormContext);
const submissionNotifier = useMemo(
() => new BehaviorSubject<{ isSubmitting: boolean }>({ isSubmitting: false }),
[],
);
const submissionNotifier = useMemo(() => new BehaviorSubject<{ isSubmitting: boolean }>({ isSubmitting: false }), []);

const state = useMemo(() => ({ patientUuid: encounterContext.patient.id, submissionNotifier }), [
encounterContext.patient.id,
submissionNotifier,
]);
const state = useMemo(
() => ({ patientUuid: encounterContext.patient.id, submissionNotifier }),
[encounterContext.patient.id, submissionNotifier],
);

useEffect(() => {
if (question.questionOptions.extensionSlotName && question.questionOptions.extensionId) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/inputs/date/ohri-date.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ const OHRIDate: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler, p
time
? time
: field.value instanceof Date
? field.value.toLocaleDateString(window.navigator.language)
: field.value
? field.value.toLocaleDateString(window.navigator.language)
: field.value
}
onChange={onTimeChange}
/>{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const OHRIEncounterLocationPicker: React.FC<{ question: OHRIFormField; on
isInline={isInline}
/>
</div>

) : (
!question.isHidden && (
<div className={`${styles.boldedLabel} ${styles.formInputField} ${styles.multiselectOverride} ${styles.flexRow}`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const OHRISectionCollapsibleToggle = () => {
const metas = useExtensionSlotMeta('patient-chart-workspace-header-slot');
const callBack = metas['ohri-form-header-toggle-ext']?.handleCollapse;

const toggleCollapsedStatus = e => {
const toggleCollapsedStatus = (e) => {
callBack && callBack(e);
};

Expand Down
26 changes: 13 additions & 13 deletions src/components/sidebar/ohri-form-sidebar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@ function OHRIFormSidebar({
}
}, [defaultPage, scrollablePages]);

const joinWord = value => {
const joinWord = (value) => {
return value.replace(/\s/g, '');
};

const unspecifiedFields = useMemo(() => {
return (
Object.keys(values)
.filter(key => key.endsWith('-unspecified'))
.filter((key) => key.endsWith('-unspecified'))
// find parent control
.map(key => key.split('-unspecified')[0])
.map((key) => key.split('-unspecified')[0])
// factor-out those with values
.filter(key => isEmpty(values[key]))
.filter((key) => isEmpty(values[key]))
// return the unspecified control keys
.map(key => `${key}-unspecified`)
.map((key) => `${key}-unspecified`)
);
}, [values]);

const handleClick = selected => {
const handleClick = (selected) => {
const activeID = selected.replace(/\s/g, '');
setActiveLink(selected);
scrollIntoView(activeID);
};

const markAllAsUnspecified = useCallback(
toggled => {
(toggled) => {
if (toggled) {
unspecifiedFields.forEach(field => {
unspecifiedFields.forEach((field) => {
values[field] = true;
});
} else {
unspecifiedFields.forEach(field => {
unspecifiedFields.forEach((field) => {
values[field] = false;
});
}
Expand All @@ -74,10 +74,10 @@ function OHRIFormSidebar({
joinWord(page.label) === selectedPage && pagesWithErrors.includes(page.label)
? styles.sidebarSectionErrorActive
: joinWord(page.label) === selectedPage
? styles.sidebarSectionActive
: pagesWithErrors.includes(page.label)
? styles.sidebarSectionError
: styles.sidebarSection
? styles.sidebarSectionActive
: pagesWithErrors.includes(page.label)
? styles.sidebarSectionError
: styles.sidebarSection
}
key={index}
onClick={() => handleClick(page.label)}>
Expand Down
2 changes: 1 addition & 1 deletion src/datasources/concept-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ConceptDataSource extends BaseOpenMRSDataSource {
} else {
return openmrsFetch(searchTerm ? `${apiUrl}&q=${searchTerm}` : apiUrl).then(({ data }) => {
return data.results.filter(
concept => concept.conceptClass && config.class.includes(concept.conceptClass.uuid),
(concept) => concept.conceptClass && config.class.includes(concept.conceptClass.uuid),
);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/datasources/location-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ export class LocationDataSource extends BaseOpenMRSDataSource {
fetchData(searchTerm: string, config?: Record<string, any>, uuid?: string): Promise<any[]> {
let apiUrl = this.url;
const urlParts = apiUrl.split('?');
if (config?.tag) {
if (config?.tag) {
apiUrl = `${urlParts[0]}?tag=${config.tag}&${urlParts[1]}`;
}
//overwrite url if there's a uuid value, meaning we are in edit mode
if(uuid){
if (uuid) {
apiUrl = `${urlParts[0]}/${uuid}?${urlParts[1]}`;
}

return openmrsFetch(searchTerm ? `${apiUrl}&q=${searchTerm}` : apiUrl).then(({ data }) => {
if(data.results){
if (data.results) {
return data.results;
}
return data;
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useClobData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { OHRIFormSchema, OpenmrsForm } from '../api/types';
import useSWRImmutable from 'swr/immutable';

export function useClobData(form: OpenmrsForm) {
const valueReferenceUuid = useMemo(() => form?.resources?.find(({ name }) => name === 'JSON schema').valueReference, [
form,
]);
const valueReferenceUuid = useMemo(
() => form?.resources?.find(({ name }) => name === 'JSON schema').valueReference,
[form],
);
const { data, error } = useSWRImmutable<{ data: OHRIFormSchema }, Error>(
valueReferenceUuid ? `/ws/rest/v1/clobdata/${valueReferenceUuid}` : null,
openmrsFetch,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useEncounterRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function useEncounterRole() {
'/ws/rest/v1/encounterrole?v=custom:(uuid,display,name)',
openmrsFetch,
);
const clinicalEncounterRole = data?.data.results.find(encounterRole => encounterRole.name === 'Clinician');
const clinicalEncounterRole = data?.data.results.find((encounterRole) => encounterRole.name === 'Clinician');

if (clinicalEncounterRole) {
return { encounterRole: clinicalEncounterRole, error, isLoading };
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useFormFieldHandlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export function useFormFieldHandlers(fields: OHRIFormField[]) {

useEffect(() => {
const supportedTypes = new Set<string>();
fields.forEach(field => {
fields.forEach((field) => {
supportedTypes.add(field.type);
});
const supportedTypesArray = Array.from(supportedTypes);
Promise.all(supportedTypesArray.map(type => getRegisteredFieldSubmissionHandler(type))).then(handlers => {
Promise.all(supportedTypesArray.map((type) => getRegisteredFieldSubmissionHandler(type))).then((handlers) => {
const typeToHandlersArray = supportedTypesArray.map((type, index) => ({
[type]: handlers[index],
}));
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useFormFieldValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export function useFormFieldValidators(fields: OHRIFormField[]) {

useEffect(() => {
const supportedTypes = new Set<string>(['default']);
fields.forEach(field => {
field.validators?.forEach(validator => supportedTypes.add(validator.type));
fields.forEach((field) => {
field.validators?.forEach((validator) => supportedTypes.add(validator.type));
});
const supportedTypesArray = Array.from(supportedTypes);
Promise.all(supportedTypesArray.map(type => getRegisteredValidator(type))).then(validators => {
Promise.all(supportedTypesArray.map((type) => getRegisteredValidator(type))).then((validators) => {
setValidators(
Object.assign({}, ...validators.map((validator, index) => ({ [supportedTypesArray[index]]: validator }))),
);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useFormsConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function useFormsConfig(moduleName: string, configPath: string) {

useEffect(() => {
if (moduleName && configPath) {
getConfig(moduleName).then(c => {
getConfig(moduleName).then((c) => {
setConfig({ config, ...get(c, configPath, config) });
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useInitialValues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('useInitialValues', () => {
const encounterDate = new Date();

afterEach(() => {
allFormFields.slice(0, 6).forEach(field => {
allFormFields.slice(0, 6).forEach((field) => {
delete field.value;
});
});
Expand Down Expand Up @@ -200,8 +200,8 @@ describe('useInitialValues', () => {
date_of_birth_1: new Date('2023-07-24T00:00:00.000+0000').toLocaleDateString('en-US'),
infant_name_1: ' TDB II',
});
expect(allFormFields.find(field => field.id === 'date_of_birth_1')).not.toBeNull();
expect(allFormFields.find(field => field.id === 'infant_name_1')).not.toBeNull();
expect(allFormFields.find((field) => field.id === 'date_of_birth_1')).not.toBeNull();
expect(allFormFields.find((field) => field.id === 'infant_name_1')).not.toBeNull();
});

it('should verify that the "isBindingComplete" flag is set to true only when the resolution of calculated values are completed', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePatientData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const patientGenderMap = {
unknown: 'U',
};

export const usePatientData = patientUuid => {
export const usePatientData = (patientUuid) => {
const { patient, isLoading: isLoadingPatient, error: patientError } = usePatient(patientUuid);
if (patient && !isLoadingPatient) {
// This is to support backward compatibility with the AMPATH JSON format
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useWorkspaceLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useWorkspaceLayout(rootRef): 'minimized' | 'maximized' {
containerWidth && setLayout(containerWidth > TABLET_MAX ? 'maximized' : 'minimized');
};
handleResize();
const resizeObserver = new ResizeObserver(entries => {
const resizeObserver = new ResizeObserver((entries) => {
handleResize();
});

Expand Down
2 changes: 1 addition & 1 deletion src/registry/inbuilt-components/inbuiltDataSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export const inbuiltDataSources: Array<RegistryItem<DataSource<any>>> = [
];

export const validateInbuiltDatasource = (name: string) => {
return inbuiltDataSources.some(datasource => datasource.name === name);
return inbuiltDataSources.some((datasource) => datasource.name === name);
};
2 changes: 1 addition & 1 deletion src/registry/inbuilt-components/template-component-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const templateToComponentMap = [
{
name: 'problem',
baseControlComponent: UISelectExtended,
}
},
];
4 changes: 2 additions & 2 deletions src/submission-handlers/base-handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const encounterContext: EncounterContext = {
},
sessionMode: 'enter',
encounterDate: new Date(2020, 11, 29),
setEncounterDate: value => {},
setEncounterDate: (value) => {},
};

describe('ObsSubmissionHandler - handleFieldSubmission', () => {
Expand Down Expand Up @@ -823,7 +823,7 @@ describe('ObsSubmissionHandler - getInitialValue', () => {
const originalModule = jest.requireActual('../api/api');
return {
getConcept: jest.fn(() => {
return new Observable(sub => {
return new Observable((sub) => {
sub.next({
uuid: '1492AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
display: 'Ever tested positive for HIV before?',
Expand Down
6 changes: 3 additions & 3 deletions src/utils/expression-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('findAndRegisterReferencedFields', () => {
it('should register field dependants', () => {
// setup
const expression = "linkedToCare == 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3' && !isEmpty(htsProviderRemarks)";
const patientIdentificationNumberField = testFields.find(f => f.id === 'patientIdentificationNumber');
const patientIdentificationNumberField = testFields.find((f) => f.id === 'patientIdentificationNumber');

// replay
findAndRegisterReferencedFields(
Expand All @@ -211,8 +211,8 @@ describe('findAndRegisterReferencedFields', () => {
);

// verify
const linkedToCare = testFields.find(f => f.id === 'linkedToCare');
const htsProviderRemarks = testFields.find(f => f.id === 'htsProviderRemarks');
const linkedToCare = testFields.find((f) => f.id === 'linkedToCare');
const htsProviderRemarks = testFields.find((f) => f.id === 'htsProviderRemarks');
expect(linkedToCare.fieldDependants).toStrictEqual(new Set(['patientIdentificationNumber']));
expect(htsProviderRemarks.fieldDependants).toStrictEqual(new Set(['patientIdentificationNumber']));
});
Expand Down
6 changes: 3 additions & 3 deletions src/utils/expression-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Common expression runner - evaluateExpression', () => {
referredToPreventionServices: [],
bodyTemperature: 0,
};
allFields.forEach(field => {
allFields.forEach((field) => {
field.fieldDependants = undefined;
});
});
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('Common expression runner - checkReferenceToResolvedFragment', () => {

describe('Common expression runner - validate helper functions', () => {
const allFields = JSON.parse(JSON.stringify(testFields));
const allFieldsKeys = allFields.map(f => f.id);
const allFieldsKeys = allFields.map((f) => f.id);
let valuesMap = {
linkedToCare: '',
patientIdentificationNumber: '',
Expand All @@ -301,7 +301,7 @@ describe('Common expression runner - validate helper functions', () => {
referredToPreventionServices: [],
bodyTemperature: 0,
};
allFields.forEach(field => {
allFields.forEach((field) => {
field.fieldDependants = undefined;
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/validators/default-value-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const OHRIDefaultFieldValueValidator: FieldValidator = {
const codedTypes = ['radio', 'checkbox', 'select', 'content-switcher'];
if (codedTypes.includes(field.questionOptions.rendering)) {
// check whether value exists in answers
if (!field.questionOptions.answers?.find(answer => answer.concept == value)) {
if (!field.questionOptions.answers?.find((answer) => answer.concept == value)) {
return [
{ resultType: 'error', errCode: 'invalid.defaultValue', message: 'Value not found in coded answers list' },
];
Expand Down
2 changes: 1 addition & 1 deletion src/validators/ohri-js-expression-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('OHRIJSExpressionValidator - validate', () => {

it('should evaluate js expressions', () => {
// setup
const field = allFields.find(f => f.id == 'htsProviderRemarks');
const field = allFields.find((f) => f.id == 'htsProviderRemarks');
const failsWhenExpression = '!isEmpty(myValue) && isEmpty(`referredToPreventionServices`)';

// replay
Expand Down
10 changes: 5 additions & 5 deletions src/validators/ohri-js-expression-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ interface JSExpressionValidatorConfig {
}

export const OHRIJSExpressionValidator: FieldValidator = {
validate: function(field: OHRIFormField, value: any, config: JSExpressionValidatorConfig) {
validate: function (field: OHRIFormField, value: any, config: JSExpressionValidatorConfig) {
const INVALID_VALUE_ERR_CODE = 'value.invalid';
const INVALID_VALUE_ERR_MESSAGE = 'Invalid value';
const FIELD_HAS_WARNINGS_MESSAGE = 'Field has warnings';
config.expressionContext.myValue = value;
return Object.keys(config)
.filter(key => key === 'failsWhenExpression' || key === 'warnsWhenExpression')
.flatMap(key => {
.filter((key) => key === 'failsWhenExpression' || key === 'warnsWhenExpression')
.flatMap((key) => {
const isErrorValidator = key === 'failsWhenExpression';
return evaluateExpression(
config[key],
Expand All @@ -34,8 +34,8 @@ export const OHRIJSExpressionValidator: FieldValidator = {
message: config.message
? config.message
: isErrorValidator
? INVALID_VALUE_ERR_MESSAGE
: FIELD_HAS_WARNINGS_MESSAGE,
? INVALID_VALUE_ERR_MESSAGE
: FIELD_HAS_WARNINGS_MESSAGE,
},
]
: [];
Expand Down

0 comments on commit 209bdbb

Please sign in to comment.