Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-management into patient-registration
  • Loading branch information
ayush-AI committed Jul 19, 2023
2 parents 6e1c2a9 + 2234a56 commit 5518fa5
Show file tree
Hide file tree
Showing 21 changed files with 232 additions and 74 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "4.5.0",
"version": "5.0.0",
"command": {
"publish": {
"verifyAccess": false
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-active-visits-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openmrs/esm-active-visits-app",
"version": "4.5.0",
"version": "5.0.0",
"description": "Active visits widget microfrontend for the OpenMRS SPA",
"browser": "dist/openmrs-esm-active-visits-app.js",
"main": "src/index.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ interface VisitResponse {
export function useActiveVisits() {
const session = useSession();
const config = useConfig();
const startDate = dayjs().format('YYYY-MM-DD');
const sessionLocation = session?.sessionLocation?.uuid;

const customRepresentation =
Expand All @@ -49,7 +48,7 @@ export function useActiveVisits() {
return null;
}

let url = `/ws/rest/v1/visit?includeInactive=false&v=${customRepresentation}&totalCount=true&fromStartDate=${startDate}&location=${sessionLocation}`;
let url = `/ws/rest/v1/visit?includeInactive=false&v=${customRepresentation}&totalCount=true&location=${sessionLocation}`;

if (pageIndex) {
url += `&startIndex=${pageIndex * 50}`;
Expand Down Expand Up @@ -88,19 +87,19 @@ export function useActiveVisits() {
visitUuid: visit.uuid,
};

//in case no configuration is given the previsous behavior remanes the same
//in case no configuration is given the previous behavior remains the same
if (!config?.activeVisits?.identifiers) {
activeVisits.idNumber = visit?.patient?.identifiers[0].identifier;
activeVisits.idNumber = visit?.patient?.identifiers[0]?.identifier ?? '--';
} else {
//map identifires on config
//map identifiers on config
config?.activeVisits?.identifiers?.map((configIdentifier) => {
//check if in the current visit the patient has in his identifiers the current identifierType name
const visitIdentifier = visit?.patient?.identifiers.find(
(visitIdentifier) => visitIdentifier?.identifierType?.name === configIdentifier?.identifierName,
);

//add the new identifier or rewrite existing one to activeVisit object
//the parameter will corresponde to the name of the key value of the configuration
//the parameter will corresponds to the name of the key value of the configuration
//and the respective value is the visit identifier
//If there isn't a identifier we display this default text '--'
activeVisits[configIdentifier.header?.key] = visitIdentifier?.identifier ?? '--';
Expand All @@ -115,7 +114,7 @@ export function useActiveVisits() {
);

//add the new attribute or rewrite existing one to activeVisit object
//the parameter will corresponde to the name of the key value of the configuration
//the parameter will correspond to the name of the key value of the configuration
//and the respective value is the persons value
//If there isn't a attribute we display this default text '--'
activeVisits[header?.key] = personAttributes?.value ?? '--';
Expand All @@ -125,12 +124,7 @@ export function useActiveVisits() {
};

const formattedActiveVisits: Array<ActiveVisit> = data
? [].concat(
...data?.map(
(res) => res?.data?.results?.map(mapVisitProperties),
// ?.filter(({ visitStartTime }) => dayjs(visitStartTime).isToday()),
),
)
? [].concat(...data?.map((res) => res?.data?.results?.map(mapVisitProperties)))
: [];

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-appointments-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openmrs/esm-appointments-app",
"version": "4.5.0",
"version": "5.0.0",
"description": "Appointments front-end module for the OpenMRS SPA",
"browser": "dist/openmrs-esm-appointments-app.js",
"main": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-outpatient-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openmrs/esm-outpatient-app",
"version": "4.5.0",
"version": "5.0.0",
"description": "Outpatient front-end module for the OpenMRS SPA",
"browser": "dist/openmrs-esm-outpatient-app.js",
"main": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-list-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openmrs/esm-patient-list-app",
"version": "4.5.0",
"version": "5.0.0",
"description": "Patient list microfrontend for the OpenMRS SPA",
"browser": "dist/openmrs-esm-patient-list-app.js",
"main": "src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-registration-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openmrs/esm-patient-registration-app",
"version": "4.5.0",
"version": "5.0.0",
"description": "Patient registration microfrontend for the OpenMRS SPA",
"browser": "dist/openmrs-esm-patient-registration-app.js",
"main": "src/index.ts",
Expand Down
16 changes: 11 additions & 5 deletions packages/esm-patient-registration-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface RegistrationConfig {
fieldConfigurations: {
name: {
displayMiddleName: boolean;
unidentifiedPatient: boolean;
allowUnidentifiedPatients: boolean;
defaultUnknownGivenName: string;
defaultUnknownFamilyName: string;
displayCapturePhoto: boolean;
Expand All @@ -52,6 +52,7 @@ export interface RegistrationConfig {
};
};
dateOfBirth: {
allowEstimatedDateOfBirth: boolean;
useEstimatedDateOfBirth: {
enabled: boolean;
dayOfMonth: number;
Expand Down Expand Up @@ -201,10 +202,10 @@ export const esmPatientRegistrationSchema = {
fieldConfigurations: {
name: {
displayMiddleName: { _type: Type.Boolean, _default: true },
unidentifiedPatient: {
allowUnidentifiedPatients: {
_type: Type.Boolean,
_default: true,
_description: 'Whether to allow patients to be registered without names.',
_description: 'Whether to allow registering unidentified patients.',
},
defaultUnknownGivenName: {
_type: Type.String,
Expand Down Expand Up @@ -296,10 +297,15 @@ export const esmPatientRegistrationSchema = {
},
},
dateOfBirth: {
allowEstimatedDateOfBirth: {
_type: Type.Boolean,
_description: 'Whether to allow estimated date of birth for a patient during registration',
_default: true,
},
useEstimatedDateOfBirth: {
enabled: {
_type: Type.Boolean,
_description: 'Whether to use custom day and month for estimated date of birth',
_description: 'Whether to use a fixed day and month for estimated date of birth',
_default: false,
},
dayOfMonth: {
Expand All @@ -309,7 +315,7 @@ export const esmPatientRegistrationSchema = {
},
month: {
_type: Type.Number,
_description: 'The custom month to use on the estimated date of birth i.e 0 = Jan 11 = Dec',
_description: 'The custom month to use on the estimated date of birth i.e 0 = Jan & 11 = Dec',
_default: 0,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const DobField: React.FC = () => {
const { t } = useTranslation();
const {
fieldConfigurations: { dateOfBirth },
} = useConfig() as RegistrationConfig;
const [dobUnknown] = useField('birthdateEstimated');
const dobKnown = !dobUnknown.value;
} = useConfig<RegistrationConfig>();
const allowEstimatedBirthDate = dateOfBirth?.allowEstimatedDateOfBirth;
const [{ value: dobUnknown }] = useField('birthdateEstimated');
const [birthdate, birthdateMeta] = useField('birthdate');
const [yearsEstimated, yearsEstimateMeta] = useField('yearsEstimated');
const [monthsEstimated, monthsEstimateMeta] = useField('monthsEstimated');
Expand Down Expand Up @@ -75,17 +75,19 @@ export const DobField: React.FC = () => {
return (
<div className={styles.halfWidthInDesktopView}>
<h4 className={styles.productiveHeading02Light}>{t('birthFieldLabelText', 'Birth')}</h4>
<div className={styles.dobField}>
<div className={styles.dobContentSwitcherLabel}>
<span className={styles.label01}>{t('dobToggleLabelText', 'Date of Birth Known?')}</span>
{(allowEstimatedBirthDate || dobUnknown) && (
<div className={styles.dobField}>
<div className={styles.dobContentSwitcherLabel}>
<span className={styles.label01}>{t('dobToggleLabelText', 'Date of Birth Known?')}</span>
</div>
<ContentSwitcher onChange={onToggle} selectedIndex={dobUnknown ? 1 : 0}>
<Switch name="known" text={t('yes', 'Yes')} />
<Switch name="unknown" text={t('no', 'No')} />
</ContentSwitcher>
</div>
<ContentSwitcher onChange={onToggle}>
<Switch name="known" text={t('yes', 'Yes')} />
<Switch name="unknown" text={t('no', 'No')} />
</ContentSwitcher>
</div>
)}
<Layer>
{dobKnown ? (
{!dobUnknown ? (
<div className={styles.dobField}>
<DatePicker dateFormat={dateFormat} datePickerType="single" onChange={onDateChange} maxDate={format(today)}>
<DatePickerInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ jest.mock('@openmrs/esm-framework', () => {
return {
...originalModule,
useConfig: jest.fn().mockImplementation(() => ({
fieldConfigurations: { dateOfBirth: { useEstimatedDateOfBirth: { enabled: true, dayOfMonth: 0, month: 0 } } },
fieldConfigurations: {
dateOfBirth: {
allowEstimatedDateOfBirth: true,
useEstimatedDateOfBirth: { enabled: true, dayOfMonth: 0, month: 0 },
},
},
})),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PatientRegistrationContext } from '../../patient-registration-context';
import styles from '../field.scss';
import { RegistrationConfig } from '../../../config-schema';

export const unidentifiedPatientAttributeTypeUuid = '8b56eac7-5c76-4b9c-8c6f-1deab8d3fc47';
const containsNoNumbers = /^([^0-9]*)$/;

function checkNumber(value: string) {
Expand All @@ -19,17 +20,26 @@ function checkNumber(value: string) {
}

export const NameField = () => {
const { t } = useTranslation();
const { setCapturePhotoProps, currentPhoto, setFieldValue } = useContext(PatientRegistrationContext);
const {
fieldConfigurations: {
name: { displayCapturePhoto, displayReverseFieldOrder },
name: {
displayCapturePhoto,
allowUnidentifiedPatients,
defaultUnknownGivenName,
defaultUnknownFamilyName,
displayMiddleName,
displayReverseFieldOrder,
},
},
} = useConfig() as RegistrationConfig;
const { t } = useTranslation();
const { setCapturePhotoProps, currentPhoto, setFieldValue } = useContext(PatientRegistrationContext);
const { fieldConfigurations } = useConfig();
const fieldConfigs = fieldConfigurations?.name;
const [{ value: unidentified }] = useField('unidentifiedPatient');
const nameKnown = !unidentified;
} = useConfig<RegistrationConfig>();

const [{ value: isPatientUnknownValue }, , { setValue: setUnknownPatient }] = useField<string>(
`attributes.${unidentifiedPatientAttributeTypeUuid}`,
);

const isPatientUnknown = isPatientUnknownValue === 'true';

const onCapturePhoto = useCallback(
(dataUri: string, photoDateTime: string) => {
Expand All @@ -47,11 +57,11 @@ export const NameField = () => {
if (e.name === 'known') {
setFieldValue('givenName', '');
setFieldValue('familyName', '');
setFieldValue('unidentifiedPatient', false);
setUnknownPatient('false');
} else {
setFieldValue('givenName', fieldConfigs.defaultUnknownGivenName);
setFieldValue('familyName', fieldConfigs.defaultUnknownFamilyName);
setFieldValue('unidentifiedPatient', true);
setFieldValue('givenName', defaultUnknownGivenName);
setFieldValue('familyName', defaultUnknownFamilyName);
setUnknownPatient('true');
}
};

Expand All @@ -65,7 +75,7 @@ export const NameField = () => {
/>
);

const middleNameField = fieldConfigs.displayMiddleName && (
const middleNameField = displayMiddleName && (
<Input
id="middleName"
name="middleName"
Expand Down Expand Up @@ -97,14 +107,21 @@ export const NameField = () => {
)}

<div className={styles.nameField}>
<div className={styles.dobContentSwitcherLabel}>
<span className={styles.label01}>{t('patientNameKnown', "Patient's Name is Known?")}</span>
</div>
<ContentSwitcher className={styles.contentSwitcher} onChange={toggleNameKnown}>
<Switch name="known" text={t('yes', 'Yes')} />
<Switch name="unknown" text={t('no', 'No')} />
</ContentSwitcher>
{nameKnown &&
{(allowUnidentifiedPatients || isPatientUnknown) && (
<>
<div className={styles.dobContentSwitcherLabel}>
<span className={styles.label01}>{t('patientNameKnown', "Patient's Name is Known?")}</span>
</div>
<ContentSwitcher
className={styles.contentSwitcher}
selectedIndex={isPatientUnknown ? 1 : 0}
onChange={toggleNameKnown}>
<Switch name="known" text={t('yes', 'Yes')} />
<Switch name="unknown" text={t('no', 'No')} />
</ContentSwitcher>
</>
)}
{!isPatientUnknown &&
(!displayReverseFieldOrder ? (
<>
{firstNameField}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const formValues: FormValues = {
givenName: '',
middleName: '',
familyName: '',
unidentifiedPatient: false,
additionalGivenName: '',
additionalMiddleName: '',
additionalFamilyName: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,6 @@ export class FormManager {
}
}

if (values.unidentifiedPatient) {
attributes.push({
// The UUID of the 'Unknown Patient' attribute-type will always be static across all implementations of OpenMRS
attributeType: '8b56eac7-5c76-4b9c-8c6f-1deab8d3fc47',
value: 'true',
});
}

return attributes;
}

Expand Down
Loading

0 comments on commit 5518fa5

Please sign in to comment.