EDTF.JS
function SentenceItem(props: {
readOnly?: boolean;
prefix?: string;
firstItem?: boolean;
default: string;
value: string;
}) {
if (props.readOnly && !props.value) return null;
return (
<>
{!props.firstItem ? ' ' : false}
{props.prefix ? `${props.prefix} ` : false}
<span className={styles.item}>{props.value ? props.value : props.default}</span>
</>
);
}
function SentenceBuild(props: {
form: FormHook<EditMedicationForm.EditMedicationFormStructure>;
fieldPath: EditMedicationForm.InstructionFields;
defaultValue: string;
useDefaultValue: boolean;
const instruction = props.form.values[props.fieldPath];
if (!isDosageTimesInstruction(instruction)) return null;
const instructions = instruction.instructions;
const routeOfAdministration = instruction.routeOfAdministration;
const times = instruction.times;
const startsOn = moment(instruction.startsOn, ValidDateFormats.NodeDateTimeTimezone);
let showStartsOn = false;
if (startsOn && startsOn.isValid()) {
showStartsOn = moment().endOf('day').isBefore(startsOn, 'day');
if (props.useDefaultValue && props.defaultValue)
<div data-test-id={'sentence-builder'} className={styles.sentenceBuilder}>
{capitalizeFirstLetter(props.defaultValue)}
</div>
<SentenceItem
firstItem
value={instructions === '' ? '' : capitalizeFirstLetter(instructions)}
default='[Administration dosage instructions]'
/>
prefix='via'
readOnly={props.readOnly}
value={routeOfAdministration?.name?.toLowerCase() ?? ''}
default='[route of administration]'
prefix='at'
value={times.length ? times.join(', ') : ''}
default='[time]'
{showStartsOn && (
prefix='starting on'
value={moment(startsOn).format(ValidDateFormats.Edit)}
default='[date]'
)}
EDSF.JS
export const EditDurationSelectorField: React.FC<{
medicationStatus: MedicationStatus;
shortCourseDefaults: boolean;
setShortCourseDefaults: (setDefaults: boolean) => void;
}> = props => {
const medicationSettings = useMedicationSettings();
const expiresOnField = useField({ form: props.form, field: 'expiresOn' });
const performedOnField = useField({ form: props.form, field: 'performedOn' });
const expiresOnMoment = expiresOnField.value
? moment(expiresOnField.value, ValidDateFormats.Edit).clone().endOf('day')
: null;
const performedOnMoment = performedDate(performedOnField.value, ValidDateFormats.Edit);
There are two components startsOn value send to performedOnMoment=startson value