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

Feat/add numeric value ranges #47

Merged
merged 3 commits into from
Jan 31, 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
2 changes: 1 addition & 1 deletion src/patient-chart/laboratory-order.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
),
},
location: {
content: <span>{entry.location.display}</span>,
content: <span>{entry?.location?.display}</span>,
},
status: {
content: <span>--</span>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PrintResultsSummary: React.FC<PrintResultsSummaryProps> = ({
<span
style={{ fontSize: "10px", fontWeight: "bold", margin: "5px" }}
>
{encounterResponse.visit.location.display}
{encounterResponse?.visit?.location?.display}
</span>
</div>
<div
Expand Down
34 changes: 32 additions & 2 deletions src/results/result-form-field.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TextInput, Select, SelectItem } from "@carbon/react";
import { useTranslation } from "react-i18next";
import { ConceptReference } from "./result-form.resource";
import { Controller } from "react-hook-form";
import { min } from "rxjs/operators";

interface ResultFormFieldProps {
concept: ConceptReference;
Expand All @@ -23,6 +24,25 @@ const ResultFormField: React.FC<ResultFormFieldProps> = ({
const isCoded = (concept) => concept.datatype?.display === "Coded";
const isPanel = (concept) => concept.setMembers?.length > 0;

const printValueRange = (concept: ConceptReference) => {
if (concept?.datatype?.display === "Numeric") {
const maxVal = Math.max(
concept?.hiAbsolute,
concept?.hiCritical,
concept?.hiNormal
);
const minVal = Math.min(
concept?.lowAbsolute,
concept?.lowCritical,
concept?.lowNormal
);
return ` (${minVal ?? 0} - ${maxVal > 0 ? maxVal : "--"} ${
concept?.units ?? ""
})`;
}
return "";
};

return (
<>
{Object.keys(errors).length > 0 && (
Expand All @@ -41,7 +61,12 @@ const ResultFormField: React.FC<ResultFormFieldProps> = ({
className={styles.textInput}
{...field}
type={concept.datatype.display === "Numeric" ? "number" : "text"}
labelText={concept?.display}
labelText={
concept?.display +
(concept.datatype.display === "Numeric"
? printValueRange(concept) ?? ""
: "")
}
autoFocus
/>
)}
Expand Down Expand Up @@ -98,7 +123,12 @@ const ResultFormField: React.FC<ResultFormFieldProps> = ({
type={
member.datatype.display === "Numeric" ? "number" : "text"
}
labelText={member?.display}
labelText={
member?.display +
(member.datatype.display === "Numeric"
? printValueRange(member) ?? ""
: "")
}
autoFocus={index === 0}
/>
)}
Expand Down
18 changes: 16 additions & 2 deletions src/results/result-form.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export interface ConceptResponse {
attributes: any[];
links: Link18[];
resourceVersion: string;
hiNormal?: number;
hiAbsolute?: number;
hiCritical?: number;
lowNormal?: number;
lowAbsolute?: number;
lowCritical?: number;
units?: string;
}

export interface Name {
Expand Down Expand Up @@ -159,6 +166,13 @@ export interface ConceptReference {
attributes: any[];
links: Link15[];
resourceVersion: string;
hiNormal?: number;
hiAbsolute?: number;
hiCritical?: number;
lowNormal?: number;
lowAbsolute?: number;
lowCritical?: number;
units?: string;
}

export interface Name3 {
Expand Down Expand Up @@ -300,7 +314,8 @@ export async function GetOrderConceptByUuid(uuid: string) {
}

export function useGetOrderConceptByUuid(uuid: string) {
const apiUrl = `/ws/rest/v1/concept/${uuid}?v=full`;
const apiUrl = `/ws/rest/v1/concept/${uuid}?v=custom:(uuid,display,name,datatype,set,answers,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units,setMembers:(uuid,display,answers,datatype,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units))`;

const { data, error, isLoading, isValidating, mutate } = useSWR<
{ data: ConceptResponse },
Error
Expand All @@ -314,7 +329,6 @@ export function useGetOrderConceptByUuid(uuid: string) {
};
}

// create observation
export async function UpdateEncounter(uuid: string, payload: any) {
const abortController = new AbortController();
return openmrsFetch(`/ws/rest/v1/encounter/${uuid}`, {
Expand Down
9 changes: 6 additions & 3 deletions src/work-list/work-list.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import { Result, useGetOrdersWorklist } from "./work-list.resource";
import styles from "./work-list.scss";
import {
ConfigurableLink,
formatDate,
parseDate,
showModal,
Expand Down Expand Up @@ -116,7 +117,7 @@
{ id: 10, header: t("actions", "Actions"), key: "actions" },
];

const ResultsOrder: React.FC<ResultsOrderProps> = ({

Check warning on line 120 in src/work-list/work-list.component.tsx

View workflow job for this annotation

GitHub Actions / build

The 'ResultsOrder' function makes the dependencies of useMemo Hook (at line 193) change on every render. Move it inside the useMemo callback. Alternatively, wrap the definition of 'ResultsOrder' in its own useCallback() Hook
order,
patientUuid,
}) => {
Expand Down Expand Up @@ -149,9 +150,11 @@
},
patient: {
content: (
<>
<span>{entry.patient.display.split("-")[1]}</span>
</>
<ConfigurableLink
to={`\${openmrsSpaBase}/patient/${entry.patient.uuid}/chart/laboratory-orders`}
>
{entry.patient.display.split("-")[1]}
</ConfigurableLink>
),
},
orderNumber: { content: <span>{entry.orderNumber}</span> },
Expand Down
Loading
Loading