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

mark fields in the lab result form as required #37

Merged
merged 2 commits into from
Jan 17, 2024
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
20 changes: 19 additions & 1 deletion src/results/result-form-field.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ interface ResultFormFieldProps {
concept: ConceptReference;
control: any;
register: any;
errors: any;
}
const ResultFormField: React.FC<ResultFormFieldProps> = ({
concept,
control,
register,
errors,
}) => {
const { t } = useTranslation();
const isTextOrNumeric = (concept) =>
Expand All @@ -24,9 +25,15 @@ const ResultFormField: React.FC<ResultFormFieldProps> = ({

return (
<>
{Object.keys(errors).length > 0 && (
<div className={styles.errorDiv}>All fields are required</div>
Copy link
Member

Choose a reason for hiding this comment

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

Can this be driven by some sort of configuration? This seems like something that might not be the case for every scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kindly give an example? what kind of configuration?

)}
{isTextOrNumeric(concept) && (
<Controller
control={control}
rules={{
required: true,
}}
name={concept.uuid}
render={({ field }) => (
<TextInput
Expand All @@ -40,17 +47,22 @@ const ResultFormField: React.FC<ResultFormFieldProps> = ({
)}
/>
)}

{isCoded(concept) && (
<Controller
name={concept.uuid}
control={control}
rules={{
required: true,
}}
render={({ field }) => (
<Select
key={concept.uuid}
className={styles.textInput}
{...field}
type="text"
labelText={concept?.display}
rules={{ required: true }}
>
<SelectItem text={t("option", "Choose an Option")} value="" />

Expand All @@ -75,6 +87,9 @@ const ResultFormField: React.FC<ResultFormFieldProps> = ({
<Controller
control={control}
name={member.uuid}
rules={{
required: true,
}}
render={({ field }) => (
<TextInput
key={member.uuid}
Expand All @@ -96,6 +111,9 @@ const ResultFormField: React.FC<ResultFormFieldProps> = ({
<Controller
name={member.uuid}
control={control}
rules={{
required: true,
}}
render={({ field }) => (
<Select
key={member.uuid}
Expand Down
24 changes: 13 additions & 11 deletions src/results/result-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const ResultForm: React.FC<ResultFormProps> = ({ order, patientUuid }) => {
const {
control,
register,
formState: { isSubmitting },
formState: { isSubmitting, errors },
getValues,
handleSubmit,
} = useForm<{ testResult: string }>({
defaultValues: {},
});
Expand All @@ -52,7 +53,7 @@ const ResultForm: React.FC<ResultFormProps> = ({ order, patientUuid }) => {
return <div>Loading test details</div>;
}

const handleSubmit = (e) => {
const onSubmit = (data, e) => {
e.preventDefault();
// assign result to test order
const documentedValues = getValues();
Expand Down Expand Up @@ -168,16 +169,17 @@ const ResultForm: React.FC<ResultFormProps> = ({ order, patientUuid }) => {
<ExtensionSlot name="patient-header-slot" state={bannerState} />
)}
{/* // we need to display test name for test panels */}
{concept.setMembers.length > 0 && (
<div>Test panel: {concept.display}</div>
)}
{concept.setMembers.length > 0 && <div>{concept.display}</div>}
{concept && (
<section className={styles.section}>
<ResultFormField
register={register}
concept={concept}
control={control}
/>
<form>
<ResultFormField
register={register}
concept={concept}
control={control}
errors={errors}
/>
</form>
</section>
)}
</ModalBody>
Expand All @@ -190,7 +192,7 @@ const ResultForm: React.FC<ResultFormProps> = ({ order, patientUuid }) => {
>
{t("cancel", "Cancel")}
</Button>
<Button onClick={handleSubmit}>Save test results</Button>
<Button onClick={handleSubmit(onSubmit)}>Save test results</Button>
</ModalFooter>
</div>
</>
Expand Down
4 changes: 4 additions & 0 deletions src/results/result-form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ section {

.textInput {
margin: 5px;
}

.errorDiv {
color: red;
}
Loading