Skip to content

Commit

Permalink
fix : free text error (#10)
Browse files Browse the repository at this point in the history
* fix : free text error

* FIX
  • Loading branch information
jabahum authored Oct 31, 2023
1 parent 9ae952d commit 7e05b34
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 156 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "src/index.ts",
"source": true,
"scripts": {
"start": "openmrs develop --backend https://ugandaemr-backend.mets.or.ug",
"start": "openmrs develop --backend http://194.163.171.253:8282",
"serve": "webpack serve --mode=development",
"build": "webpack --mode production",
"analyze": "webpack --mode=production --env analyze=true",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export const addToWorklistDialog = getAsyncLifecycle(
options
);

export const sendEmailDialog = getAsyncLifecycle(
() => import("./patient-chart/results-summary/send-email-dialog.component"),
options
);

export const resultsSummaryWorkSpace = getAsyncLifecycle(
() => import("./patient-chart/results-summary/results-summary.component"),
options
Expand Down
83 changes: 78 additions & 5 deletions src/patient-chart/laboratory-order.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { useCallback, useMemo, useState } from "react";
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { useTranslation } from "react-i18next";
import { EmptyState } from "@ohri/openmrs-esm-ohri-commons-lib";
import styles from "./laboratory-order.scss";
Expand All @@ -10,6 +16,7 @@ import {
parseDate,
ErrorState,
useLayoutType,
showModal,
} from "@openmrs/esm-framework";

import {
Expand All @@ -33,15 +40,26 @@ import {
TableExpandHeader,
TableExpandRow,
TableExpandedRow,
Button,
} from "@carbon/react";
import { Printer, MailAll, Edit } from "@carbon/react/icons";

import ViewLaboratoryItemActionMenu from "./laboratory-item/view-laboratory-item.component";
import { getOrderColor, useLabOrders } from "./laboratory-order.resource";
import TestsResults from "./results-summary/test-results-table.component";
import { useReactToPrint } from "react-to-print";
import SendEmailDialog from "./results-summary/send-email-dialog.component";
import PrintResultsSummary from "./results-summary/print-results-summary.component";
import { EncounterResponse } from "./laboratory-item/view-laboratory-item.resource";

interface LaboratoryOrderOverviewProps {
patientUuid: string;
}

interface PrintProps {
encounter: EncounterResponse;
}

type FilterProps = {
rowIds: Array<string>;
headers: any;
Expand Down Expand Up @@ -116,6 +134,63 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
[items, initialTests]
);

const EmailButtonAction: React.FC = () => {
const launchSendEmailModal = useCallback(() => {
const dispose = showModal("send-email-dialog", {
closeModal: () => dispose(),
});
}, []);

return (
<Button
kind="ghost"
size="sm"
onClick={(e) => launchSendEmailModal()}
renderIcon={(props) => <MailAll size={16} {...props} />}
/>
);
};

const PrintButtonAction: React.FC<PrintProps> = ({ encounter }) => {
const [isPrinting, setIsPrinting] = useState(false);

const contentToPrintRef = useRef(null);

const onBeforeGetContentResolve = useRef(null);

useEffect(() => {
if (onBeforeGetContentResolve.current) {
onBeforeGetContentResolve.current();
}
}, [isPrinting]);

const handlePrint = useReactToPrint({
content: () => contentToPrintRef.current,
onBeforeGetContent: () =>
new Promise((resolve) => {
onBeforeGetContentResolve.current = resolve;
setIsPrinting(true);
}),
onAfterPrint: () => {
onBeforeGetContentResolve.current = null;
setIsPrinting(false);
},
});

return (
<div>
<div ref={contentToPrintRef}>
<PrintResultsSummary encounterResponse={encounter} />
</div>
<Button
kind="ghost"
size="sm"
onClick={handlePrint}
renderIcon={(props) => <Printer size={16} {...props} />}
/>
</div>
);
};
const handleFilter = ({
rowIds,
headers,
Expand Down Expand Up @@ -184,10 +259,8 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
actions: {
content: (
<>
<ViewLaboratoryItemActionMenu
closeModal={() => true}
encounter={entry}
/>
<PrintButtonAction encounter={entry} />
<EmailButtonAction />
</>
),
},
Expand Down
68 changes: 67 additions & 1 deletion src/patient-chart/laboratory-order.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,80 @@ export interface GroupMember {
order: Order;
encounter: Encounter;
voided: boolean;
value: number;
value: number | Value;
valueModifier: any;
formFieldPath: any;
formFieldNamespace: any;
links: Link[];
resourceVersion: string;
}

export interface Value {
uuid: string;
display: string;
name: Name;
datatype: Datatype;
conceptClass: ConceptClass;
set: boolean;
version: any;
retired: boolean;
names: Name2[];
descriptions: Description[];
mappings: Mapping[];
answers: any[];
setMembers: any[];
attributes: any[];
links: Link[];
resourceVersion: string;
}

export interface Name {
display: string;
uuid: string;
name: string;
locale: string;
localePreferred: boolean;
conceptNameType: string;
links: Link[];
resourceVersion: string;
}

export interface Link {
rel: string;
uri: string;
resourceAlias: string;
}

export interface Datatype {
uuid: string;
display: string;
links: Link[];
}

export interface ConceptClass {
uuid: string;
display: string;
links: Link[];
}

export interface Name2 {
uuid: string;
display: string;
links: Link[];
}

export interface Description {
uuid: string;
display: string;
links: Link[];
}

export interface Mapping {
uuid: string;
display: string;
links: Link[];
}

export interface ObsGroup {
uuid: string;
display: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const PrintResultsSummary: React.FC<PrintResultsSummaryProps> = ({
</div>
</section>
<section className={styles.section}>
<TestsPrintResults orders={encounterResponse?.orders} />
<TestsPrintResults obs={encounterResponse?.obs} />
</section>
</div>
);
Expand Down
59 changes: 3 additions & 56 deletions src/patient-chart/results-summary/results-summary.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,8 @@ const ResultsSummary: React.FC<ResultsSummaryProps> = ({ encounter }) => {
// const { encounter, isLoading, isError } = useGetEncounterById(encounterUuid);

// print button
const PrintButtonAction: React.FC = () => {
const [isPrinting, setIsPrinting] = useState(false);

const contentToPrintRef = useRef(null);

const onBeforeGetContentResolve = useRef(null);

useEffect(() => {
if (onBeforeGetContentResolve.current) {
onBeforeGetContentResolve.current();
}
}, [isPrinting]);

const handlePrint = useReactToPrint({
content: () => contentToPrintRef.current,
onBeforeGetContent: () =>
new Promise((resolve) => {
onBeforeGetContentResolve.current = resolve;
setIsPrinting(true);
}),
onAfterPrint: () => {
onBeforeGetContentResolve.current = null;
setIsPrinting(false);
},
});

return (
<div>
<div ref={contentToPrintRef}>
<PrintResultsSummary encounterResponse={encounter} />
</div>
<Button
kind="ghost"
size="sm"
onClick={handlePrint}
renderIcon={(props) => <Printer size={16} {...props} />}
/>
</div>
);
};

// email button
const EmailButtonAction: React.FC = () => {
const handleButtonClick = (event: MouseEvent) => {
event.preventDefault();
};
return (
<Button
kind="ghost"
size="sm"
onClick={(e) => handleButtonClick(e)}
renderIcon={(props) => <MailAll size={16} {...props} />}
/>
);
};

// if (encounter) {
// return <DataTableSkeleton role="progressbar" />;
Expand All @@ -100,8 +47,8 @@ const ResultsSummary: React.FC<ResultsSummaryProps> = ({ encounter }) => {
<div style={{ display: "flex", justifyContent: "space-between" }}>
<div></div>
<div style={{ display: "flex", flexDirection: "row" }}>
<PrintButtonAction />
<EmailButtonAction />
{/* <PrintButtonAction /> */}
{/* <EmailButtonAction /> */}
</div>
</div>
</section>
Expand Down Expand Up @@ -135,7 +82,7 @@ const ResultsSummary: React.FC<ResultsSummaryProps> = ({ encounter }) => {
</div>
</section>
<section className={styles.section}>
<TestsResults obs={obsData} />
{/* <TestsResults obs={obsData} /> */}
</section>
</ModalBody>
{/* <ModalFooter>
Expand Down
Loading

0 comments on commit 7e05b34

Please sign in to comment.