Skip to content

Commit

Permalink
mock requests
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Sep 23, 2024
1 parent 8b19c67 commit a2c05fd
Show file tree
Hide file tree
Showing 17 changed files with 259 additions and 248 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"zod": "^3.22.2"
},
"devDependencies": {
"@openmrs/esm-framework": "next",
"@openmrs/esm-framework": "^5.8.2-pre.2346",
"@playwright/test": "1.45.3",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.89",
Expand Down Expand Up @@ -60,7 +60,7 @@
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^14.0.1",
"lodash": "^4.17.21",
"openmrs": "next",
"openmrs": "^5.8.2-pre.2346",
"prettier": "^3.0.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-form-entry-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"ngx-build-plus": "^17.0.0",
"openmrs": "next",
"openmrs": "^5.8.2-pre.2346",
"protractor": "~7.0.0",
"rxjs": "^7.8.0",
"style-loader": "2.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ const TestTypeSearchResultItem: React.FC<TestTypeSearchResultItemProps> = ({ t,
</div>
<div className={styles.searchResultFooter}>
<ExtensionSlot
name="order-item-price-and-stock-info"
state={{ code: testType.conceptUuid }}
name="order-tem-additional-info-slot"
state={{ orderItemUuid: testType.conceptUuid }}
className={styles.priceAndStockContainer}
/>
<div className={styles.searchResultActions}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@
}

.priceAndStockContainer {
font-size: 12px;
display: flex;
justify-content: start;
align-items: center;
gap: layout.$spacing-02;
gap: layout.$spacing-05;
}

