From 1a4e9428fae79a43fbd84180420790224c6c7fb0 Mon Sep 17 00:00:00 2001 From: josephatJ Date: Tue, 19 Nov 2024 14:00:26 +0300 Subject: [PATCH] Add lis price-list module and fix null pointer when setting price of an item --- .../icare/core/impl/ICareServiceImpl.java | 4 ++- .../laboratory/laboratory.component.html | 2 +- .../laboratory/laboratory.component.ts | 6 ++++ .../modules/settings/components/index.ts | 4 ++- .../lab-price-list-home.component.html | 17 +++++++++++ .../lab-price-list-home.component.scss | 0 .../lab-price-list-home.component.spec.ts | 23 +++++++++++++++ .../lab-price-list-home.component.ts | 24 ++++++++++++++++ .../modules/settings/containers/index.ts | 2 ++ ...b-price-list-home-container.component.html | 14 ++++++++++ ...b-price-list-home-container.component.scss | 0 ...rice-list-home-container.component.spec.ts | 23 +++++++++++++++ ...lab-price-list-home-container.component.ts | 28 +++++++++++++++++++ .../settings/settings-routing.module.ts | 5 ++++ .../maintenance/models/item-price.model.ts | 2 +- .../maintenance/models/pricing-item.model.ts | 4 +-- .../price-list/price-list.component.scss | 4 ++- .../price-list/price-list.component.ts | 9 +++--- .../app/store/effects/pricing-item.effects.ts | 7 +++++ 19 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.html create mode 100644 ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.scss create mode 100644 ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.spec.ts create mode 100644 ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.ts create mode 100644 ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.html create mode 100644 ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.scss create mode 100644 ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.spec.ts create mode 100644 ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.ts diff --git a/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java b/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java index 6e974f2ed..7164397d9 100644 --- a/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java +++ b/omods/core/api/src/main/java/org/openmrs/module/icare/core/impl/ICareServiceImpl.java @@ -257,7 +257,9 @@ public ItemPrice saveItemPrice(ItemPrice itemPrice) throws APIException { itemPrice.setPaymentType(paymentType); if (itemPrice.getPayable() != null && itemPrice.getPayablePaymentMode() == null) { throw new APIException("Payment mode for payable not provided"); - } else { + } else if (itemPrice.getPayablePaymentMode() != null + && itemPrice.getPayablePaymentMode().getUuid() != null + && conceptService.getConceptByUuid(itemPrice.getPayablePaymentMode().getUuid()) != null) { Concept payablePaymentMode = conceptService.getConceptByUuid(itemPrice.getPayablePaymentMode().getUuid()); itemPrice.setPayablePaymentMode(payablePaymentMode); } diff --git a/ui/src/app/modules/laboratory/laboratory.component.html b/ui/src/app/modules/laboratory/laboratory.component.html index e2f59dd21..7446884a7 100644 --- a/ui/src/app/modules/laboratory/laboratory.component.html +++ b/ui/src/app/modules/laboratory/laboratory.component.html @@ -252,7 +252,7 @@
+ + +
+

Payment types not set

+
+
diff --git a/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.scss b/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.spec.ts b/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.spec.ts new file mode 100644 index 000000000..c69bb6698 --- /dev/null +++ b/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LabPriceListHomeComponent } from './lab-price-list-home.component'; + +describe('LabPriceListHomeComponent', () => { + let component: LabPriceListHomeComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [LabPriceListHomeComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LabPriceListHomeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.ts b/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.ts new file mode 100644 index 000000000..b71897a06 --- /dev/null +++ b/ui/src/app/modules/laboratory/modules/settings/components/lab-price-list-home/lab-price-list-home.component.ts @@ -0,0 +1,24 @@ +import { Component, Input, OnInit } from "@angular/core"; +import { select, Store } from "@ngrx/store"; +import { Observable } from "rxjs"; +import { initiatePaymentTypes } from "src/app/store/actions/payment-type.actions"; +import { AppState } from "src/app/store/reducers"; +import { getAllPaymentTypes } from "src/app/store/selectors/payment-type.selectors"; + +@Component({ + selector: "app-lab-price-list-home", + templateUrl: "./lab-price-list-home.component.html", + styleUrl: "./lab-price-list-home.component.scss", +}) +export class LabPriceListHomeComponent implements OnInit { + @Input() paymentCategories: any[]; + paymentTypes$: Observable; + constructor(private store: Store) {} + ngOnInit(): void { + this.store.dispatch( + initiatePaymentTypes({ paymentCategories: this.paymentCategories }) + ); + + this.paymentTypes$ = this.store.pipe(select(getAllPaymentTypes)); + } +} diff --git a/ui/src/app/modules/laboratory/modules/settings/containers/index.ts b/ui/src/app/modules/laboratory/modules/settings/containers/index.ts index 1a819b701..60aea7875 100644 --- a/ui/src/app/modules/laboratory/modules/settings/containers/index.ts +++ b/ui/src/app/modules/laboratory/modules/settings/containers/index.ts @@ -1,3 +1,4 @@ +import { LabPriceListHomeContainerComponent } from "./lab-price-list-home-container/lab-price-list-home-container.component"; import { LabSystemSettingsComponent } from "./lab-system-settings/lab-system-settings.component"; import { LabsAndSectionsManagementComponent } from "./labs-and-sections-management/labs-and-sections-management.component"; import { OtherLabConfigurationsComponent } from "./other-lab-configurations/other-lab-configurations.component"; @@ -12,4 +13,5 @@ export const settingsContainers: any[] = [ LabSystemSettingsComponent, WorksheetManagementComponent, SystemLogsComponent, + LabPriceListHomeContainerComponent, ]; diff --git a/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.html b/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.html new file mode 100644 index 000000000..53de25b01 --- /dev/null +++ b/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.html @@ -0,0 +1,14 @@ +
+ + +
diff --git a/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.scss b/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.spec.ts b/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.spec.ts new file mode 100644 index 000000000..1a6875b6d --- /dev/null +++ b/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LabPriceListHomeContainerComponent } from './lab-price-list-home-container.component'; + +describe('LabPriceListHomeContainerComponent', () => { + let component: LabPriceListHomeContainerComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [LabPriceListHomeContainerComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LabPriceListHomeContainerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.ts b/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.ts new file mode 100644 index 000000000..e7bc79400 --- /dev/null +++ b/ui/src/app/modules/laboratory/modules/settings/containers/lab-price-list-home-container/lab-price-list-home-container.component.ts @@ -0,0 +1,28 @@ +import { Component, OnInit } from "@angular/core"; +import { Store } from "@ngrx/store"; +import { Observable } from "rxjs"; +import { loadConceptByUuid } from "src/app/store/actions"; +import { AppState } from "src/app/store/reducers"; +import { getConceptById } from "src/app/store/selectors"; + +@Component({ + selector: "app-lab-price-list-home-container", + templateUrl: "./lab-price-list-home-container.component.html", + styleUrl: "./lab-price-list-home-container.component.scss", +}) +export class LabPriceListHomeContainerComponent implements OnInit { + paymentCategories$: Observable; + constructor(private store: Store) {} + ngOnInit(): void { + // TODO: Save the uuid on global properties, and switch-map accordingly + this.store.dispatch( + loadConceptByUuid({ + uuid: "c95c1065-bcea-4a35-aee0-ca62906ec8e2", + fields: "custom:(uuid,display,setMembers:(uuid,display)", + }) + ); + this.paymentCategories$ = this.store.select(getConceptById, { + id: "c95c1065-bcea-4a35-aee0-ca62906ec8e2", + }); + } +} diff --git a/ui/src/app/modules/laboratory/modules/settings/settings-routing.module.ts b/ui/src/app/modules/laboratory/modules/settings/settings-routing.module.ts index a9676b702..351402c8b 100644 --- a/ui/src/app/modules/laboratory/modules/settings/settings-routing.module.ts +++ b/ui/src/app/modules/laboratory/modules/settings/settings-routing.module.ts @@ -1,12 +1,17 @@ import { NgModule } from "@angular/core"; import { Routes, RouterModule } from "@angular/router"; import { SettingsComponent } from "./settings/settings.component"; +import { LabPriceListHomeContainerComponent } from "./containers/lab-price-list-home-container/lab-price-list-home-container.component"; const routes: Routes = [ { path: "", component: SettingsComponent, }, + { + path: "price-list", + component: LabPriceListHomeContainerComponent, + }, ]; @NgModule({ diff --git a/ui/src/app/modules/maintenance/models/item-price.model.ts b/ui/src/app/modules/maintenance/models/item-price.model.ts index 59c04d0df..8b242c5ca 100644 --- a/ui/src/app/modules/maintenance/models/item-price.model.ts +++ b/ui/src/app/modules/maintenance/models/item-price.model.ts @@ -18,7 +18,7 @@ export class ItemPrice { } get display(): string { - return this.itemPriceDetails?.item?.display; + return this.itemPriceDetails?.item?.display?.replace("TEST_ORDERS:", ""); } get paymentType(): any { diff --git a/ui/src/app/modules/maintenance/models/pricing-item.model.ts b/ui/src/app/modules/maintenance/models/pricing-item.model.ts index 7df5ad035..b0dd3775a 100644 --- a/ui/src/app/modules/maintenance/models/pricing-item.model.ts +++ b/ui/src/app/modules/maintenance/models/pricing-item.model.ts @@ -1,4 +1,4 @@ -import { kebabCase } from 'lodash'; +import { kebabCase } from "lodash"; export interface PricingItemInterface { id: string; uuid: string; @@ -18,7 +18,7 @@ export class PricingItem { get display(): string { return ( - this.itemPriceDetails?.concept?.display || + this.itemPriceDetails?.concept?.display?.replace("TEST_ORDERS:", "") || this.itemPriceDetails?.drug?.display ); } diff --git a/ui/src/app/shared/components/price-list/price-list.component.scss b/ui/src/app/shared/components/price-list/price-list.component.scss index d3f5a12fa..24327b8e4 100644 --- a/ui/src/app/shared/components/price-list/price-list.component.scss +++ b/ui/src/app/shared/components/price-list/price-list.component.scss @@ -1 +1,3 @@ - +.price-list-container { + padding: 8px; +} diff --git a/ui/src/app/shared/components/price-list/price-list.component.ts b/ui/src/app/shared/components/price-list/price-list.component.ts index 233f06db0..cd71e290e 100644 --- a/ui/src/app/shared/components/price-list/price-list.component.ts +++ b/ui/src/app/shared/components/price-list/price-list.component.ts @@ -90,7 +90,10 @@ export class PriceListComponent implements OnInit, OnChanges { ngOnInit() { this.currentDepartmentId = this.departmentId; - this.isDrug = this.currentDepartmentId == "Drug" ? true : false; + this.isDrug = + this.currentDepartmentId && this.currentDepartmentId == "Drug" + ? true + : false; this.loadData(); this.priceListDepartments$ = @@ -153,7 +156,7 @@ export class PriceListComponent implements OnInit, OnChanges { panelClass: "custom-dialog-container", data: { pricingItems }, }); - this.trackActionForAnalytics('Add Price List: Open'); + this.trackActionForAnalytics("Add Price List: Open"); // TODO: Find best way in order to stop subscribing here dialog.afterClosed().subscribe((results) => { if (results) { @@ -213,8 +216,6 @@ export class PriceListComponent implements OnInit, OnChanges { (pricingItem: PricingItemInterface) => { this.addingPricingItem = false; this.store.dispatch(upsertPricingItem({ pricingItem })); - - }, () => { this.addingPricingItem = false; diff --git a/ui/src/app/store/effects/pricing-item.effects.ts b/ui/src/app/store/effects/pricing-item.effects.ts index db2fbbef6..df4239b72 100644 --- a/ui/src/app/store/effects/pricing-item.effects.ts +++ b/ui/src/app/store/effects/pricing-item.effects.ts @@ -68,6 +68,13 @@ export class PricingItemEffects { prices: priceItem?.prices.map((price) => { return { ...price, + item: { + ...price?.item, + display: price?.item?.display?.replace( + "TEST_ORDERS:", + "" + ), + }, paymentSchemeUuid: price?.paymentScheme?.uuid, }; }),