Skip to content

Commit

Permalink
refactor: some getParent()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Honlet committed Nov 12, 2024
1 parent 7e56bad commit cd09a2d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/app-patient/blocs/file-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default function FilePanel({
{file instanceof PatientRelated &&
!addMode &&
(!(file instanceof Patient) ||
folder.getFilesRelatedToPatient().length == 0) && (
folder.getChildren().length == 0) && (
<ActionConfirm
style="Delete"
discrete={true}
Expand Down
5 changes: 2 additions & 3 deletions src/app-patient/folder-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function FolderElement({
mode?: string;
}): React.ReactNode {
const [folder, folderUpdated] = useState<Folder>(initialFolder);
const patient = folder.getPatient();

const folderUpdatedCallback = (folder: Folder | undefined) => {
if (folder) {
Expand Down Expand Up @@ -118,9 +117,9 @@ export default function FolderElement({
<IO.Date label="Next appointment" value={folder.getNextAppointment()} />
</Panel>

{patientElementGenerator(patient, commonProps)}
{patientElementGenerator(folder.getPatient(), commonProps)}

{(folder.getFilesRelatedToPatient() as PatientRelated[]).map(
{(folder.getChildren() as PatientRelated[]).map(
(file: PatientRelated) => {
if (file instanceof Appointment) {
return appointmentElementGenerator(file, commonProps);
Expand Down
76 changes: 0 additions & 76 deletions src/business/bill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ export default class Bill extends Timed {
return getSession()?.prices?.[this.price_id] ?? null;
}

// getTotalForCategory(category: string) {
// return this.items
// .filter((item) => item.category === category)
// .reduce(
// (total: number, item: BillLine) =>
// total + item.value * this.getPriceFor(item.key),
// 0
// );
// }

social_level_calculated() {
/**
From TC:
Expand Down Expand Up @@ -106,64 +96,6 @@ export default class Bill extends Timed {
return 4;
}

// // Legacy
// get_total_real() {
// if (!this.getPrice()) {
// this.total_real = 0;
// this.total_asked = 0;
// return -1;
// }
// let total = 0;
// for (const i in this.getPrice()) {
// if (i[0] === "_") {
// continue;
// }
// if (i === "id") {
// continue;
// }
// if (i === "created_at") {
// continue;
// }
// if (i === "updated_at") {
// continue;
// }
// if (i === "last_user") {
// continue;
// }
// if (i === "date_from") {
// continue;
// }
// if (i === "date_to") {
// continue;
// }
// if (i === "controller") {
// continue;
// }
// if (i === "locked") {
// continue;
// }
// if (i === "dlocked") {
// continue;
// }
// if (i.startsWith("social_level_")) {
// continue;
// }
// if (this.getPrice()[i] < 0) {
// continue;
// }
// if (typeof this[i] === "undefined") {
// continue;
// }
// if (this[i] <= 0) {
// continue;
// }
// total += this.getPrice()[i] * this[i];
// } //, this);
// this.total_real = total;
// this.total_asked = this.total_real * this.calculate_percentage_asked();
// return this.total_real;
// }

get_percentage_asked(): number {
if (!this.getPrice()) {
//console.warn('calculate_percentage_asked(): no price id');
Expand Down Expand Up @@ -191,14 +123,6 @@ export default class Bill extends Timed {
return this.getPrice()[key];
}

// // Legacy
// getTotalFor(key: string): number {
// if (!this.getPrice()) return 0;
// if (!this.getPrice()[key]) return 0;
// if (!this[key]) return 0;
// return this.getPrice()[key] * this[key];
// }

getTotalAlreadyPaid() {
return this.getPayments().reduce(
(acc: number, payment: Payment) => acc + payment.amount,
Expand Down
72 changes: 34 additions & 38 deletions src/business/folder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import test, { beforeEach } from "node:test";
import { loadReferenceFolder, RefFolder1 } from "../test-helper";
import PatientRelated from "./abstracts/patient-related";
import Appointment from "./appointment";
import Bill from "./bill";
import ConsultOther from "./consult-other";
import ConsultRicket from "./consult-ricket";
import Folder from "./folder";
import Patient from "./patient";
import Payment from "./payment";
import Picture from "./picture";
import Surgery from "./surgery";

let f: Folder = new Folder();

Expand Down Expand Up @@ -47,46 +43,46 @@ test("should return null if element is not found (consult_other.0)", () => {
});

test("should give patient related files", () => {
const list = f.getFilesRelatedToPatient();
const list = f.getChildren();
assert.equal(list.length, 6);

list.forEach((e) => {
assert.equal(e.getPatient()?.id, 1);
});

let i = -1;
i++;
assert(list[i] instanceof Appointment);
assert.equal(list[i].id, 2);
assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Appointment).id);

i++;
assert(list[i] instanceof Picture);
assert.equal(list[i].id, 2);
assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Picture).id);

i++;
assert(list[i] instanceof ConsultRicket);
assert.equal(list[i].id, 13);
assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as ConsultRicket).id);

i++;
assert(list[i] instanceof Surgery);
assert.equal(list[i].id, 5);
assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Surgery).id);

i++;
assert(list[i] instanceof Bill);
assert.equal(list[i].id, 1);
assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Bill).id);

i++;
assert(list[i] instanceof ConsultOther);
assert.equal(list[i].id, 1);
assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as ConsultOther).id);

// And out of bounds...
assert.throws(() => f.getFileRelatedToPatient(1000));
// let i = -1;
// i++;
// assert(list[i] instanceof Appointment);
// assert.equal(list[i].id, 2);
// assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Appointment).id);

// i++;
// assert(list[i] instanceof Picture);
// assert.equal(list[i].id, 2);
// assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Picture).id);

// i++;
// assert(list[i] instanceof ConsultRicket);
// assert.equal(list[i].id, 13);
// assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as ConsultRicket).id);

// i++;
// assert(list[i] instanceof Surgery);
// assert.equal(list[i].id, 5);
// assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Surgery).id);

// i++;
// assert(list[i] instanceof Bill);
// assert.equal(list[i].id, 1);
// assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as Bill).id);

// i++;
// assert(list[i] instanceof ConsultOther);
// assert.equal(list[i].id, 1);
// assert.equal(f.getFileRelatedToPatient(i)?.id, (list[i] as ConsultOther).id);

// // And out of bounds...
// assert.throws(() => f.getFileRelatedToPatient(1000));
});

test("should give bill related files", () => {
Expand Down
10 changes: 1 addition & 9 deletions src/business/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class Folder extends Pojo {
return list[0] as Patient;
}

getFilesRelatedToPatient(): PatientRelated[] {
getChildren(): PatientRelated[] {
if (!this.getPatient().id) {
return [];
}
Expand All @@ -171,14 +171,6 @@ export default class Folder extends Pojo {
);
}

getFileRelatedToPatient(i: number): PatientRelated {
const list = this.getFilesRelatedToPatient();
if (list.length > i) {
return list[i];
}
throw new Error(`Could not find ${i}} in getFileRelatedToPatient`);
}

// TODO: move this to bill
getFilesRelatedToBill(id?: string): Payment[] {
return this.getByFieldValue("bill_id", id).sort(
Expand Down

0 comments on commit cd09a2d

Please sign in to comment.