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 46990a4
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 136 deletions.
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],
);
};
126 changes: 67 additions & 59 deletions packages/esm-patient-orders-app/src/hooks/useOrderStockInfo.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,71 @@
// import { useState, useEffect } from 'react';
// import { OrderStockData } from '../types/order'; // Adjust based on path
import { type OrderStockData } from '../types/order';

export const useOrderStockInfo = (code: string) => {
// const [stock, setStock] = useState<OrderStockData | null>(null);
//
// useEffect(() => {
// const fetchStock = async () => {
// const response = await fetch(`http://localhost:8080/odoo/R4/InventoryItem?code=${code}`);
// const data: OrderStockData = await response.json();
// setStock(data.entry[0]); // Get the first entry
// };
//
// fetchStock();
// }, [code]);
import useSWR from 'swr';
import { fhirBaseUrl } from '@openmrs/esm-framework';
import { useMemo } from 'react';

return {
resourceType: 'Bundle',
id: '73e12fd2-b13c-4675-b7f4-704dff90bb1d',
meta: {
lastUpdated: '2024-09-10T10:56:28.983+03:00',
},
type: 'searchset',
link: [
{
relation: 'self',
url: 'http://localhost:8080/odoo/R4/InventoryItem?code=af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
},
],
entry: [
{
resource: {
resourceType: 'InventoryItem',
id: 'af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
meta: {
profile: ['http://hl7.org/fhir/StructureDefinition/InventoryItem'],
},
status: 'active',
code: [
{
coding: [
{
system: 'https://fhir.openmrs.org/concept-system/inventory-item',
code: 'af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
display: 'Vitamine B-Complex Injection',
},
],
},
],
name: [
{
name: 'Vitamine B-Complex Injection',
export const useOrderStockInfo = (orderItemUuid: string) => {
const { data, isLoading } = useSWR(
orderItemUuid ? `${fhirBaseUrl}/ChargeItemDefinition?code=${orderItemUuid}` : null,
async (): Promise<OrderStockData> => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
resourceType: 'Bundle',
id: '73e12fd2-b13c-4675-b7f4-704dff90bb1d',
meta: {
lastUpdated: '2024-09-10T10:56:28.983+03:00',
},
],
netContent: {
value: 220.0,
unit: 'Ampule(s)',
},
},
},
],
};
type: 'searchset',
link: [
{
relation: 'self',
url: 'http://localhost:8080/odoo/R4/InventoryItem?code=af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
},
],
entry: [
{
resource: {
resourceType: 'InventoryItem',
id: 'af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
meta: {
profile: ['http://hl7.org/fhir/StructureDefinition/InventoryItem'],
},
status: 'active',
code: [
{
coding: [
{
system: 'https://fhir.openmrs.org/concept-system/inventory-item',
code: 'af3fce1f-dcb1-4f76-ad4c-b8ebda43070c',
display: 'Vitamine B-Complex Injection',
},
],
},
],
name: [
{
name: 'Vitamine B-Complex Injection',
},
],
netContent: {
value: 220.0,
unit: 'Ampule(s)',
},
},
},
],
});
}, 3000);
});
},
);

return useMemo(
() => ({
data,
isLoading,
}),
[data, isLoading],
);
};
4 changes: 2 additions & 2 deletions packages/esm-patient-orders-app/src/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
{
"name": "order-price-details",
"component": "orderPriceDetailsExtension",
"slot": "order-item-price-and-stock-info",
"slot": "order-tem-additional-info-slot",
"order": 0
},
{
"name": "order-stock-details",
"component": "orderStockDetailsExtension",
"slot": "order-item-price-and-stock-info",
"slot": "order-tem-additional-info-slot",
"order": 1
},
{
Expand Down

0 comments on commit 46990a4

Please sign in to comment.