Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 418_improve_updatin…
Browse files Browse the repository at this point in the history
…g_of_patients

# Conflicts:
#	txmatching/web/frontend/src/app/components/patient-donor-detail/patient-donor-detail.component.scss
#	txmatching/web/frontend/src/app/components/patient-donor-detail/patient-donor-detail.component.ts
#	txmatching/web/frontend/src/app/services/patient/patient.service.ts
  • Loading branch information
tomaspavlin committed Feb 22, 2021
2 parents b36d852 + 9f4a564 commit 9eeb8d8
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ jobs:
id: docker_build
uses: docker/build-push-action@v2
with:
tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.AWS_ECR_REPOSITORY }}:${{ env.RELEASE_VERSION }}
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ env.AWS_ECR_REPOSITORY }}:${{ env.RELEASE_VERSION }}
${{ steps.login-ecr.outputs.registry }}/${{ env.AWS_ECR_REPOSITORY }}:latest
labels: ${{ steps.docker_meta.outputs.labels }}
push: true
build-args: |
Expand Down
2 changes: 1 addition & 1 deletion txmatching/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def add_headers(response):
if origin in allowed_origins:
response.headers.add('Access-Control-Allow-Origin', origin)
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,POST,PUT')
response.headers.add('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE')
return response

def log_request_performance():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@
[showActiveCheckbox]="true">
</app-donor-settings>

<app-button [type]="'submit'"
[loading]="loading"
[disabled]="loading"
[success]="!loading && success"
[variant]="'success'">Save changes
</app-button>
<div class="buttons">
<app-button [type]="'submit'"
[loading]="loading"
[disabled]="loading"
[success]="!loading && success"
[variant]="'success'">Save changes
</app-button>

<app-button [loading]="deleteLoading"
[disabled]="deleteLoading"
[success]="!deleteLoading && deleteSuccess"
[variant]="'danger'"
[size]="'sm'"
(click)="handleDeleteDonor()">
<fa-icon [icon]="deleteIcon"></fa-icon>&nbsp;Delete
</app-button>
</div>
</form>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@
form {
margin-top: $padding-y;
}

