Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lab results to lab results encounter #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export const configSchema = {
_default: "52a447d3-a64a-11e3-9aeb-50e549534c5e",
_description: "Uuid for orderType",
},
laboratoryResultEncounterTypeUuid: {
_type: Type.String,
_default: "3596fafb-6f6f-4396-8c87-6e63a0f1bd71",
_description: "Uuid for lab resulting encounter type",
},
targetPatientDashboard: {
redirectToResultsViewer: {
_type: Type.String,
Expand All @@ -26,5 +31,6 @@ export const configSchema = {

export type Config = {
laboratoryOrderTypeUuid: string;
laboratoryResultEncounterTypeUuid: string;
targetPatientDashboard: Object;
};
7 changes: 1 addition & 6 deletions src/results/result-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,14 @@ const ResultForm: React.FC<ResultFormProps> = ({ order, patientUuid }) => {
concept: order.concept.uuid,
orderer: order.orderer,
};
const orders: Array<any> = [];
orders.push(order);

const encounterPostData = {
patient: patientUuid,
location: userLocation,
encounterType: laboratoryResultEncounterTypeUuid,
//visit: order.encounter activeVisit?.uuid,
obs: [],
//orders,
};
UpdateOrderResult(
//order.encounter.uuid,
laboratoryResultEncounterTypeUuid,
obsPayload,
orderDiscontinuationPayload,
encounterPostData
Expand Down
32 changes: 31 additions & 1 deletion src/results/result-form.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,43 @@ export async function UpdateEncounter(uuid: string, payload: any) {

//TODO: the calls to update order and observations for results should be transactional to allow for rollback
export async function UpdateOrderResult(
encounterUuid: string,
obsPayload: any,
orderPayload: any,
encounterPostData: any
) {
const abortController = new AbortController();

const patientVisits = await openmrsFetch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of fetching all visits and looping through them, it is possible to use the order's encounter and fetch the associated visit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out a way to do that unfortunately.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CynthiaKamau @arodidev could you be of assistance to @reagan-meant

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reagan-meant It should just be: encounters/${encounter.uuid}?v=custom:(visit:(uuid))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out a way to do that unfortunately.

Perhaps you can try exploring that through custom representation

Also kindly address the conflicts

`${restBaseUrl}/visit?patient=${orderPayload.patient}&v=custom:(uuid,encounters:(uuid))`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
signal: abortController.signal,
}
);

function findVisitUuidByOrderEncounterUuid(visits, orderEncounterUuid) {
for (const visit of visits) {
if (
visit.encounters.some(
(encounter) => encounter.uuid === orderEncounterUuid
)
) {
return visit.uuid;
}
}
return null;
}

const visitUuid = findVisitUuidByOrderEncounterUuid(
patientVisits.data.results,
orderPayload.encounter
);

encounterPostData.visit = visitUuid;

const createOrderResultEncounterCall = await openmrsFetch(
`${restBaseUrl}/encounter`,
{
Expand Down
Loading