Skip to content

Commit

Permalink
Merge branch 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
neophyte57 committed Oct 23, 2023
2 parents 314921b + 974ad77 commit 1ed7856
Show file tree
Hide file tree
Showing 17 changed files with 499 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ export class SiteResource {
);
}

public updateVendor(siteId: number, vendorCode: number, rationale: string): NoContent {
const payload = { vendorCode, rationale };
return this.apiResource.put<NoContent>(`sites/${siteId}/vendor`, payload)
.pipe(
NoContentResponse,
tap(() => this.toastService.openSuccessToast('Vendor has been updated')),
catchError((error: any) => {
this.toastService.openErrorToast('Vendor could not be updated');
this.logger.error('[SiteRegistration] SiteResource::updateVendor error has occurred: ', error);
throw error;
})
);
}

public setSiteAdjudicator(siteId: number, adjudicatorId?: number): NoContent {
const params = this.apiResourceUtilsService.makeHttpParams({ adjudicatorId });
return this.apiResource.put<NoContent>(`sites/${siteId}/adjudicator`, null, params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</ng-container>
</app-page-subheader2>

<form (ngSubmit)="onSubmit()"
<form (ngSubmit)="saveSiteId()"
[formGroup]="form"
novalidate>

Expand Down Expand Up @@ -66,4 +66,37 @@

</form>
</app-page-section>

<app-page-section class="mb-5">
<app-page-subheader2>
<ng-container appPageSubheader2Title>Enter Vendor</ng-container>
</app-page-subheader2>

<form (ngSubmit)="saveVendor()"
[formGroup]="form"
novalidate>

<div class="row">
<div class="col-sm-12 col-lg-9 col-xl-5 pb-2">

<mat-form-field class="w-100">
<mat-select placeholder="Vendor"
formControlName="vendors">
<mat-option *ngFor="let vendor of healthAuthorityVendors"
[value]="vendor">{{ vendor.name }}</mat-option>
</mat-select>
</mat-form-field>

</div>
<div class="col-sm-12">

<button mat-flat-button
color="primary">Save Vendor
</button>

</div>
</div>

</form>
</app-page-section>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { RouterTestingModule } from '@angular/router/testing';

import { APP_CONFIG, APP_DI_CONFIG } from 'app/app-config.module';
import { MockPermissionService } from 'test/mocks/mock-permission.service';
import { MockConfigService } from 'test/mocks/mock-config.service';

import { NgxMaterialModule } from '@lib/modules/ngx-material/ngx-material.module';

import { PermissionService } from '@auth/shared/services/permission.service';
import { CapitalizePipe } from '@shared/pipes/capitalize.pipe';
import { ConfigService } from '@config/config.service';

import { SiteOverviewPageComponent } from './site-overview-page.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
Expand Down Expand Up @@ -38,6 +40,10 @@ describe('SiteOverviewPageComponent', () => {
provide: PermissionService,
useClass: MockPermissionService
},
{
provide: ConfigService,
useClass: MockConfigService
},
CapitalizePipe
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { HealthAuthoritySite } from '@health-auth/shared/models/health-authority-site.model';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { BehaviorSubject, mergeMap, Observable, Subscription } from 'rxjs';

import { HealthAuthorityResource } from '@core/resources/health-authority-resource.service';
import { FormUtilsService } from '@core/services/form-utils.service';
import { SiteResource } from '@core/resources/site-resource.service';
import { asyncValidator } from '@lib/validators/form-async.validators';

import { HealthAuthoritySiteAdmin } from '@health-auth/shared/models/health-authority-admin-site.model';
import { VendorConfig } from '@config/config.model';
import { ConfigService } from '@config/config.service';
import { DialogOptions } from '@shared/components/dialogs/dialog-options.model';
import { ChangeVendorNoteComponent } from '@shared/components/dialogs/content/change-vendor-note/change-vendor-note.component';
import { MatDialog } from '@angular/material/dialog';
import { HealthAuthority } from '@shared/models/health-authority.model';

interface HealthAuthorityVendorMap extends VendorConfig {
id?: number;
}
@Component({
selector: 'app-site-overview-page',
templateUrl: './site-overview-page.component.html',
Expand All @@ -18,15 +28,19 @@ import { HealthAuthoritySiteAdmin } from '@health-auth/shared/models/health-auth
export class SiteOverviewPageComponent implements OnInit {
public busy: Subscription;
public site: HealthAuthoritySiteAdmin;
public healthAuthoritySite: HealthAuthoritySite;
public form: FormGroup;
public healthAuthorityVendors: HealthAuthorityVendorMap[];
public refresh: BehaviorSubject<boolean>;

constructor(
private healthAuthorityResource: HealthAuthorityResource,
private route: ActivatedRoute,
private formUtilsService: FormUtilsService,
private fb: FormBuilder,
private configService: ConfigService,
private siteResource: SiteResource,
private dialog: MatDialog,
) {
this.refresh = new BehaviorSubject<boolean>(null);
}
Expand All @@ -35,8 +49,12 @@ export class SiteOverviewPageComponent implements OnInit {
return this.form.get('pec') as FormControl;
}

public onSubmit(): void {
if (this.formUtilsService.checkValidity(this.form)) {
public get vendors(): FormControl {
return this.form.get('vendors') as FormControl;
}

public saveSiteId(): void {
if (this.pec.valid) {
const siteId = +this.route.snapshot.params.sid;
const pec = this.form.value.pec;
this.busy = this.siteResource.updatePecCode(siteId, pec)
Expand All @@ -47,16 +65,56 @@ export class SiteOverviewPageComponent implements OnInit {
}
}

public saveVendor(): void {
const vendor = this.vendors.value;
const existingVendor = this.healthAuthorityVendors.find((vendor: VendorConfig) => vendor.code === this.site.healthAuthorityVendor.vendorCode).name;

if (this.vendors.valid && vendor.name !== existingVendor) {
const siteId = +this.route.snapshot.params.sid;
const vendorChangeText = `from ${existingVendor} to ${vendor.name}`;

const data: DialogOptions = {
data: {
siteId,
vendorCode: vendor.code,
vendorChangeText
}
};
this.dialog.open(ChangeVendorNoteComponent, { data }).afterClosed()
.subscribe((vendorChanged: boolean) => {
if (vendorChanged) {
this.refresh.next(true);
this.site.healthAuthorityVendor.vendorCode = vendor.code;
}
});
}
}

public ngOnInit(): void {
this.createFormInstance();

this.busy = this.healthAuthorityResource
.getHealthAuthorityAdminSite(+this.route.snapshot.params.haid, +this.route.snapshot.params.sid)
.subscribe((site: HealthAuthoritySiteAdmin) => {
this.site = site;
this.initForm(site);
.pipe(
mergeMap((site: HealthAuthoritySiteAdmin) => {
this.site = site;
return this.healthAuthorityResource
.getHealthAuthorityById(this.site.healthAuthorityOrganizationId);
}),
)
.subscribe((hao: HealthAuthority) => {
let careTypeVendors = hao.careTypes.find(t => t.careType === this.site.healthAuthorityCareType.careType).vendors;
this.healthAuthorityVendors = this.configService.vendors
.filter((vendorConfig: VendorConfig) => careTypeVendors.findIndex(v => v.vendorCode === vendorConfig.code) >= 0) as HealthAuthorityVendorMap[];

const vendor = this.healthAuthorityVendors
.find((vendorConfig: VendorConfig) =>
vendorConfig.code == this.site.healthAuthorityVendor.vendorCode
);
this.initForm(this.site, vendor);
});

this.vendors.markAsTouched();
this.pec.markAsTouched();
}

Expand All @@ -66,12 +124,13 @@ export class SiteOverviewPageComponent implements OnInit {
'',
[Validators.required],
asyncValidator(this.checkPecIsAssignable(), 'assignable')
]
],
vendors: ['', [Validators.required]]
});
}

private initForm({ pec }: HealthAuthoritySiteAdmin): void {
this.form.patchValue({ pec });
private initForm({ pec }: HealthAuthoritySiteAdmin, vendor: VendorConfig): void {
this.form.patchValue({ pec, 'vendors': vendor });
}

private checkPecIsAssignable(): (value: string) => Observable<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
</ng-container>
</app-page-subheader2>

<form (ngSubmit)="onSubmit()"
<form (ngSubmit)="saveSiteId()"
[formGroup]="form"
novalidate>

Expand Down Expand Up @@ -151,6 +151,39 @@
</form>
</app-page-section>

<app-page-section class="mb-5">
<app-page-subheader2>
<ng-container appPageSubheader2Title>Enter Vendor</ng-container>
</app-page-subheader2>

<form (ngSubmit)="saveVendor()"
[formGroup]="form"
novalidate>

<div class="row">
<div class="col-sm-12 col-lg-9 col-xl-5 pb-2">

<mat-form-field class="w-100">
<mat-select placeholder="Vendor"
formControlName="vendors">
<mat-option *ngFor="let vendor of siteVendors"
[value]="vendor">{{ vendor.name }}</mat-option>
</mat-select>
</mat-form-field>

</div>
<div class="col-sm-12">

<button mat-flat-button
color="primary">Save Vendor
</button>

</div>
</div>

</form>
</app-page-section>

<app-page-section *ngIf="showSendNotification"
class="mb-5">
<app-page-subheader2>
Expand Down
Loading

0 comments on commit 1ed7856

Please sign in to comment.