Skip to content

Commit

Permalink
mark fields in the lab result form as required (#37)
Browse files Browse the repository at this point in the history
* mark fields in the lab result form as required

* mend
  • Loading branch information
ojwanganto authored Jan 17, 2024
1 parent e4efcd4 commit e14f4c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
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>
)}
{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;
}

0 comments on commit e14f4c4

Please sign in to comment.