Skip to content

Commit

Permalink
Delete resource file, refactor component to use afterPostSubmission e…
Browse files Browse the repository at this point in the history
…ndpoint
  • Loading branch information
ODORA0 committed Jan 22, 2025
1 parent ef6a916 commit b065236
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 124 deletions.
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +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,
getPostSubmissionActionById,
} from "@openmrs/openmrs-form-engine-lib";
import { registerPostSubmissionAction } from "@openmrs/openmrs-form-engine-lib";

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

Expand All @@ -35,10 +32,7 @@ export const importTranslation = require.context(
);

export function startupApp() {
console.log("Initializing Rwanda ESM...");
defineConfigSchema(moduleName, configSchema);

console.log("Registering BillingSubmissionAction...");
registerPostSubmissionAction({
name: "BillingSubmissionAction",

Check failure on line 37 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type '{ name: string; load: () => Promise<typeof import("/home/runner/work/openmrs-esm-rwanda-app/openmrs-esm-rwanda-app/src/post-submission-handlers/billing-submission-action")>; }' is not assignable to parameter of type 'PostSubmissionActionRegistration'.
load: () => import("./post-submission-handlers/billing-submission-action"),
Expand Down
102 changes: 34 additions & 68 deletions src/post-submission-handlers/billing-submission-action.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,52 @@
import { type PostSubmissionAction } from "@openmrs/openmrs-form-engine-lib";
import {
getConfig,
openmrsFetch,
type OpenmrsResource,
} from "@openmrs/esm-framework";
import {
BillingConfig,
BillingData,
BillingResponse,
} from "./billing.resource";

const getUuid = (
resource: string | OpenmrsResource | undefined
): string | undefined => {
if (!resource) {
return undefined;
}
if (typeof resource === "string") {
return resource;
}
return resource.uuid;
};
import { openmrsFetch, showSnackbar, showToast } from "@openmrs/esm-framework";

const BillingSubmissionAction: PostSubmissionAction = {
applyAction: async function ({ patient, encounters, sessionMode }) {
applyAction: async function ({ patient, encounters, sessionMode }, config) {

Check warning on line 5 in src/post-submission-handlers/billing-submission-action.ts

View workflow job for this annotation

GitHub Actions / build

'patient' is defined but never used

Check warning on line 5 in src/post-submission-handlers/billing-submission-action.ts

View workflow job for this annotation

GitHub Actions / build

'config' is defined but never used
try {
if (sessionMode !== "enter") {
console.log("Not a new form submission, skipping billing");
return;
return true;
}

console.log("Starting billing submission process");
const config: BillingConfig = await getConfig(
"@ohri/openmrs-esm-billing-app"
);
const encounter = encounters[0];
const billingEndpoint = "/ws/rest/v1/mohbilling/afterPostSubmission";

// Extract observations from encounter
const getObsValue = (conceptUuid: string) => {
const obs = encounter.obs?.find(
(observation) => observation.concept.uuid === conceptUuid
);
return obs ? obs.value : null;
const obsData = {
obs: encounters[0].obs.map((ob) => ({
uuid: ob.uuid,
})),
};

// Get values for billing
const diseaseType = getObsValue(config.concepts.diseaseType);
const consultationType = getObsValue(config.concepts.consultationType);
const department = getObsValue(config.concepts.department);
const isAdmitted = getObsValue(config.concepts.isAdmitted);
const response = await openmrsFetch(billingEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(obsData),
});

if (!diseaseType || !consultationType || !department) {
console.error("Missing required billing information");
return;
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",
});
}

// Prepare billing data
const billingData: BillingData = {
patientUuid: patient.id,
encounterUuid: encounter.uuid,
diseaseType,
consultationType,
department,
isAdmitted: isAdmitted || false,
dateCreated: new Date().toISOString(),
location: getUuid(encounter.location),
provider: encounter.encounterProviders?.[0]?.provider?.uuid,
};

console.log("Billing data prepared:", billingData);
return true;

/* TODO: Uncomment when API is ready
const response = await openmrsFetch<BillingResponse>(config.endpoints.billing, {
method: 'POST',
body: billingData
});
return response.ok;
*/
} catch (error) {
console.error("Error in billing submission:", error);
return false;
showToast({
description: `An error occurred during billing submission: ${
error.message || "Unknown error"
}`,
kind: "error",
});
return true;
}
},
};
Expand Down
49 changes: 0 additions & 49 deletions src/post-submission-handlers/billing.resource.ts

This file was deleted.

0 comments on commit b065236

Please sign in to comment.