Skip to content

Commit

Permalink
Merge pull request #19 from Injiri/main
Browse files Browse the repository at this point in the history
esm app shell for an extension of @openmrs/esm-laboratory-app to support posting samples to eid platform
  • Loading branch information
Rugute authored Mar 4, 2024
2 parents fb5c526 + 35270bd commit 0826ec8
Show file tree
Hide file tree
Showing 22 changed files with 951 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/esm-lab-order-manifest-app/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const rootConfig = require('../../jest.config.js');

module.exports = rootConfig;
55 changes: 55 additions & 0 deletions packages/esm-lab-order-manifest-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@ampath/esm-lab-order-manifest-app",
"version": "6.0.0",
"description": "AMPATH lab Orders Manifest App",
"browser": "dist/ampath-esm-lab-order-manifest-app.js",
"main": "src/index.ts",
"source": true,
"license": "MPL-2.0",
"homepage": "https://github.com/AMPATH/ampath-esm-3.x#readme",
"scripts": {
"start": "openmrs develop --port 4542 --backend http://amrs.ampath.or.ke:8080 --api-url /amrs --importmap http://amrs.ampath.or.ke:8080/amrs/spa/importmap.json",
"serve": "webpack serve --mode=development",
"debug": "npm run serve",
"build": "webpack --mode production",
"analyze": "webpack --mode=production --env.analyze=true",
"lint": "cross-env TIMING=1 eslint src --ext ts,tsx",
"test": "cross-env TZ=UTC jest --config jest.config.js --verbose false --passWithNoTests --color",
"test:watch": "cross-env TZ=UTC jest --watch --config jest.config.js --color",
"coverage": "yarn test --coverage",
"typescript": "tsc",
"extract-translations": "i18next 'src/**/*.component.tsx'"
},
"browserslist": [
"extends browserslist-config-openmrs"
],
"keywords": [
"openmrs",
"ampath"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AMPATH/ampath-esm-3.x.git"
},
"bugs": {
"url": "https://github.com/AMPATH/ampath-esm-3.x/issues"
},
"dependencies": {
"@carbon/react": "~1.37.0",
"lodash-es": "^4.17.15"
},
"peerDependencies": {
"@openmrs/esm-framework": "5.x",
"@openmrs/esm-laboratory-app": "1.0.0",
"react": "^18.1.0",
"react-i18next": "11.x",
"react-router-dom": "6.x",
"swr": "2.x"
},
"devDependencies": {
"webpack": "^5.74.0"
}
}
8 changes: 8 additions & 0 deletions packages/esm-lab-order-manifest-app/src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Type } from '@openmrs/esm-framework';
export const configSchema = {
basicAuthBase64: {
_type: Type.String,
_description: 'Basic auth base64 string for the API call e.g Basic someBase64String==',
_default: '',
},
};
4 changes: 4 additions & 0 deletions packages/esm-lab-order-manifest-app/src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '@carbon/react';
declare module '*.css';
declare module '*.scss';
declare type SideNavProps = {};
32 changes: 32 additions & 0 deletions packages/esm-lab-order-manifest-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { defineConfigSchema, getAsyncLifecycle, getSyncLifecycle } from '@openmrs/esm-framework';
import { configSchema } from './config-schema';
import Root from './root.component';

const moduleName = '@ampath/esm-lab-order-manifest-app';

const options = {
featureName: 'esm-lab-order-manifest-app',
moduleName,
};

export const importTranslation = require.context('../translations', false, /.json$/, 'lazy');

export const root = getSyncLifecycle(Root, options);
export const manifestOrdersComponent = getAsyncLifecycle(
() => import('./lab-order-manifest/manifest-orders.component'),
options,
);

export const postOrderToEidDialog = getAsyncLifecycle(
() => import('./lab-order-manifest/dialog/post-to-eid-dialog.component'),
options,
);

export const postOrderToEidButton = getAsyncLifecycle(
() => import('./lab-order-manifest/order-actions/post-to-eid-action.component'),
options,
);

