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

(enhancement) Add ability to display poc forms only and filter out ht… #573

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions packages/esm-patient-forms-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export const configSchema = {
},
],
},
showHtmlFormEntryForms: {
_type: Type.Boolean,
_default: true,
_description: 'Whether HTML Form Entry forms should be included in lists of forms',
},
};

export interface HtmlFormEntryForm {
Expand Down
8 changes: 5 additions & 3 deletions packages/esm-patient-forms-app/src/hooks/use-forms.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import dayjs from 'dayjs';
import useSWR from 'swr';
import { openmrsFetch } from '@openmrs/esm-framework';
import { openmrsFetch, useConfig } from '@openmrs/esm-framework';
import { ListResponse, FormEncounter, EncounterWithFormRef, CompletedFormInfo } from '../types';
import { customEncounterRepresentation, formEncounterUrl } from '../constants';
import { isFormFullyCached } from '../offline-forms/offline-form-helpers';

export function useFormEncounters(cachedOfflineFormsOnly = false) {
return useSWR([formEncounterUrl, cachedOfflineFormsOnly], async () => {
const res = await openmrsFetch<ListResponse<FormEncounter>>(formEncounterUrl);
const config = useConfig();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: @brandones do we normally declare the config outside of a function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by "declare the config." This all looks reasonable though. useConfig is a hook, so it's subject to the normal rules of hooks; since useFormEncounters is also a hook, this is usage is good.

const url = config.showHtmlFormEntryForms ? formEncounterUrl : formEncounterUrl.concat('&q=poc');
return useSWR([url, cachedOfflineFormsOnly], async () => {
const res = await openmrsFetch<ListResponse<FormEncounter>>(url);
// show published forms and hide component forms
const forms = res.data?.results?.filter((form) => form.published && !/component/i.test(form.name)) ?? [];

Expand Down