.searchResultActions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function LabOrderBasketItemTile({ orderBasketItem, onItemClick, onRemoveC
/>
</div>
<ExtensionSlot
name="order-item-price-and-stock-info"
state={{ code: orderBasketItem.testType.conceptUuid }}
name="order-tem-additional-info-slot"
state={{ orderItemUuid: orderBasketItem.testType.conceptUuid }}
className={styles.priceAndStockContainer}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@
border-top: 1px solid $grey-2;
margin-top: layout.$spacing-03;
padding-top: layout.$spacing-03;
font-size: 12px;
display: flex;
justify-content: start;
align-items: center;
gap: layout.$spacing-02;
gap: layout.$spacing-05;
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ const DrugSearchResultItem: React.FC<DrugSearchResultItemProps> = ({ drug, openO
) : (
<div className={styles.searchResultFooter}>
<ExtensionSlot
name="order-item-price-and-stock-info"
state={{ code: orderItem.drug.uuid }}
name="order-tem-additional-info-slot"
state={{ orderItemUuid: orderItem.drug.uuid }}
className={styles.priceAndStockContainer}
/>
<div className={styles.searchResultActions}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
}

.priceAndStockContainer {
font-size: 12px;
display: flex;
flex-flow: row wrap;
justify-content: start;
align-items: center;
gap: layout.$spacing-02;
gap: layout.$spacing-05;
}

.searchResultActions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export default function OrderBasketItemTile({ orderBasketItem, onItemClick, onRe
/>
</div>
<ExtensionSlot
name="order-item-price-and-stock-info"
state={{ code: orderBasketItem.drug.uuid }}
name="order-tem-additional-info-slot"
state={{ orderItemUuid: orderBasketItem.drug.uuid }}
className={styles.priceAndStockContainer}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@
border-top: 1px solid $grey-2;
margin-top: layout.$spacing-03;
padding-top: layout.$spacing-03;
font-size: 12px;
display: flex;
justify-content: start;
align-items: center;
gap: layout.$spacing-02;
gap: layout.$spacing-05;
}
1 change: 0 additions & 1 deletion packages/esm-patient-medications-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"name": "add-drug-order",
"title": "addDrugOrderWorkspaceTitle",
"component": "addDrugOrderWorkspace",
"width": "wider",
"type": "order"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { Information } from '@carbon/react/icons';
import { useTranslation } from 'react-i18next';

interface OrderPriceDetailsComponentProps {
code: string;
orderItemUuid: string;
}

const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({ code }) => {
const OrderPriceDetailsComponent: React.FC<OrderPriceDetailsComponentProps> = ({ orderItemUuid }) => {
const { t } = useTranslation();
const priceData = useOrderPrice(code);
const { data: priceData } = useOrderPrice(orderItemUuid);
// console.log(code);

if (!priceData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { CheckmarkFilled, CloseFilled } from '@carbon/react/icons';
import styles from './order-stock-details.scss';

interface OrderStockDetailsComponentProps {
code: string;
orderItemUuid: string;
}

const OrderStockDetailsComponent: React.FC<OrderStockDetailsComponentProps> = ({ code }) => {
const stockData = useOrderStockInfo(code);
const OrderStockDetailsComponent: React.FC<OrderStockDetailsComponentProps> = ({ orderItemUuid }) => {
const { data: stockData } = useOrderStockInfo(orderItemUuid);

if (!stockData) {
return <div>Loading stock...</div>;
Expand Down
111 changes: 59 additions & 52 deletions packages/esm-patient-orders-app/src/hooks/useOrderPrice.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,62 @@
// import { useState, useEffect } from 'react';
// import { OrderPriceData } from '../types/order'; // Adjust based on path
import { type OrderPriceData } from '../types/order';
import { fhirBaseUrl } from '@openmrs/esm-framework';
import useSWR from 'swr';
import { useMemo } from 'react';

export const useOrderPrice = (code: string) => {
// const [price, setPrice] = useState<OrderPriceData | null>(null);
//
// useEffect(() => {
// const fetchPrice = async () => {
// const response = await fetch(`http://localhost:8080/odoo/R4/ChargeItemDefinition?code=${code}`);
// const data: OrderPriceData = await response.json();
// setPrice(data.entry[0]); // Get the first entry
// };
//
// fetchPrice();
// }, [code]);

return {
resourceType: 'Bundle',
id: '4c2b7e55-b7b3-4ae2-a144-99ea1d01a21a',
meta: {
lastUpdated: '2024-09-11T18:17:57.249+03:00',
},
type: 'searchset',
link: [
{
relation: 'self',
url: 'http://localhost:8080/odoo/R4/ChargeItemDefinition?code=af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
},
],
entry: [
{
resource: {
resourceType: 'ChargeItemDefinition',
id: 'af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
name: 'Vitamine B-Complex Injection',
status: 'active',
date: '2024-09-03T13:59:50+03:00',
propertyGroup: [
{
priceComponent: [
{
type: 'base',
amount: {
value: 1.08,
currency: 'USD',
},
},
],
export const useOrderPrice = (orderItemUuid: string) => {
const { data, isLoading } = useSWR(
orderItemUuid ? `${fhirBaseUrl}/ChargeItemDefinition?code=${orderItemUuid}` : null,
async (): Promise<OrderPriceData> => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
resourceType: 'Bundle',
id: '4c2b7e55-b7b3-4ae2-a144-99ea1d01a21a',
meta: {
lastUpdated: '2024-09-11T18:17:57.249+03:00',
},
],
},
},
],
};
type: 'searchset',
link: [
{
relation: 'self',
url: 'http://localhost:8080/odoo/R4/ChargeItemDefinition?code=af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
},
],
entry: [
{
resource: {
resourceType: 'ChargeItemDefinition',
id: 'af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
name: 'Vitamine B-Complex Injection',
status: 'active',
date: '2024-09-03T13:59:50+03:00',
propertyGroup: [
{
priceComponent: [
{
type: 'base',
amount: {
value: 1.08,
currency: '$',
},
},
],
},
],
},
},
],
});
}, 3000);
});
},
);

return useMemo(
() => ({
data,
isLoading,
}),
[data, isLoading],
);
};
Loading

0 comments on commit a2c05fd

Please sign in to comment.