export function startupApp() {
defineConfigSchema(moduleName, configSchema);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@use '@carbon/styles/scss/spacing';
@use '@carbon/styles/scss/type';

section {
margin: spacing.$spacing-03;
}

.sectionTitle {
margin-bottom: spacing.$spacing-04;
}

.modalBody {
padding-bottom: spacing.$spacing-05;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React, { useState } from 'react';

import {
Button,
ContentSwitcher,
Form,
ModalBody,
ModalFooter,
ModalHeader,
Select,
SelectItem,
Switch,
TextArea,
Grid,
Checkbox,
TextInput,
IconButton,
} from '@carbon/react';
import { useTranslation } from 'react-i18next';
import styles from './post-orde-to-eid-dialog.scss';
import { type Result } from '../manifest-orders-list-resource';
import { PostToEid } from './post-to-eid-dialog.resource';
import { showNotification, showSnackbar } from '@openmrs/esm-framework';
import { Card } from '@ampath/esm-patient-registration-app/src/patient-verification/verification.component';

interface PostOrderDialogProps {
order: Result;
closeModal: () => void;
}

const PostEidOrderDialog: React.FC<PostOrderDialogProps> = ({ order, closeModal }) => {
const { t } = useTranslation();

const [notes, setNotes] = useState('');

const postOrder = async (event) => {
event.preventDefault();
// TODO Clean up for amrs posting to nascop eid
const payload = {
fulfillerStatus: 'EXCEPTION',
fulfillerComment: notes,
};
PostToEid(order.uuid, payload).then(
(resp) => {
showSnackbar({
isLowContrast: true,
title: t('postOrder', 'Post Order'),
kind: 'success',
subtitle: t(
'successfullyPosted',
`You have successfully posted an Order with OrderNumber ${order.orderNumber} `,
),
});
closeModal();
},
(err) => {
showNotification({
title: t(`errorRejectingOrder', 'Error Rejecting the order`),
kind: 'error',
critical: true,
description: err?.message,
});
},
);
};

return (
<div>
<Form onSubmit={postOrder}>
<ModalHeader closeModal={closeModal} title={t('postOrder', 'Post Order To EID')} />
<ModalBody>
<div className={styles.modalBody}>
<section className={styles.section}>
<h5 className={styles.section}>
{order?.accessionNumber} &nbsp; · &nbsp;{order?.fulfillerStatus} &nbsp; · &nbsp;
{order?.orderNumber}
&nbsp;
</h5>
</section>
<br />
<section className={styles.section}>
<Card label="Client ID (CCC Number)" value="" />
<TextArea
labelText={t('notes', 'Enter Comments ')}
id="nextNotes"
name="nextNotes"
invalidText="Required"
helperText="Please enter comment"
maxCount={500}
enableCounter
onChange={(e) => setNotes(e.target.value)}
/>
</section>
</div>
</ModalBody>
<ModalFooter>
<Button kind="secondary" onClick={closeModal}>
{t('cancel', 'Cancel')}
</Button>
<Button kind="success" type="submit">
{t('postToEid', 'Post To EID')}
</Button>
</ModalFooter>
</Form>
</div>
);
};

export default PostEidOrderDialog;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { openmrsFetch } from '@openmrs/esm-framework';

export async function PostToEid(uuid: string, body: any) {
const abortController = new AbortController();

return openmrsFetch(`/ws/rest/v1/order/${uuid}/fulfillerdetails/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
signal: abortController.signal,
body: body,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { openmrsFetch } from '@openmrs/esm-framework';
import useSWR from 'swr';

export interface Result {
uuid: string;
orderNumber: string;
accessionNumber: string;
patient: Patient;
concept: Concept;
action: string;
careSetting: CareSetting;
previousOrder: PreviousOrder;
dateActivated: string;
scheduledDate: any;
dateStopped: any;
autoExpireDate: any;
encounter: Encounter;
orderer: Orderer;
orderReason: any;
orderReasonNonCoded: any;
orderType: OrderType;
urgency: string;
instructions: any;
commentToFulfiller: any;
display: string;
auditInfo: AuditInfo;
fulfillerStatus: string;
fulfillerComment: any;
specimenSource: SpecimenSource;
laterality: any;
clinicalHistory: any;
frequency: any;
numberOfRepeats: any;
links: Link[];
type: string;
resourceVersion: string;
}

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

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

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

export interface CareSetting {
uuid: string;
name: string;
description: string;
retired: boolean;
careSettingType: string;
display: string;
links: Link[];
resourceVersion: string;
}

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

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

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

export interface OrderType {
uuid: string;
display: string;
name: string;
javaClassName: string;
retired: boolean;
description: string;
conceptClasses: any[];
parent: any;
links: Link[];
resourceVersion: string;
}

export interface AuditInfo {
creator: Creator;
dateCreated: string;
changedBy: any;
dateChanged: any;
}

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

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

export function useGetOrdersWorklist(activatedOnOrAfterDate: string, fulfillerStatus: string) {
const apiUrl = `/ws/rest/v1/order?orderTypes=52a447d3-a64a-11e3-9aeb-50e549534c5e&activatedOnOrAfterDate=${activatedOnOrAfterDate}&isStopped=false&fulfillerStatus=${fulfillerStatus}&v=full
`;

const { data, error, isLoading } = useSWR<{ data: { results: Array<Result> } }, Error>(apiUrl, openmrsFetch);

return {
workListEntries: data?.data ? data.data.results : [],
isLoading,
isError: error,
};
}
Loading

0 comments on commit 0826ec8

Please sign in to comment.