Skip to content

Commit e5b3e8d

Browse files
committed
fix some pr comments
1 parent fa3f325 commit e5b3e8d

File tree

9 files changed

+48
-63
lines changed

9 files changed

+48
-63
lines changed

apps/ehr/src/pages/reports/InvoiceablePatients.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export default function InvoiceablePatients(): React.ReactElement {
106106
const pageSP = Number(searchParams.get('page') ?? '0');
107107
const statusSP = searchParams.get('status');
108108
const patientSP = searchParams.get('patient');
109-
console.log('patient sp changed, ', patientSP);
110109

111110
const handleBack = (): void => {
112111
navigate('/reports');

packages/utils/lib/helpers/tasks/invoices-tasks.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ export function parseInvoiceTaskInput(invoiceTask: Task): InvoiceTaskInput {
3030
const claimId = getInvoiceTaskInputFieldByCode('claimId', invoiceTask);
3131
const finalizationDate = getInvoiceTaskInputFieldByCode('finalizationDate', invoiceTask);
3232

33-
return InvoiceTaskInputSchema.parse({
33+
const taskInput: InvoiceTaskInput = {
3434
dueDate,
3535
memo,
3636
smsTextMessage,
37-
amount,
3837
claimId,
3938
finalizationDate,
40-
});
39+
amountCents: parseInt(amount ?? '0'),
40+
};
41+
return InvoiceTaskInputSchema.parse(taskInput);
4142
}
4243

4344
function getInvoiceTaskInputFieldByCode(code: keyof InvoiceTaskInput, task: Task): string | undefined {

packages/utils/lib/types/api/invoicing.types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ import { Secrets } from '../../secrets';
55
export const INVOICEABLE_PATIENTS_PAGE_SIZE = 40;
66
export const GET_INVOICES_TASKS_ZAMBDA_KEY = 'get-invoices-tasks';
77

8-
export const InvoiceTaskDisplayStatuses = ['ready', 'updating', 'sending', 'sent', 'error'];
8+
export const InvoiceTaskDisplayStatuses = ['ready', 'updating', 'sending', 'sent', 'error'] as const;
99
export type InvoiceTaskDisplayStatus = (typeof InvoiceTaskDisplayStatuses)[number];
1010

1111
export const InvoiceTaskInputSchemaBase = z.object({
1212
dueDate: z.string(),
1313
memo: z.string(),
1414
smsTextMessage: z.string(),
15-
amountCents: z.number().gt(0),
15+
amountCents: z.number(),
1616
claimId: z.string().optional(),
1717
finalizationDate: z.string().optional(),
1818
});
1919
export const InvoiceTaskInputSchema = InvoiceTaskInputSchemaBase.partial();
2020
export type InvoiceTaskInput = z.infer<typeof InvoiceTaskInputSchema>;
2121
export const SubSendInvoiceToPatientTaskInputSchema = InvoiceTaskInputSchemaBase.extend({
2222
memo: z.string().optional(),
23+
amountCents: z.number().gt(0),
2324
});
2425
export type SubSendInvoiceToPatientTaskInput = z.infer<typeof SubSendInvoiceToPatientTaskInputSchema>;
2526

packages/zambdas/src/cron/create-invoices-tasks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const index = wrapHandler(ZAMBDA_NAME, async (input: ZambdaInput): Promis
7373
}
7474
});
7575

76-
async function getPrefilledInvoiceInfo(
76+
async function getInvoiceTaskInput(
7777
claimId: string,
7878
finalizationDate: Date,
7979
patientBalanceInCents: number
@@ -104,7 +104,7 @@ export async function createTaskForEncounter(oystehr: Oystehr, encounterPkg: Enc
104104
const { encounter, claim, amountCents } = encounterPkg;
105105
const patientId = encounter.subject?.reference?.replace('Patient/', '');
106106
if (!patientId) throw new Error('Patient ID not found in encounter: ' + encounter.id);
107-
const prefilledInvoiceInfo = await getPrefilledInvoiceInfo(claim.claimId, claim.timestamp, amountCents);
107+
const prefilledInvoiceInfo = await getInvoiceTaskInput(claim.claimId, claim.timestamp, amountCents);
108108
console.log(
109109
`Creating task. patient: ${claim.patientExternalId}, claim: ${claim.claimId}, oyst encounter: ${encounter.id} balance (cents): ${amountCents}`
110110
);

packages/zambdas/src/ehr/get-invoices-tasks/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const index = wrapHandler(ZAMBDA_NAME, async (input: ZambdaInput): Promis
7070
const oystehr = createOystehrClient(m2mToken, secrets);
7171

7272
const fhirSearchStart = performance.now();
73-
const fhirResources = await getFhirResourcesGroupped(oystehr, validatedParams);
73+
const fhirResources = await getFhirResourcesGrouped(oystehr, validatedParams);
7474
const fhirSearchEnd = performance.now();
7575
const taskGroups = fhirResources.taskGroups;
7676

@@ -115,10 +115,19 @@ function performEffect(taskGroups: TaskGroup[], total: number): GetInvoicesTasks
115115
}
116116
const visitDate = formatDateConfigurable({ isoDate: appointment?.start, timezone });
117117

118+
const relatedPerson = resources.find(
119+
(resource) =>
120+
resource.resourceType === 'RelatedPerson' &&
121+
(resource as RelatedPerson).relationship?.find(
122+
(relationship) => relationship.coding?.find((code) => code.code === 'user-relatedperson')
123+
)
124+
) as RelatedPerson;
125+
const patientPhoneNumber = relatedPerson && getPhoneNumberForIndividual(relatedPerson);
126+
118127
reports.push({
119128
claimId: taskInput.claimId ?? '---',
120129
finalizationDate: taskInput.finalizationDate ?? '---',
121-
amountInvoiceable: `${taskInput.amountCents ?? 0 / 100}`,
130+
amountInvoiceable: `${(taskInput.amountCents ?? 0) / 100}`,
122131
visitDate: visitDate ?? '---',
123132
location: group.location?.name ?? '---',
124133
task: task,
@@ -127,7 +136,7 @@ function performEffect(taskGroups: TaskGroup[], total: number): GetInvoicesTasks
127136
fullName: patientName,
128137
dob: patientDob,
129138
gender: patientGenderLabel,
130-
phoneNumber: 'll', // todo this
139+
phoneNumber: patientPhoneNumber,
131140
},
132141
responsibleParty: {
133142
fullName: responsiblePartyName,
@@ -141,7 +150,7 @@ function performEffect(taskGroups: TaskGroup[], total: number): GetInvoicesTasks
141150
return { reports, totalCount: total };
142151
}
143152

144-
async function getFhirResourcesGroupped(
153+
async function getFhirResourcesGrouped(
145154
oystehr: Oystehr,
146155
complexValidatedInput: GetInvoicesTasksInput
147156
): Promise<{ taskGroups: TaskGroup[]; bundleTotal: number }> {

packages/zambdas/src/ehr/invoiceable-patients-report/index.ts

Whitespace-only changes.

packages/zambdas/src/subscriptions/task/sub-refresh-invoice-task/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ export const index = wrapHandler(ZAMBDA_NAME, async (input: ZambdaInput): Promis
6262
console.log(`Updated task input for task id: "${taskId}"`);
6363
}
6464

65-
console.error('Task was not updated because no inventory record was found for the task.'); // todo how i can better manage this situation
65+
console.warn('Task was not updated because no inventory record was found for the task.'); // todo how i can better manage this situation
66+
await oystehr.fhir.patch({
67+
resourceType: 'Task',
68+
id: taskId,
69+
operations: [{ op: 'replace', path: '/status', value: mapDisplayToInvoiceTaskStatus('error') }],
70+
});
71+
6672
return {
6773
statusCode: 200,
6874
body: JSON.stringify({ message: 'Task was not updated because no inventory record was found for the task.' }),

packages/zambdas/src/subscriptions/task/sub-update-invoice-task/index.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/populate-invoices-tasks-manually.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import Oystehr from '@oystehr/sdk';
21
import { CandidApiClient, CandidApiEnvironment } from 'candidhealth';
32
import { InventoryRecord } from 'candidhealth/api/resources/patientAr/resources/v1';
43
import fs from 'fs';
54
import { DateTime } from 'luxon';
65
import { getCandidInventoryPages } from 'utils';
7-
import { createTaskForEncounter, getEncountersWithoutTaskFhir } from 'zambdas/src/cron/create-invoices-tasks';
86

9-
async function createOyst(zambdaEnv: Record<string, string>, token: string): Promise<Oystehr> {
10-
const oystehr = new Oystehr({
11-
accessToken: token,
12-
projectId: zambdaEnv.PROJECT_ID,
13-
services: {
14-
fhirApiUrl: zambdaEnv.FHIR_API,
15-
projectApiUrl: zambdaEnv.PROJECT_API,
16-
},
17-
});
18-
console.log(`Created Oystehr client`);
19-
return oystehr;
20-
}
7+
// async function createOyst(zambdaEnv: Record<string, string>, token: string): Promise<Oystehr> {
8+
// const oystehr = new Oystehr({
9+
// accessToken: token,
10+
// projectId: zambdaEnv.PROJECT_ID,
11+
// services: {
12+
// fhirApiUrl: zambdaEnv.FHIR_API,
13+
// projectApiUrl: zambdaEnv.PROJECT_API,
14+
// },
15+
// });
16+
// console.log(`Created Oystehr client`);
17+
// return oystehr;
18+
// }
2119

2220
async function createCandid(
2321
zambdaEnv: Record<string, string>,
@@ -41,14 +39,14 @@ async function main(): Promise<void> {
4139
const candidEnv = environment === 'production' ? CandidApiEnvironment.Production : CandidApiEnvironment.Staging;
4240
const startFrom = DateTime.fromFormat('01/14/2026', 'MM/dd/yyyy');
4341
const endOn = startFrom.plus({ weeks: 2 });
44-
const token = '<a-key-from-ottehr-console-here>';
42+
// const token = '<a-key-from-ottehr-console-here>';
4543
const maxCandidPages = 18;
4644

4745
console.log(`Reading environment variables from packages/zambdas/.env/${environment}.json.`);
4846
const zambdaEnv: Record<string, string> = JSON.parse(
4947
fs.readFileSync(`packages/zambdas/.env/${environment}.json`, 'utf8')
5048
);
51-
const oystehr = await createOyst(zambdaEnv, token);
49+
// const oystehr = await createOyst(zambdaEnv, token);
5250
const candid = await createCandid(zambdaEnv, candidEnv);
5351

5452
let candidClaims = await getAllCandidClaims(candid, startFrom, maxCandidPages);
@@ -65,13 +63,13 @@ async function main(): Promise<void> {
6563
}
6664
console.log(`Found ${candidClaims.length} claims between ${firstDate} and ${lastDate}`);
6765

68-
const pkgs = await getEncountersWithoutTaskFhir(oystehr, candid, candidClaims);
69-
console.log('Encounters without a task and positive amount: ', pkgs.length);
66+
// const pkgs = await getEncountersWithoutTaskFhir(oystehr, candid, candidClaims);
67+
// console.log('Encounters without a task and positive amount: ', pkgs.length);
7068

7169
const promises: Promise<void>[] = [];
72-
pkgs.forEach((encounter) => {
73-
promises.push(createTaskForEncounter(oystehr, encounter));
74-
});
70+
// pkgs.forEach((encounter) => {
71+
// promises.push(createTaskForEncounter(oystehr, encounter));
72+
// });
7573
await Promise.all(promises);
7674
}
7775

0 commit comments

Comments
 (0)