Skip to content

Commit

Permalink
Merge branch 'develop' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
neophyte57 committed Jan 23, 2024
2 parents a9e0798 + ef8531d commit 5160328
Show file tree
Hide file tree
Showing 24 changed files with 20,479 additions and 381 deletions.
2 changes: 2 additions & 0 deletions prime-angular-frontend/src/app/config/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Config<T> {

export interface CollegeConfig extends PracticeConfig {
collegeLicenses: CollegeLicenseConfig[];
weight: number;
}

export interface PracticeConfig extends Config<number> {
Expand All @@ -53,6 +54,7 @@ export interface CollegeLicenseConfig {
collegeCode: number;
licenseCode: number;
collegeLicenseGroupingCode: number;
discontinued: boolean;
}

export class CollegeLicenseGroupingConfig extends Config<number> implements IWeightedConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
class="pl-2"
*matCellDef="let row;">
{{ row.licenseCode | configCode: 'licenses' | default }}
{{ row.discontinued ? " - *Discontinued*" : ""}}
</td>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class LicenseClassesMaintenancePageComponent implements OnInit {
return {
collegeName: college.name,
licenseCode: collegeLicense.licenseCode,
discontinued: collegeLicense.discontinued,
...license
} as LicenseMaintenanceConfig;
}).sort(this.utilsService.sortByKey<LicenseMaintenanceConfig>('weight'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class OverviewComponent extends BaseEnrolmentPage implements OnInit {
&& !enrolment.enrolleeHealthAuthorities?.some(ha => ha.healthAuthorityCode),
expiredCertification: enrolment.certifications.some(cert => moment(cert.renewalDate).isBefore(moment())),
requiresLicenceUpdate: enrolment.certifications.some((cert: CollegeCertification) =>
!this.configService.licenses.some(l => l.code === cert.licenseCode && l.collegeLicenses.some(cl => cl.collegeCode === cert.collegeCode))),
this.configService.licenses.some(l => l.code === cert.licenseCode && l.collegeLicenses.some(cl => cl.collegeCode === cert.collegeCode && cl.discontinued))),
requireRedoSelfDeclaration: enrolment.requireRedoSelfDeclaration,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { FormArray, FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { CollegeCertification } from '@enrolment/shared/models/college-certification.model';

import { CollegeConfig } from '@config/config.model';
import { AbstractFormState } from '@lib/classes/abstract-form-state.class';
import { ConfigService } from '@config/config.service';
import { CollegeLicenceClassEnum } from '@shared/enums/college-licence-class.enum';

import { EnrolmentRegulatoryForm } from './enrolment-regulatory-form.model';
export class RegulatoryFormState extends AbstractFormState<EnrolmentRegulatoryForm> {
public colleges: CollegeConfig[];

public constructor(
protected fb: FormBuilder,
protected configService: ConfigService
) {
super();
this.buildForm();
this.colleges = this.configService.colleges;
}

public get certifications(): FormArray {
Expand Down Expand Up @@ -53,7 +57,7 @@ export class RegulatoryFormState extends AbstractFormState<EnrolmentRegulatoryFo

const { certifications: rawCertifications, deviceProviderId, deviceProviderRoleCode, certificationNumber } = this.formInstance.getRawValue();
let certifications = rawCertifications.map(c => {
const { nurseCategory, ...collegeCertification } = c;
const { category, ...collegeCertification } = c;
return collegeCertification;
});

Expand Down Expand Up @@ -101,7 +105,7 @@ export class RegulatoryFormState extends AbstractFormState<EnrolmentRegulatoryFo
return this.fb.group({
// Force selection of "None" on new certifications
collegeCode: ['', []],
nurseCategory: [null, []],
category: [null, []],
licenseCode: [null, []],
// Validators are applied at the component-level when
// fields are made visible to allow empty submissions
Expand All @@ -118,16 +122,16 @@ export class RegulatoryFormState extends AbstractFormState<EnrolmentRegulatoryFo
if (collegeCertification) {
// Nursing category is a derived field for BCCNM, which is used to filter the
// results for the verbose number of available licence codes for nurses
const nurseCategory = (collegeCertification.collegeCode === CollegeLicenceClassEnum.BCCNM)
const category = this.collegeHasGrouping(collegeCertification.collegeCode)
? this.configService.colleges
.find(c => c.code === CollegeLicenceClassEnum.BCCNM)
.find(c => c.code === collegeCertification.collegeCode)
.collegeLicenses
.filter(cl => cl.collegeCode === collegeCertification.collegeCode && cl.licenseCode === collegeCertification.licenseCode)
.shift()
.collegeLicenseGroupingCode
: null;

certification.patchValue({ ...collegeCertification, nurseCategory });
certification.patchValue({ ...collegeCertification, category });
}

this.certifications.push(certification);
Expand All @@ -136,4 +140,12 @@ export class RegulatoryFormState extends AbstractFormState<EnrolmentRegulatoryFo
public removeCollegeCertifications() {
this.certifications.clear();
}

public collegeHasGrouping(collegeCode: number): boolean {
if (collegeCode === 0) {
return false;
}
const college = this.colleges.find((c) => c.code === collegeCode);
return college ? college.collegeLicenses.some((l) => l.collegeLicenseGroupingCode) : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class RegulatoryFormState extends BaseRegulatoryPageFormState {
} = this.formInstance.getRawValue();

const certifications = rawCertifications.map(c => {
const { nurseCategory, ...collegeCertification } = c;
const { category, ...collegeCertification } = c;
return collegeCertification;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class RegulatoryFormState extends AbstractFormState<RegulatoryForm> {
return this.fb.group({
// Force selection of "None" on new certifications
collegeCode: ['', [Validators.required]],
nurseCategory: [null, []],
category: [null, []],
licenseCode: [null, []],
// Validators are applied at the component-level when
// fields are made visible to allow empty submissions
Expand All @@ -87,7 +87,7 @@ export class RegulatoryFormState extends AbstractFormState<RegulatoryForm> {
if (collegeCertification) {
// Nursing category is a derived field for BCCNM, which is used to filter the
// results for the verbose number of available licence codes for nurses
const nurseCategory = (collegeCertification.collegeCode === CollegeLicenceClassEnum.BCCNM)
const category = (collegeCertification.collegeCode === CollegeLicenceClassEnum.BCCNM)
? this.configService.colleges
.find(c => c.code === CollegeLicenceClassEnum.BCCNM)
.collegeLicenses
Expand All @@ -96,7 +96,7 @@ export class RegulatoryFormState extends AbstractFormState<RegulatoryForm> {
.collegeLicenseGroupingCode
: null;

certification.patchValue({ ...collegeCertification, nurseCategory });
certification.patchValue({ ...collegeCertification, category });
}

this.certifications.push(certification);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
<app-alert *ngIf="licenseClassDiscontinued"
type="danger"
icon="warning"
class="mb-4">
<ng-container #alertContent
class="alert-content">
{{ this.collegeDiscontinued ?
"The name of your college has changed. Please select the new name from the dropdown list for college name, " +
"then " : "Your previous licence class is no longer available, please " }}
use the dropdown menu to select the licence you currently hold.
</ng-container>
</app-alert>

<ng-container [formGroup]="form">

<app-form-icon-group [show]="total > 1"
(event)="removeCertification()">

<ng-template #collegeLicences>
<mat-form-field class="w-100">
<mat-label>College Licences</mat-label>
<mat-label>College</mat-label>
<mat-select formControlName="collegeCode">
<mat-option *ngIf="!condensed && defaultOption"
value="">
Expand Down Expand Up @@ -38,22 +51,22 @@
</div>

<div class="col-sm-12">
<ng-container *ngIf="!condensed && collegeCode?.value === CollegeLicenceClassEnum.BCCNM">
<ng-container *ngIf="!condensed && collegeHasGrouping(collegeCode?.value)">
<mat-form-field class="w-100">
<mat-label>Nurse Category</mat-label>
<mat-select formControlName="nurseCategory">
<mat-option *ngFor="let group of nurseGroups"
<mat-label>Category</mat-label>
<mat-select formControlName="category">
<mat-option *ngFor="let group of getGrouping(collegeCode?.value)"
[value]="group.code">
{{ group.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="nurseCategory.hasError('required')">Required</mat-error>
<mat-error *ngIf="category.hasError('required')">Required</mat-error>
</mat-form-field>
</ng-container>
</div>

<ng-container
*ngIf="collegeCode.value !== CollegeLicenceClassEnum.BCCNM && collegeCode.value || collegeCode.value === CollegeLicenceClassEnum.BCCNM && (condensed || nurseCategory?.value)">
*ngIf="!collegeHasGrouping(collegeCode?.value) && collegeCode.value || collegeHasGrouping(collegeCode?.value) && (condensed || category?.value)">
<div *ngIf="showLicenceClass()"
class="col-sm-12 pl-5">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ export class CollegeCertificationFormComponent implements OnInit {
public practices: PracticeConfig[];
public filteredLicenses: Config<number>[];
public filteredPractices: Config<number>[];
public nurseGroups: CollegeLicenseGroupingConfig[];
public licenseGroups: CollegeLicenseGroupingConfig[];
public hasPractices: boolean;
public licenseClassDiscontinued: boolean;
public collegeDiscontinued: boolean;

/**
* @description
* Indicates the prescriber ID (PharmaNet) type associated with a
Expand All @@ -64,10 +67,18 @@ export class CollegeCertificationFormComponent implements OnInit {
private enrolmentService: EnrolmentService
) {
this.remove = new EventEmitter<number>();
this.colleges = this.configService.colleges;
this.licenses = this.configService.licenses;
this.licenses = this.configService.licenses.filter(l => l.collegeLicenses.filter(cl => cl.discontinued).length === 0);
var collegeCodes: Array<number> = [];
this.configService.licenses.forEach(l => {
l.collegeLicenses.forEach(cl => {
if (!cl.discontinued && !collegeCodes.some(cc => cc === cl.collegeCode)) {
collegeCodes.push(cl.collegeCode);
}
});
});
this.colleges = this.configService.colleges.filter(c => collegeCodes.some(cc => cc === c.code));
this.practices = this.configService.practices;
this.nurseGroups = this.configService.collegeLicenseGroupings;
this.licenseGroups = this.configService.collegeLicenseGroupings;
this.minRenewalDate = (this.enrolmentService.isProfileComplete) ? null : moment();
this.condensed = false;
this.defaultOption = true;
Expand All @@ -81,8 +92,8 @@ export class CollegeCertificationFormComponent implements OnInit {
return this.form.get('collegeCode') as FormControl;
}

public get nurseCategory(): FormControl {
return this.form.get('nurseCategory') as FormControl;
public get category(): FormControl {
return this.form.get('category') as FormControl;
}

public get licenseNumber(): FormControl {
Expand Down Expand Up @@ -110,6 +121,19 @@ export class CollegeCertificationFormComponent implements OnInit {
return this.form.get('practiceCode') as FormControl;
}

public getGrouping(collegeCode: string): CollegeLicenseGroupingConfig[] {
let groupingCodes = this.colleges.find((c) => c.code === +collegeCode).collegeLicenses.map((l) => l.collegeLicenseGroupingCode);
return this.licenseGroups.filter((g) => groupingCodes.some((gc) => gc === g.code));
}

public collegeHasGrouping(collegeCode: string): boolean {
if (collegeCode === '') {
return false;
}
const college = this.colleges.find((c) => c.code === +collegeCode);
return college ? college.collegeLicenses.some((l) => l.collegeLicenseGroupingCode) : false;
}

public get filteredColleges(): CollegeConfig[] {
return this.colleges.filter((college: CollegeConfig) =>
// Allow the currently chosen value to persist
Expand All @@ -119,8 +143,8 @@ export class CollegeCertificationFormComponent implements OnInit {

public allowedColleges(): CollegeConfig[] {
return (this.collegeFilterPredicate)
? this.filteredColleges.filter(this.collegeFilterPredicate)
: this.filteredColleges;
? this.filteredColleges.filter(this.collegeFilterPredicate).sort((a, b) => a.weight - b.weight)
: this.filteredColleges.sort((a, b) => a.weight - b.weight);
}

public allowedLicenses() {
Expand Down Expand Up @@ -159,6 +183,8 @@ export class CollegeCertificationFormComponent implements OnInit {

// TODO decouple default and condensed modes in controller and template
public ngOnInit() {
this.checkLicenseIfDiscontinued();

if (this.condensed) {
this.formUtilsService.setValidators(this.collegeCode, [Validators.required]);
}
Expand All @@ -185,8 +211,8 @@ export class CollegeCertificationFormComponent implements OnInit {
}
});

const initialNursingCategory = +this.nurseCategory.value ?? null;
this.nurseCategory.valueChanges
const initialNursingCategory = +this.category.value ?? null;
this.category.valueChanges
.pipe(
startWith(initialNursingCategory),
tap((collegeLicenseGroupingCode: number | null) => (collegeLicenseGroupingCode) ? this.clearNursingCategoryValidators() : null),
Expand All @@ -198,7 +224,7 @@ export class CollegeCertificationFormComponent implements OnInit {
)
.subscribe((collegeLicenseGroupingCode: number) => {
this.setNursingCategoryValidators();
this.loadLicensesByNursingCategory(collegeLicenseGroupingCode);
this.loadLicensesByCategory(collegeLicenseGroupingCode);
});
} else {
const prescriberIdType = this.enrolmentService.getPrescriberIdType(this.licenseCode.value);
Expand All @@ -213,14 +239,14 @@ export class CollegeCertificationFormComponent implements OnInit {
return;
}

if (collegeCode === CollegeLicenceClassEnum.BCCNM && !this.condensed) {
this.formUtilsService.setValidators(this.nurseCategory, [Validators.required]);
if ((collegeCode === CollegeLicenceClassEnum.BCCNM || collegeCode === CollegeLicenceClassEnum.OralHealth) && !this.condensed) {
this.formUtilsService.setValidators(this.category, [Validators.required]);
return;
}

// In case previous selection was BCCNM, clear validators
if (!this.condensed) {
this.formUtilsService.setValidators(this.nurseCategory, []);
this.formUtilsService.setValidators(this.category, []);
this.clearNursingCategoryValidators();
}

Expand Down Expand Up @@ -261,11 +287,15 @@ export class CollegeCertificationFormComponent implements OnInit {

private resetCollegeCertification() {
this.licenseCode.reset(null);
this.licenseNumber.reset(null);
if (!this.licenseClassDiscontinued) {
this.licenseNumber.reset(null);
}

if (!this.condensed) {
this.nurseCategory.reset(null);
this.renewalDate.reset(null);
this.category.reset(null);
if (!this.licenseClassDiscontinued) {
this.renewalDate.reset(null);
}
this.practiceCode.reset(null);
this.resetPractitionerIdStateAndValidators();
}
Expand Down Expand Up @@ -343,24 +373,24 @@ export class CollegeCertificationFormComponent implements OnInit {
this.formUtilsService.setValidators(this.licenseNumber, []);

if (!this.condensed) {
this.formUtilsService.setValidators(this.nurseCategory, []);
this.formUtilsService.setValidators(this.category, []);
this.formUtilsService.setValidators(this.renewalDate, []);
this.formUtilsService.setValidators(this.practitionerId, []);
}
}

private loadLicenses(collegeCode: number) {
if (collegeCode !== CollegeLicenceClassEnum.BCCNM || this.condensed) {
if (!this.collegeHasGrouping(collegeCode.toString()) || this.condensed) {
this.filteredLicenses = this.filterLicenses(collegeCode);
this.licenseCode.patchValue(this.licenseCode.value || null, { emitEvent: false });
}
}

private loadLicensesByNursingCategory(nursingCategory: number) {
private loadLicensesByCategory(category: number) {
const collegeCode = this.collegeCode.value;
if (collegeCode === CollegeLicenceClassEnum.BCCNM) {
if (this.collegeHasGrouping(collegeCode)) {
this.loadPractices(collegeCode);
this.filteredLicenses = this.filterLicensesByGrouping(nursingCategory);
this.filteredLicenses = this.filterLicensesByGrouping(category);
this.licenseCode.patchValue(this.licenseCode.value || null, { emitEvent: false });
}
}
Expand All @@ -382,4 +412,18 @@ export class CollegeCertificationFormComponent implements OnInit {
private filterPractices(collegeCode: number): PracticeConfig[] {
return this.practices.filter(p => p.collegePractices.map(cl => cl.collegeCode).includes(collegeCode));
}


private checkLicenseIfDiscontinued() {
if (this.collegeCode.value && this.licenseCode.value) {
this.licenseClassDiscontinued = this.isCertificationDiscontinued(this.collegeCode.value, this.licenseCode.value);
//check if the current college code is in the valid college list. If not, the current college is discontinued.
this.collegeDiscontinued = !this.colleges.some(c => c.code === this.collegeCode.value);
}
}

private isCertificationDiscontinued(collegeCode: number, licenseCode: number): boolean {
let license = this.configService.licenses.find(l => l.code === licenseCode);
return license.collegeLicenses.find(cl => cl.collegeCode === collegeCode && cl.licenseCode === licenseCode).discontinued;
}
}
Loading

0 comments on commit 5160328

Please sign in to comment.