.buttons {
display: flex;
align-items: baseline;
justify-content: center;

& > * {
margin: 0 20px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TxmEvent } from '@app/model/Event';
import { LoggerService } from '@app/services/logger/logger.service';
import { DonorEditable } from '@app/model/DonorEditable';
import { AlertService } from '@app/services/alert/alert.service';
import { faTrash } from '@fortawesome/free-solid-svg-icons';

@Component({
selector: 'app-patient-detail-donor',
Expand All @@ -23,6 +24,9 @@ export class PatientDonorDetailComponent extends ListItemDetailAbstractComponent

public loading: boolean = false;
public success: boolean = false;
public deleteLoading: boolean = false;
public deleteSuccess: boolean = false;
public deleteIcon = faTrash;

constructor(private _patientService: PatientService,
private _logger: LoggerService,
Expand Down Expand Up @@ -74,4 +78,35 @@ export class PatientDonorDetailComponent extends ListItemDetailAbstractComponent
this.donorEditable.initializeFromPatient(this.item);
this._logger.log('DonorEditable initialized', [this.donorEditable]);
}

public handleDeleteDonor(): void {
if (!this.item) {
this._logger.error('handleDeleteDonor failed because item not set');
return;
}
if (!this.defaultTxmEvent) {
this._logger.error('handleDeleteDonor failed because defaultTxmEvent not set');
return;
}

const message = this.item.related_recipient_db_id != undefined
? 'Are you sure you want to remove donor and its recipient?'
: 'Are you sure you want to remove donor?';
if (!confirm(message)) {
return;
}

this.deleteLoading = true;
this.deleteSuccess = false;
this._patientService.deleteDonor(this.defaultTxmEvent.id, this.item.db_id)
.then(() => {
this.deleteSuccess = true;
})
.catch(() => {
this._logger.error('Error deleting donor');
})
.finally(() => {
this.deleteLoading = false;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PatientDonorItemComponent } from '@app/components/patient-donor-item/pa
import { PatientDonorDetailWrapperComponent } from '@app/components/patient-donor-detail-wrapper/patient-donor-detail-wrapper.component';
import { EventService } from '@app/services/event/event.service';
import { AbstractLoggedComponent } from '@app/pages/abstract-logged/abstract-logged.component';
import { Subscription } from 'rxjs';
import { PatientUploadSuccessResponseGenerated } from '@app/generated';
import { PatientPairToAdd } from '@app/services/patient/patient.service.interface';
import { DonorType } from '@app/model/enums/DonorType';
Expand All @@ -26,6 +27,8 @@ import { DonorType } from '@app/model/enums/DonorType';
})
export class PatientsComponent extends AbstractLoggedComponent implements OnInit {

private _deleteDonorSubscription?: Subscription;

public patients?: PatientList;
public pairs: PatientPair[] = [];
public items: (Donor | PatientPair)[] = [];
Expand Down Expand Up @@ -53,9 +56,19 @@ export class PatientsComponent extends AbstractLoggedComponent implements OnInit
super.ngOnInit();

this.loading = true;

this._deleteDonorSubscription = this._patientService.onDeleteDonor().subscribe((donorDbId) => {
this._alertService.success('Patients were deleted');
this._initPatientsWithStats();
});

this._initAll().finally(() => this.loading = false);
}

ngOnDestroy(): void {
this._deleteDonorSubscription?.unsubscribe();
}

private async _initAll(): Promise<void> {
await this._initTxmEvents();
await this._initPatientsAndConfiguration();
Expand Down Expand Up @@ -155,6 +168,18 @@ export class PatientsComponent extends AbstractLoggedComponent implements OnInit
this.items = [...items]; // make a copy, not a reference
}

private _initPatientStatsAndItems(): void {
if (!this.patients) {
this._logger.error('_initPatientStatsAndItems failed because patients not set');
return;
}
this.donorsCount = this.patients.donors.length;
this.recipientCount = this.patients.recipients.length;

// Init list items
this._initItems();
}

private async _initPatientsWithStats(): Promise<void> {
// if not already loading before Promise.all
let loadingWasSwitchedOn = false;
Expand All @@ -166,15 +191,8 @@ export class PatientsComponent extends AbstractLoggedComponent implements OnInit
// try getting patients
try {
await this._initPatients();
if (!this.patients) {
return;
}
this.donorsCount = this.patients.donors.length;
this.recipientCount = this.patients.recipients.length;
this._initPatientStatsAndItems();
this._logger.log(`Got ${this.donorsCount + this.recipientCount} patients from server`, [this.patients]);

// Init list items
this._initItems();
} finally {
if (loadingWasSwitchedOn) {
this.loading = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '@environments/environment';
import { first, map } from 'rxjs/operators';
import { filter, first, map } from 'rxjs/operators';
import { LoggerService } from '@app/services/logger/logger.service';
import { PatientList } from '@app/model/PatientList';
import { Donor } from '@app/model/Donor';
Expand All @@ -16,6 +16,7 @@ import {
RecipientModelToUpdateGenerated
} from '@app/generated';
import { parseDonor, parsePatientList, parseRecipient } from '@app/parsers';
import { BehaviorSubject, Observable } from 'rxjs';
import { DonorEditable } from '@app/model/DonorEditable';
import { RecipientEditable } from '@app/model/RecipientEditable';
import { fromDonorEditableToUpdateGenerated } from '@app/parsers/to-generated/donor.parsers';
Expand All @@ -27,10 +28,16 @@ import { fromPatientsEditableToInGenerated } from '@app/parsers/to-generated/pat
})
export class PatientService {

private _deletedDonorDbIdSubject: BehaviorSubject<number> = new BehaviorSubject<number>(-1);

constructor(private _http: HttpClient,
private _logger: LoggerService) {
}

public onDeleteDonor(): Observable<number> {
return this._deletedDonorDbIdSubject.asObservable().pipe(filter(dbId => dbId !== -1));
}

public async getPatients(txmEventId: number): Promise<PatientList> {
return this._http.get<PatientsGenerated>(
`${environment.apiUrl}/txm-event/${txmEventId}/patients`
Expand Down Expand Up @@ -80,4 +87,12 @@ export class PatientService {
payload
).pipe(first()).toPromise();
}

public async deleteDonor(txmEventId: number, donorDbId: number): Promise<void> {
this._logger.log(`Deleting donor ${donorDbId}`);
await this._http.delete(
`${environment.apiUrl}/txm-event/${txmEventId}/patients/pairs/${donorDbId}`
).pipe(first()).toPromise();
this._deletedDonorDbIdSubject.next(donorDbId);
}
}

0 comments on commit 9eeb8d8

Please sign in to comment.