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

Post Submission Handlers for key forms #12

Merged
merged 7 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
},
"devDependencies": {
"@ohri/openmrs-esm-ohri-commons-lib": "next",
"@openmrs/esm-form-engine-lib": "next",
"@openmrs/esm-framework": "next",
"@openmrs/esm-patient-common-lib": "next",
"@openmrs/esm-styleguide": "next",
"@openmrs/openmrs-form-engine-lib": "next",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.68",
"@swc/jest": "^0.2.26",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AllEncounters from "./encounters/encounters.component";
import PatientSummary from "./patient-summary/patient-summary.component";
import CareAndTreatment from "./care-and-treatment/care-and-treatment.component";
import versionTwoNavigationButton from "./app-menu-navigation/app-menu-navigation";
import { registerPostSubmissionAction } from "@openmrs/openmrs-form-engine-lib";

const moduleName = "@ohri/openmrs-esm-rwanda-app";

Expand All @@ -32,6 +33,10 @@ export const importTranslation = require.context(

export function startupApp() {
defineConfigSchema(moduleName, configSchema);
registerPostSubmissionAction({
name: "BillingSubmissionAction",
load: () => import("./post-submission-handlers/billing-submission-action"),
});
}

// clinical views divider
Expand Down
54 changes: 54 additions & 0 deletions src/post-submission-handlers/billing-submission-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { type PostSubmissionAction } from "@openmrs/openmrs-form-engine-lib";
import { openmrsFetch, showSnackbar, showToast } from "@openmrs/esm-framework";

const BillingSubmissionAction: PostSubmissionAction = {
applyAction: async function ({ encounters, sessionMode }) {
try {
if (sessionMode !== "enter") {
return true;
}

const billingEndpoint = "/ws/rest/v1/mohbilling/afterPostSubmission";

const obsData = {
obs: encounters[0].obs.map((ob) => ({
uuid: ob.uuid,
})),
};

const response = await openmrsFetch(billingEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(obsData),
});

if (response.ok) {
showSnackbar({
title: "Post Submission Action",
subtitle: "Patient bill has been created successfully",
kind: "success",
timeoutInMs: 4000,
});
} else {
showToast({
description: `Billing submission failed: ${response.statusText}`,
kind: "error",
});
}

return true;
} catch (error) {
showToast({
description: `An error occurred during billing submission: ${
error.message || "Unknown error"
}`,
kind: "error",
});
return true;
}
},
};

export default BillingSubmissionAction;
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"es2015.promise",
"es2016.array.include",
"es2018",
"es2020"
"es2020",
"es2021",
"es2022"
],
"resolveJsonModule": true,
"noEmit": true,
Expand Down
Loading
Loading