Skip to content

Commit

Permalink
added delete examination to service
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavinp14 committed Dec 30, 2024
1 parent c410316 commit 1524337
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/app/health/health-event-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, Inject, OnInit, OnDestroy } from '@angular/core';
import { Component, Inject, OnInit, OnDestroy, EventEmitter, Output } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { conditionAndTreatmentFields, vitals } from './health.constants';
import { Router } from '@angular/router';
import { timer, of, combineLatest } from 'rxjs';
import { switchMap, takeWhile } from 'rxjs/operators';
import { UsersService } from '../users/users.service';
import { CouchService } from '../shared/couchdb.service';
import { HealthService } from './health.service';
import { UserService } from '../shared/user.service';
import { DialogsPromptComponent } from '../shared/dialogs/dialogs-prompt.component';
import { MatDialog } from '@angular/material/dialog';
Expand All @@ -18,6 +19,7 @@ export class HealthEventDialogComponent implements OnInit, OnDestroy {

event: any;
hasConditionAndTreatment = false;
@Output() examinationDeleted = new EventEmitter<string>();
conditionAndTreatmentFields = conditionAndTreatmentFields;
conditions: string;
hasVital = false;
Expand All @@ -36,6 +38,7 @@ export class HealthEventDialogComponent implements OnInit, OnDestroy {
private usersService: UsersService,
private couchService: CouchService,
private userService: UserService,
private healthService: HealthService,
private planetMessageService: PlanetMessageService,
) {
this.event = this.data.event || {};
Expand Down Expand Up @@ -87,18 +90,19 @@ export class HealthEventDialogComponent implements OnInit, OnDestroy {
});
}

deleteExamination(event){
deleteExamination(event) {
const {_id: eventId, _rev: eventRev} = event;
return {
request: this.couchService.delete('health' + '/' + eventId + '?rev=' + eventRev),
onNext: (data) => {
request: this.healthService.deleteExamination(eventId, eventRev),
onNext: () => {
this.deleteDialog.close();
this.dialog.closeAll();
this.examinationDeleted.emit(eventId);
this.planetMessageService.showMessage($localize`You have deleted this examination`);
},
onError: (error) => this.planetMessageService.showAlert($localize`There was a problem deleting this resource.`)
}
}
onError: () => this.planetMessageService.showAlert($localize`There was a problem deleting this resource.`)
};
}

editButtonCountdown() {
this.couchService.currentTime().pipe(
Expand Down
18 changes: 15 additions & 3 deletions src/app/health/health.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { Injectable, Input } from '@angular/core';
import { of, forkJoin, BehaviorSubject } from 'rxjs';
import { CouchService } from '../shared/couchdb.service';
import { switchMap, catchError } from 'rxjs/operators';
Expand All @@ -12,6 +12,8 @@ import { findDocuments } from '../shared/mangoQueries';
})
export class HealthService {

private examinations = new BehaviorSubject<any[]>([]);
examinationsUpdated = this.examinations.asObservable();
healthData: any = {};
readonly encryptedFields = [
'events', 'profile', 'lastExamination', 'userKey',
Expand All @@ -23,7 +25,8 @@ export class HealthService {
constructor(
private couchService: CouchService,
private stateService: StateService,
private usersService: UsersService
private usersService: UsersService,

) {}

userDatabaseName(userId: string) {
Expand Down Expand Up @@ -149,4 +152,13 @@ export class HealthService {
return this.couchService.findAll('health', findDocuments({ planetCode }));
}

}
deleteExamination(eventId: string, eventRev: string) {
return this.couchService.delete(`health/${eventId}?rev=${eventRev}`).pipe(
switchMap(() => this.getExaminations(this.stateService.configuration.code)),
switchMap((exams: any[]) => {
const updatedExams = exams.filter(exam => exam._id !== eventId);
this.examinations.next(updatedExams);
return of(true);
})
);
}}

0 comments on commit 1524337

Please sign in to comment.