src/app/doctors/doctors.service.ts
Doctors service or db adapter
Properties |
Methods |
constructor(db: AngularFireDatabase)
|
||||||||
|
Defined in src/app/doctors/doctors.service.ts:24
|
||||||||
|
Doctors service constructor
Parameters :
|
| addDoctor | ||||||||||||||||||||||||
addDoctor(name: string, place: string, qualification: string, hospital: string, year_of_experience: number)
|
||||||||||||||||||||||||
|
Defined in src/app/doctors/doctors.service.ts:89
|
||||||||||||||||||||||||
|
Add new doctors
Parameters :
Returns :
void
|
| deleteAllDoctorss |
deleteAllDoctorss()
|
|
Defined in src/app/doctors/doctors.service.ts:138
|
|
Remove all doctors
Returns :
void
|
| deleteDoctor | ||||||||
deleteDoctor(key: string)
|
||||||||
|
Defined in src/app/doctors/doctors.service.ts:131
|
||||||||
|
Delete Doctor
Parameters :
Returns :
void
|
| filterBy | ||||||||
filterBy(place: string | null)
|
||||||||
|
Defined in src/app/doctors/doctors.service.ts:41
|
||||||||
|
Filter doctors by a location
Parameters :
Returns :
Observable<any[]>
|
| getDoctors |
getDoctors()
|
|
Defined in src/app/doctors/doctors.service.ts:56
|
|
Get doctors list
Returns :
Observable<any[]>
|
| getDoctorsRef |
getDoctorsRef()
|
|
Defined in src/app/doctors/doctors.service.ts:63
|
|
Get doctors db reference
Returns :
AngularFireList<any>
|
| getKeyedList |
getKeyedList()
|
|
Defined in src/app/doctors/doctors.service.ts:70
|
|
Get subscribable doctors list with key
Returns :
Subscribable<any>
|
| updateHospital | ||||||||||||||||||||||||||||
updateHospital(key: string, name: string, place: string, qualification: string, hospital: string, year_of_experience: number)
|
||||||||||||||||||||||||||||
|
Defined in src/app/doctors/doctors.service.ts:110
|
||||||||||||||||||||||||||||
|
Update doctor
Parameters :
Returns :
void
|
| doctorsRef |
doctorsRef:
|
Type : AngularFireList<any>
|
|
Defined in src/app/doctors/doctors.service.ts:24
|
|
doctors reference |
import { Doctors } from './doctors';
// import { environment } from './../../environments/environment.prod';
import { Injectable } from '@angular/core';
import { Observable, Subscribable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/switchMap';
// import { Http } from '@angular/http';
import {
AngularFireDatabase,
AngularFireList,
AngularFireAction
} from 'angularfire2/database';
import * as firebase from 'firebase';
/**
* Doctors service or db adapter
*/
@Injectable()
export class DoctorsService {
/**
* doctors reference
*/
doctorsRef: AngularFireList<any>;
/**
* Doctors service constructor
* @param db
*/
constructor(private db: AngularFireDatabase) {
/**
* get doctors db ref
*/
this.doctorsRef = this.db.list('doctors');
}
/**
* Filter doctors by a location
* @param place
*/
filterBy(place: string | null): Observable<any[]> {
return this.db
.list('/doctors', ref => ref.orderByChild('place').equalTo(place))
.snapshotChanges()
.map(changes => {
return changes.map(c => ({
key: c.payload.key,
...c.payload.val()
}));
});
}
/**
* Get doctors list
*/
getDoctors(): Observable<any[]> {
return this.doctorsRef.valueChanges();
}
/**
* Get doctors db reference
*/
getDoctorsRef(): AngularFireList<any> {
return this.doctorsRef;
}
/**
* Get subscribable doctors list with key
*/
getKeyedList(): Subscribable<any> {
return this.getDoctorsRef()
.snapshotChanges()
.map(changes => {
return changes.map(c => ({
key: c.payload.key,
...c.payload.val()
}));
});
}
/**
* Add new doctors
* @param name name of the doctors
* @param place place
* @param qualification qualification
* @param hospital hospital where doctor working
* @param year_of_experience year of experience
*/
addDoctor(
name: string,
place: string,
qualification: string,
hospital: string,
year_of_experience: number
) {
this.getDoctorsRef().push({
name: name,
place: place,
qualification: qualification,
hospital: hospital,
year_of_experience: year_of_experience
});
}
/**
* Update doctor
* @param key doctor key
* @param name updated name
*/
updateHospital(
key: string,
name: string,
place: string,
qualification: string,
hospital: string,
year_of_experience: number
) {
this.getDoctorsRef().update(key, {
name: name,
place: place,
qualification: qualification,
hospital: hospital,
year_of_experience: year_of_experience
});
}
/**
* Delete Doctor
* @param key Doctor key
*/
deleteDoctor(key: string) {
this.getDoctorsRef().remove(key);
}
/**
* Remove all doctors
*/
deleteAllDoctorss() {
this.getDoctorsRef().remove();
}
}