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

(feat) O3-4180: Configure Advanced search filter to support person attributes #1362

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
113 changes: 113 additions & 0 deletions __mocks__/search.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,116 @@ export const mockSearchResults = {
],
},
};

export const mockAdvancedSearchResults = [
{
patientId: 14,
uuid: 'e46dfea6-f32d-4b61-bc7d-e79fd35332a4',
identifiers: [
{
identifier: '100008E',
identifierType: {
uuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
display: 'OpenMRS ID',
},
},
],
display: '100008E - Joshua Johnson',
patientIdentifier: {
uuid: '1e6c2da6-f63f-4ea5-a595-ded69df9f882',
identifier: '100008E',
},
person: {
gender: 'M',
age: 5,
birthdate: '2019-09-25T00:00:00.000+0000',
birthdateEstimated: false,
personName: {
display: 'Joshua Johnson',
givenName: 'Joshua',
familyName: 'Johnson',
},
addresses: [
{
address1: 'Address16442',
cityVillage: 'City6442',
stateProvince: 'State6442',
country: 'Country6442',
postalCode: '20839',
preferred: true,
},
],
dead: false,
deathDate: null,
},
attributes: [
{
value: '0785434125',
attributeType: {
uuid: '14d4f066-15f5-102d-96e4-000c29c2a5d7',
display: 'Telephone Number',
},
},
],
},
{
patientId: 42,
uuid: 'a83747aa-3041-489a-a112-1c024582c83d',
identifiers: [
{
identifier: '100016H',
identifierType: {
uuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
display: 'OpenMRS ID',
},
},
],
display: '100016H - Joseph Davis',
patientIdentifier: {
uuid: '0ac0a9a0-b040-4c0a-9c35-c4e0bb52a570',
identifier: '100016H',
},
person: {
gender: 'M',
age: 30,
birthdate: '1994-10-13T00:00:00.000+0000',
birthdateEstimated: false,
personName: {
display: 'Joseph Davis',
givenName: 'Joseph',
familyName: 'Davis',
},
addresses: [
{
address1: 'Address19050',
cityVillage: 'City9050',
stateProvince: 'State9050',
country: 'Country9050',
postalCode: '46548',
preferred: true,
},
],
dead: false,
deathDate: null,
},
attributes: [
{
value: {
uuid: '1ce1b7d4-c865-4178-82b0-5932e51503d6',
display: 'Community Outreach',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/location/1ce1b7d4-c865-4178-82b0-5932e51503d6',
resourceAlias: 'location',
},
],
},
attributeType: {
uuid: '8d87236c-c2cc-11de-8d13-0010c6dffd0f',
display: 'Health Center',
},
},
],
},
];
180 changes: 180 additions & 0 deletions packages/esm-patient-search-app/src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { Type, validators } from '@openmrs/esm-framework';

export type BuiltInFieldType = 'gender' | 'dateOfBirth' | 'age' | 'postcode';

export interface PersonAttributeFieldConfig {
attributeTypeUuid: string;
label?: string;
placeholder?: string;
answerConceptSetUuid?: string;
customConceptAnswers?: Array<{ uuid: string; label?: string }>;
locationTag?: string;
}

export interface BuiltInFieldConfig {
enabled: boolean;
label?: string;
min?: number;
max?: number;
}

export interface BuiltInFields {
gender: BuiltInFieldConfig;
dateOfBirth: BuiltInFieldConfig;
age: BuiltInFieldConfig & { min?: number };
postcode: BuiltInFieldConfig;
}

export const configSchema = {
search: {
patientChartUrl: {
Expand All @@ -21,6 +46,157 @@ export const configSchema = {
_description:
'Disable the default "keyup search" for instant patient search as typing concludes on tablet devices',
},
searchFields: {
_type: Type.Object,
_description: 'Configuration for advanced search fields',
_default: {
fields: {
gender: {
enabled: true,
label: 'Sex',
},
dateOfBirth: {
enabled: true,
label: 'Date of Birth',
},
age: {
enabled: true,
label: 'Age',
min: 0,
},
postcode: {
enabled: true,
label: 'Postcode',
},
},
personAttributes: [
{
label: 'Phone Number',
attributeTypeUuid: '14d4f066-15f5-102d-96e4-000c29c2a5d7',
},
],
},
fields: {
_type: Type.Object,
_description: 'Configuration for built-in search fields',
gender: {
_type: Type.Object,
_description: 'Configuration for gender field',
enabled: {
_type: Type.Boolean,
_description: 'Optional. If true, determines whether to display the gender field or not. Defaults to true',
_default: true,
},
label: {
_type: Type.String,
_description: 'The label text for the gender field',
_default: 'Sex',
},
},
dateOfBirth: {
_type: Type.Object,
_description: 'Configuration for the date of birth field',
enabled: {
_type: Type.Boolean,
_description:
'Optional. If true, determines whether to display the date of birth field or not. Defaults to true',
_default: true,
},
label: {
_type: Type.String,
_description: 'The label text for date of birth field',
_default: 'Date of Birth',
},
},
age: {
_type: Type.Object,
_description: 'Configuration for the age field',
enabled: {
_type: Type.Boolean,
_description: 'Optional. If true, determines whether to display the age field or not. Defaults to true',
_default: true,
},
label: {
_type: Type.String,
_description: 'The label text for the age field',
_default: 'Age',
},
min: {
_type: Type.Number,
_description: 'The minimum value for the age field',
_default: 0,
},
max: {
_type: Type.Number,
_description: 'The maximum value for the age field',
_default: 0,
},
},
postcode: {
_type: Type.Object,
_description: 'Configuration for the postcode field',
enabled: {
_type: Type.Boolean,
_description:
'Optional. If true, determines whether to display the postcode field or not. Defaults to true',
_default: true,
},
label: {
_type: Type.String,
_description: 'The label text for the postcode field',
_default: 'Postcode',
},
},
},
personAttributes: {
_type: Type.Array,
_description: 'Configuration for person attributes to display on advanced search',
_elements: {
_type: Type.Object,
label: {
_type: Type.String,
_description: 'The label text for the field',
},
placeholder: {
_type: Type.String,
_description: 'Placeholder text for the field',
_default: '',
},
attributeTypeUuid: {
_type: Type.UUID,
_description: 'UUID of the person attribute type',
},
answerConceptSetUuid: {
_type: Type.ConceptUuid,
_default: null,
_description:
'For coded questions only. A concept which has the possible responses either as answers or as set members.',
},
customConceptAnswers: {
_type: Type.Array,
_default: [],
_elements: {
_type: Type.Object,
uuid: {
_type: Type.UUID,
_description: 'Answer concept UUID',
},
label: {
_type: Type.String,
_default: null,
_description: 'The custom label for the answer concept.',
},
},
},
locationTag: {
_type: Type.String,
_default: null,
_description:
'Only for fields with "person attribute" type `org.openmrs.Location`. This filters the list of location options in the dropdown based on their location tag.',
},
},
},
},
},
includeDead: {
_type: Type.Boolean,
Expand Down Expand Up @@ -58,6 +234,10 @@ export type PatientSearchConfig = {
disableTabletSearchOnKeyUp: boolean;
patientChartUrl: string;
showRecentlySearchedPatients: boolean;
searchFields: {
fields: BuiltInFields;
personAttributes: Array<PersonAttributeFieldConfig>;
};
};
contactAttributeType: Array<string>;
defaultIdentifier: string;
Expand Down
Loading