-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Add configurable ability to print multiple stickers on the sam…
…e page
- Loading branch information
1 parent
5e7a458
commit 56cfd5b
Showing
15 changed files
with
391 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ges/esm-patient-banner-app/src/banner-tags/print-identifier-sticker-content.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react'; | ||
import { useConfig } from '@openmrs/esm-framework'; | ||
import { type ConfigObject } from '../config-schema'; | ||
import IdentifierSticker from './print-identifier-sticker.component'; | ||
import styles from './print-identifier-sticker-content.scss'; | ||
|
||
interface PrintIdentifierStickerContentProps { | ||
labels: Array<{}>; | ||
numberOfLabelColumns: number; | ||
numberOfLabelRowsPerPage: number; | ||
patient: fhir.Patient; | ||
} | ||
|
||
const PrintIdentifierStickerContent = forwardRef<HTMLDivElement, PrintIdentifierStickerContentProps>( | ||
({ labels, numberOfLabelColumns, numberOfLabelRowsPerPage, patient }, ref) => { | ||
const { printIdentifierStickerWidth, printIdentifierStickerHeight, printIdentifierStickerPaperSize } = | ||
useConfig<ConfigObject>(); | ||
const divRef = useRef<HTMLDivElement>(); | ||
|
||
useImperativeHandle(ref, () => divRef.current, []); | ||
|
||
useEffect(() => { | ||
if (divRef.current) { | ||
const style = divRef.current.style; | ||
style.setProperty('--omrs-print-label-paper-size', printIdentifierStickerPaperSize); | ||
style.setProperty('--omrs-print-label-colums', numberOfLabelColumns.toString()); | ||
style.setProperty('--omrs-print-label-rows', numberOfLabelRowsPerPage.toString()); | ||
style.setProperty('--omrs-print-label-sticker-height', printIdentifierStickerHeight); | ||
style.setProperty('--omrs-print-label-sticker-width', printIdentifierStickerWidth); | ||
} | ||
}, [ | ||
numberOfLabelColumns, | ||
numberOfLabelRowsPerPage, | ||
printIdentifierStickerHeight, | ||
printIdentifierStickerPaperSize, | ||
printIdentifierStickerWidth, | ||
]); | ||
|
||
const maxLabelsPerPage = numberOfLabelRowsPerPage * numberOfLabelColumns; | ||
const pages: Array<typeof labels> = []; | ||
|
||
for (let i = 0; i < labels.length; i += maxLabelsPerPage) { | ||
pages.push(labels.slice(i, i + maxLabelsPerPage)); | ||
} | ||
|
||
if (numberOfLabelColumns < 1 || numberOfLabelRowsPerPage < 1 || labels.length < 1) { | ||
return; | ||
} | ||
|
||
return ( | ||
<div ref={divRef} className={styles.printRoot}> | ||
{pages.map((pageLabels, pageIndex) => ( | ||
<div key={pageIndex} className={pageIndex < pages.length - 1 ? styles.pageBreak : ''}> | ||
<div className={styles.labelsContainer}> | ||
{pageLabels.map((label, index) => ( | ||
<div key={index} className={styles.printContainer}> | ||
<IdentifierSticker patient={patient} /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
export default PrintIdentifierStickerContent; |
41 changes: 41 additions & 0 deletions
41
packages/esm-patient-banner-app/src/banner-tags/print-identifier-sticker-content.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@use '@carbon/layout'; | ||
@use '@carbon/type'; | ||
@use '@openmrs/esm-styleguide/src/vars' as *; | ||
|
||
.printRoot { | ||
@media print { | ||
@page { | ||
size: var(--omrs-print-label-paper-size, auto); | ||
} | ||
|
||
html, | ||
body { | ||
height: initial !important; | ||
overflow: initial !important; | ||
background-color: white; | ||
} | ||
} | ||
|
||
.labelsContainer { | ||
grid-template-columns: repeat(var(--omrs-print-label-colums, 1), 1fr); | ||
grid-template-rows: repeat(var(--omrs-print-label-rows, 1), auto); | ||
} | ||
} | ||
|
||
.printContainer { | ||
height: var(--omrs-print-label-sticker-height, 11rem); | ||
width: var(--omrs-print-label-sticker-width, 13rem); | ||
background-color: $ui-01; | ||
} | ||
|
||
.pageBreak { | ||
page-break-after: always; | ||
} | ||
|
||
.labelsContainer { | ||
display: grid; | ||
column-gap: 1.3rem; | ||
row-gap: 1rem; | ||
place-items: center; | ||
background-color: white; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/esm-patient-banner-app/src/banner-tags/print-identifier-sticker.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { forwardRef, useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { age, getPatientName, useConfig, getCoreTranslation } from '@openmrs/esm-framework'; | ||
import { type ConfigObject } from '../config-schema'; | ||
import styles from './print-identifier-sticker.scss'; | ||
|
||
interface IdentifierStickerProps { | ||
patient: fhir.Patient; | ||
} | ||
|
||
const getGender = (gender: string): string => { | ||
switch (gender) { | ||
case 'male': | ||
return getCoreTranslation('male', 'Male'); | ||
case 'female': | ||
return getCoreTranslation('female', 'Female'); | ||
case 'other': | ||
return getCoreTranslation('other', 'Other'); | ||
case 'unknown': | ||
return getCoreTranslation('unknown', 'Unknown'); | ||
default: | ||
return gender; | ||
} | ||
}; | ||
|
||
const IdentifierSticker = forwardRef<HTMLDivElement, IdentifierStickerProps>(({ patient }, ref) => { | ||
const { t } = useTranslation(); | ||
const { printIdentifierStickerFields, excludePatientIdentifierCodeTypes } = useConfig<ConfigObject>(); | ||
|
||
const patientDetails = useMemo(() => { | ||
if (!patient) { | ||
return {}; | ||
} | ||
|
||
const identifiers = | ||
patient.identifier?.filter( | ||
(identifier) => !excludePatientIdentifierCodeTypes?.uuids.includes(identifier.type.coding[0].code), | ||
) ?? []; | ||
|
||
return { | ||
address: patient.address, | ||
age: age(patient.birthDate), | ||
dateOfBirth: patient.birthDate, | ||
gender: getGender(patient.gender), | ||
id: patient.id, | ||
identifiers: [...identifiers], | ||
name: patient ? getPatientName(patient) : '', | ||
photo: patient.photo, | ||
}; | ||
}, [excludePatientIdentifierCodeTypes?.uuids, patient]); | ||
|
||
return ( | ||
<div ref={ref} className={styles.stickerContainer}> | ||
{printIdentifierStickerFields.includes('name') && <div className={styles.patientName}>{patientDetails.name}</div>} | ||
{patientDetails.identifiers.map((identifier) => { | ||
return ( | ||
<p key={identifier?.id}> | ||
{identifier?.type?.text}: <span className="patient-identifier">{identifier?.value}</span> | ||
</p> | ||
); | ||
})} | ||
<p> | ||
{getCoreTranslation('sex', 'Sex')}: <span className="patient-gender">{patientDetails.gender}</span> | ||
</p> | ||
<p> | ||
{t('dob', 'DOB')}: <span className="patient-dob">{patientDetails.dateOfBirth}</span> | ||
</p> | ||
<p> | ||
{getCoreTranslation('age', 'Age')}: <span className="patient-age">{patientDetails.age}</span> | ||
</p> | ||
</div> | ||
); | ||
}); | ||
|
||
export default IdentifierSticker; |
Oops, something went wrong.