Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Mar 1, 2024
1 parent a79ce1a commit 7fd3e2b
Show file tree
Hide file tree
Showing 21 changed files with 568 additions and 731 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'class-validator'

import { exampleTestElement } from 'src/domain'
import { TestElementNormalRuleDto } from './normal-rule.dto'
import { TestElementTestElementNormalRuleDto } from './normal-rule.dto'

export class TestElementCreateRequestDto {
@Expose()
Expand Down Expand Up @@ -53,12 +53,12 @@ export class TestElementCreateRequestDto {
@Expose()
@ApiProperty({
...exampleTestElement.normalRules,
type: () => TestElementNormalRuleDto,
type: () => TestElementTestElementNormalRuleDto,
})
@IsArray()
@ValidateNested({ each: true })
@Type(() => TestElementNormalRuleDto)
normalRules: TestElementNormalRuleDto[]
@Type(() => TestElementTestElementNormalRuleDto)
normalRules: TestElementTestElementNormalRuleDto[]

@Expose()
@ApiProperty(exampleTestElement.testId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

import { exampleNormalRule } from 'src/domain'

export class TestElementNormalRuleDto {
export class TestElementTestElementNormalRuleDto {
@Expose()
@ApiProperty(exampleNormalRule.category)
@IsEnum(PatientCategory)
Expand Down
26 changes: 19 additions & 7 deletions apps/hcdc-web-app/src/components/form/FormAutocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type FormAutocompleteProps<
getOptionValue: (option: OptionType) => unknown

disableError?: boolean
multiple?: boolean
groupBy?: AutocompleteProps<
OptionType,
undefined,
Expand All @@ -30,7 +31,7 @@ export type FormAutocompleteProps<

export function FormAutocomplete<
TFieldValues extends FieldValues = FieldValues,
OptionType = any,
OptionType = unknown,
>({
name,
label,
Expand All @@ -39,6 +40,7 @@ export function FormAutocomplete<
getOptionLabel,
getOptionValue,
groupBy,
multiple = false,
disableError = false,
}: FormAutocompleteProps<TFieldValues, OptionType>) {
return (
Expand All @@ -56,18 +58,28 @@ export function FormAutocomplete<
return (
<Autocomplete
fullWidth
multiple
multiple={multiple}
filterSelectedOptions={!!multiple}
options={options}
groupBy={groupBy}
PopperComponent={StyledPopper}
getOptionLabel={getOptionLabel}
onChange={(event, value, reason) => {
onChange(value.map(getOptionValue))
if (value) {
if (Array.isArray(value)) {
onChange(value.map(getOptionValue))
} else {
onChange(getOptionValue(value))
}
}
}}
value={options.filter((option) =>
value?.includes(getOptionValue(option)),
)}
filterSelectedOptions
value={
multiple === true
? options.filter((option) =>
value?.includes(getOptionValue(option)),
)
: options.find((option) => getOptionValue(option) === value)
}
renderInput={(params) => (
<TextField
{...params}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BioProductResponseDto } from 'src/infra/api/access-service/bio-product'
import { TestResultDto } from 'src/infra/api/access-service/sample'
import { TestCategoryResponseDto } from 'src/infra/api/access-service/test-category'
import {
HighlightRuleDto,
TestElementNormalRuleDto,
TestElementResponseDto,
} from 'src/infra/api/access-service/test-element'
import { UserResponseDto } from 'src/infra/api/access-service/user'
Expand Down Expand Up @@ -37,6 +37,8 @@ export interface ResultCardProps {
elementId: string,
{ checked, value }: { checked?: boolean; value?: string },
) => void
getHighlightRule: (highlightRules: HighlightRuleDto[]) => HighlightRuleDto
getHighlightRule: (
highlightRules: TestElementNormalRuleDto[],
) => TestElementNormalRuleDto
sampleId: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { merge } from 'lodash'
import { useSampleUpdateByIdMutation } from 'src/infra/api/access-service/sample'
import { TestResponseDto } from 'src/infra/api/access-service/test'
import {
HighlightRuleDto,
TestElementNormalRuleDto,
TestElementResponseDto,
useLazyTestElementSearchQuery,
} from 'src/infra/api/access-service/test-element'
Expand Down Expand Up @@ -65,13 +65,13 @@ export default function EditResultPage() {
}, [sampleId])

const getHighlightRule = useCallback(
(highlightRules: HighlightRuleDto[]) => {
(highlightRules: TestElementNormalRuleDto[]) => {
return (
highlightRules.find(({ category }) => category === patientCategory) ??
highlightRules.find(
({ category }) => category === PatientCategory.Any,
) ??
({} as HighlightRuleDto)
({} as TestElementNormalRuleDto)
)
},
[patientCategory],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { PatientCategory } from '@diut/hcdc'
import { HighlightRuleDto } from 'src/infra/api/access-service/test-element'
import { TestElementNormalRuleDto } from 'src/infra/api/access-service/test-element'

export function getTechnicalHint(
patientCategory: PatientCategory,
highlightRules: HighlightRuleDto[],
highlightRules: TestElementNormalRuleDto[],
) {
const highlightRule =
highlightRules.find(({ category }) => category === patientCategory) ??
highlightRules.find(({ category }) => category === PatientCategory.Any) ??
({} as HighlightRuleDto)
({} as TestElementNormalRuleDto)

const { min, max, normalValue, description, category } = highlightRule

Expand Down Expand Up @@ -49,7 +49,10 @@ export function getTechnicalHint(
return ''
}

export function checkHighlight(highlightRule: HighlightRuleDto, value: string) {
export function checkHighlight(
highlightRule: TestElementNormalRuleDto,
value: string,
) {
const { min, max, normalValue } = highlightRule

if (min != undefined && max != undefined) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { PatientCategory, PatientCategoryValues } from '@diut/hcdc'
import { GridColDef } from '@mui/x-data-grid'

import { TestElementNormalRuleDto } from 'src/infra/api/access-service/test-element'

const patientCategoryDisplayText = {
[PatientCategory.Any]: 'Tất cả',
[PatientCategory.YoungMale]: 'Bé trai',
[PatientCategory.YoungFemale]: 'Bé gái',
[PatientCategory.MatureMale]: 'Nam',
[PatientCategory.MatureFemale]: 'Nữ',
[PatientCategory.Pregnant]: 'Thai phụ',
}

export type TestElementNormalRuleDtoWithId = TestElementNormalRuleDto & {
id: string
}

export const normalRuleColumns: GridColDef<TestElementNormalRuleDtoWithId>[] = [
{
field: 'category',
headerName: 'Phân loại',
type: 'singleSelect',
minWidth: 150,
sortable: false,
editable: true,
valueOptions: PatientCategoryValues.map((category) => ({
value: category,
label: patientCategoryDisplayText[category],
})),
// valueFormatter: ({ value }) => patientCategoryDisplayText[value as PatientCategory],
},
{
field: 'normalLowerBound',
headerName: 'Min',
type: 'number',
width: 100,
sortable: false,
editable: true,
},
{
field: 'normalUpperBound',
headerName: 'Max',
type: 'number',
width: 100,
sortable: false,
editable: true,
},
{
field: 'normalValue',
headerName: 'So sánh',
minWidth: 100,
flex: 1,
sortable: false,
editable: true,
},
{
field: 'description',
headerName: 'Mô tả',
minWidth: 100,
flex: 1,
sortable: false,
editable: true,
},
{
field: 'note',
headerName: 'Tham khảo',
minWidth: 100,
flex: 1,
sortable: false,
editable: true,
},
{
field: 'defaultChecked',
type: 'boolean',
headerName: 'Mặc định',
minWidth: 80,
sortable: false,
editable: true,
valueGetter: ({ value }) => {
return value ?? false
},
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { useEffect, useState } from 'react'
import { Box, Button } from '@mui/material'

import {
TestElementNormalRuleDto,
TestElementResponseDto,
} from 'src/infra/api/access-service/test-element'
import { CrudTable } from 'src/components/table'
import { SideAction } from 'src/components/ui/SideAction'
import { TestElementNormalRuleDtoWithId, normalRuleColumns } from './columns'

type NormalRuleEditorProps = {
element: TestElementResponseDto | null
onClose: Function
onSubmit: (normalRules: TestElementNormalRuleDto[]) => void
isSubmitting: boolean
}

export function NormalRuleEditor(props: NormalRuleEditorProps) {
const [items, setItems] = useState<TestElementNormalRuleDtoWithId[]>([])

useEffect(() => {
if (props.element?.normalRules) {
setItems(
props.element?.normalRules.map((rule) => ({
id: JSON.stringify(rule),
...rule,
})),
)
}
}, [props.element?.normalRules])

const handleSubmit = () => {
props.onSubmit(
items.map((rule) => ({
...rule,
id: undefined,
defaultChecked: rule.defaultChecked ?? false,
})),
)
props.onClose()
}

const handleCancel = () => {
props.onClose()
}

return (
<SideAction
fullWidth
open={props.element != null}
onClose={props.onClose}
title={props.element?.name ?? ''}
disableClickOutside={props.isSubmitting}
>
<Box sx={{ height: '100%' }}>
<CrudTable
items={items}
itemIdField="id"
fieldColumns={normalRuleColumns}
onItemCreate={(item) => {
setItems((items) => [
...items,
{ ...item, id: JSON.stringify(item) },
])
}}
onItemUpdate={(item) => {
setItems((items) => [
{ ...item, id: JSON.stringify(item) },
...items.filter((rule) => rule.id !== item.id),
])
}}
onItemDelete={(item) => {
setItems((items) => items.filter((rule) => rule.id !== item.id))
}}
/>
<Box>
<Button
sx={{ mt: 2 }}
variant="contained"
color="primary"
onClick={handleSubmit}
>
Lưu
</Button>
<Button sx={{ mt: 2, mx: 1 }} color="primary" onClick={handleCancel}>
Huỷ
</Button>
</Box>
</Box>
</SideAction>
)
}
Loading

0 comments on commit 7fd3e2b

Please sign in to comment.