Skip to content

Commit

Permalink
(feat) Order summary/history (#1463)
Browse files Browse the repository at this point in the history
* (feat) lab orders history and results

orders print and pending orders

adds translations

moving orders summary to orders esm

translations

updates import

* fixes to residue after rebase

* adds pagination and filter logic

* pr changes

* PR changes

* adds feature flag and minor tweaks

* Cleanup

---------

Co-authored-by: Vineet Sharma <[email protected]>
  • Loading branch information
pirupius and vasharma05 authored Dec 4, 2023
1 parent 7a49ac2 commit 4087f96
Show file tree
Hide file tree
Showing 23 changed files with 970 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/esm-patient-common-lib/src/orders/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './useOrderBasket';
export * from './postOrders';
export * from './useOrders';
export * from './types';
33 changes: 33 additions & 0 deletions packages/esm-patient-common-lib/src/orders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,39 @@ export interface Order {
route: OpenmrsResource;
scheduleDate: null;
urgency: string;

// additional properties
accessionNumber: string;
scheduledDate: string;
display: string;
auditInfo: {
creator: {
uuid: string;
display: string;
};
dateCreated: string;
changedBy: string;
dateChanged: string;
};
fulfillerStatus: string;
fulfillerComment: string;
specimenSource: string;
laterality: string;
clinicalHistory: string;
numberOfRepeats: string;
type: string;
}

export interface OrderTypeFetchResponse {
results: Array<OrderType>;
}

export interface OrderType {
uuid: string;
display: string;
name: string;
retired: boolean;
description: string;
}

export interface Drug {
Expand Down
52 changes: 52 additions & 0 deletions packages/esm-patient-common-lib/src/orders/useOrders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import useSWR, { mutate } from 'swr';
import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework';
import { useCallback, useMemo } from 'react';
import { type OrderTypeFetchResponse, type PatientOrderFetchResponse } from '@openmrs/esm-patient-common-lib';

export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0';

export function usePatientOrders(patientUuid: string, status: 'ACTIVE' | 'any', orderType?: string) {
const baseOrdersUrl = `/ws/rest/v1/order?v=full&patient=${patientUuid}&careSetting=${careSettingUuid}&status=${status}`;
const ordersUrl = orderType ? `${baseOrdersUrl}&orderType=${orderType}` : baseOrdersUrl;

const { data, error, isLoading, isValidating } = useSWR<FetchResponse<PatientOrderFetchResponse>, Error>(
patientUuid ? ordersUrl : null,
openmrsFetch,
);

const mutateOrders = useCallback(
() => mutate((key) => typeof key === 'string' && key.startsWith(`/ws/rest/v1/order?patient=${patientUuid}`)),
[patientUuid],
);

const orders = useMemo(
() =>
data?.data?.results
? data.data.results?.sort((order1, order2) => (order2.dateActivated > order1.dateActivated ? 1 : -1))
: null,
[data],
);

return {
data: orders,
error,
isLoading,
isValidating,
mutate: mutateOrders,
};
}

export function useOrderTypes() {
const orderTypesUrl = `/ws/rest/v1/ordertype`;
const { data, error, isLoading, isValidating } = useSWR<FetchResponse<OrderTypeFetchResponse>, Error>(
orderTypesUrl,
openmrsFetch,
);

return {
data: data?.data?.results,
error,
isLoading,
isValidating,
};
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useCallback, useState } from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Button, ButtonSet, Column, ComboBox, Form, Layer, Grid, InlineNotification, TextInput } from '@carbon/react';
import { launchPatientWorkspace, useOrderBasket } from '@openmrs/esm-patient-common-lib';
import { useLayoutType, useSession } from '@openmrs/esm-framework';
import { type LabOrderBasketItem, careSettingUuid, prepLabOrderPostData } from '../api';
import { Button, ButtonSet, Column, ComboBox, Form, Layer, Grid, InlineNotification, TextInput } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { priorityOptions } from './lab-order';
import { type TestType, useTestTypes } from './useTestTypes';
import styles from './lab-order-form.scss';
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-labs-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
}
],
"pages": []
}
}
8 changes: 4 additions & 4 deletions packages/esm-patient-medications-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "medications-details-widget",
"component": "medicationsSummary",
"slot": "patient-chart-orders-dashboard-slot",
"slot": "patient-chart-medications-dashboard-slot",
"meta": {
"columnSpan": 1
}
Expand All @@ -19,15 +19,15 @@
"meta": {
"columnSpan": 4
},
"order": 4
"order": 4
},
{
"name": "medications-summary-dashboard",
"component": "medicationsDashboardLink",
"slot": "patient-chart-dashboard-slot",
"order": 3,
"meta": {
"slot": "patient-chart-orders-dashboard-slot",
"slot": "patient-chart-medications-dashboard-slot",
"columns": 1,
"path": "Medications"
}
Expand All @@ -39,4 +39,4 @@
"order": 1
}
]
}
}
2 changes: 2 additions & 0 deletions packages/esm-patient-orders-app/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import useSWR, { useSWRConfig } from 'swr';
import { type FetchResponse, openmrsFetch, type OpenmrsResource, parseDate, type Visit } from '@openmrs/esm-framework';
import { type OrderPost, useVisitOrOfflineVisit, useSystemVisitSetting } from '@openmrs/esm-patient-common-lib';

export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0';

/**
* Returns a function which refreshes the patient orders cache. Uses SWR's mutate function.
* Refreshes patient orders for all kinds of orders.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@use '@carbon/styles/scss/colors';
@use '@carbon/styles/scss/spacing';
@use '@carbon/styles/scss/type';
@import "../root";

.widgetCard {
border: 1px solid colors.$gray-20;
border-bottom: none;
}

.row {
span {
margin: auto;
}

p {
padding: spacing.$spacing-02 0;
}
}

.medicationRecord {
display: flex;
flex-direction: column;
justify-content: space-between;
}

.startDateColumn {
@include type.type-style("body-compact-01");
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: space-between;
min-height: spacing.$spacing-11;
padding-bottom: spacing.$spacing-02;

span {
margin: 0rem;
}
}

.dosage {
@include type.type-style("heading-compact-01");
}

.tooltip {
margin: 0rem -0.5rem -0.625rem;
}

.menuItem {
max-width: none;
}

.buttons {
justify-content: flex-end;
}
Loading

0 comments on commit 4087f96

Please sign in to comment.