Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.getRandom = function() {
- const randomIndex = Math.floor(Math.random() * this.length);
- return this[randomIndex];
- }
- const BEDS_PER_ROOM = 3;
- const ROOMS_CAPACITY = 10;
- const NEED_DAYS_FOR_HEALING = 3;
- class Hospital {
- constructor(name) {
- this.name = name;
- this.doctors = [];
- this.nurses = [];
- this.patients = [];
- this.departments = [];
- }
- addNewDepartment(department) {
- if (department instanceof Department) {
- this.departments.push(department);
- department.hospital = this;
- } else {
- throw new Error('invalid department input!');
- }
- }
- hireDoctor(doctor) {
- this.doctors.push(doctor);
- doctor.hospital = this;
- }
- setDoctorsToDepartments() {
- this.departments.forEach(department => {
- if (department instanceof Ortopediq) {
- department.doctors.push(this.doctors.filter(doctor => doctor instanceof Ortoped));
- }
- if (department instanceof Kardiologiq) {
- department.doctors.push(this.doctors.filter(doctor => doctor instanceof Kardiolog));
- }
- if (department instanceof Virusologiq) {
- department.doctors.push(this.doctors.filter(doctor => doctor instanceof Virusolog));
- }
- });
- }
- hireNurse(nurse) {
- this.doctors.push(nurse);
- nurse.hospital = this;
- }
- recievePatient(patient) {
- this.patients.push(patient); // priema pacienta
- patient.hospital = this;
- const randomDoctor = this.doctors.getRandom(); //zachislqva mu se doktor
- patient.healingDoctor = randomDoctor;
- randomDoctor.patients.push(patient);
- randomDoctor.makePlanForHealing(patient); //doktora dava diagnoza
- randomDoctor.department.acceptPatient(patient); //pacienta se priema v otdelenie i staq
- console.log('Patient' + patient.name + ' gender: ' + patient.sex + ' is hospitalized with diagnoses '
- + patient.diagnosis + ' Healing Doctor: ' + randomDoctor.name);
- }
- startNewDay() {
- this.patients.forEach(patient => { //proverqva dali pacienta e za izpisvane
- if (patient.daysOfHealing >= Math.floor(Math.random() * 2) + 3) {
- console.log('Patient ' + patient.name + ' with diagnosis: ' + patient.diagnosis
- + ' was sign out from: ' + patient.hospital.name + ' hospital');
- this.patients.splice(indexOf(patient), 1); // pacienta se izpisva
- patient.healingDoctor.signOutPatient(patient);
- patient.healingDoctor.department.releasePatient(patient);
- } else {
- const randomNurse = this.nurses.getRandom(); //med. sestra dava lekartvo
- console.log('Nurse ' + randomNurse.name + ' give to ' + patient.name
- + patient.medicine + ' in room number ' + patient.room.numberOfRoom +
- ' in department ' + patient.room.department);
- console.log('Doctor ' + patient.healingDoctor + ' has visited patient ' //vizitaciq
- + patient.name + ' in room number ' + patient.room.numberOfRoom +
- ' in department ' + patient.room.department);
- patient.daysOfHealing++;
- }
- });
- }
- printPatientsPerDoctor() {
- this.doctors.forEach(doctor =>
- console.log(doctor.name + ' : ' + doctor.patients.length + ' patients'));
- }
- printPatientsReadyToGoHome() {
- this.patients.forEach(patient => {
- if (patient.daysOfHealing >= NEED_DAYS_FOR_HEALING) {
- console.log(patient.name);
- }
- });
- }
- }
- /**
- * options for departments - Ortopediq, Kardiologiq, Virusologiq
- */
- class Department {
- constructor() {
- this.rooms = [];
- this.doctors = [];
- }
- addRoom(room) {
- if (this.rooms.length < ROOMS_CAPACITY) {
- this.rooms.push(room);
- room.department = this;
- }
- }
- acceptPatient(patient) {
- this.rooms.forEach(room => {
- if (room.patients.length > 0) {
- if (room.numberOfFreeBeds > 0 && patient.sex === room.patients[0].sex) {
- room.patients.push(patient);
- patient.room = room;
- room.numberOfFreeBeds--;
- break;
- } else {
- console.log('not enough free beds in room ' + room.numberOfRoom
- + ' department: ' + this.name);
- }
- } else {
- room.patients.push(patient);
- patient.room = room;
- room.numberOfFreeBeds--;
- }
- });
- }
- releasePatient(patient) {
- patient.room.patients.splice(indexOf(patient), 1);
- }
- }
- class Ortopediq extends Department {
- constructor() {
- this.name = 'ortopediq'
- }
- }
- class Kardiologiq extends Department {
- constructor() {
- this.name = 'kardiologiq'
- }
- }
- class Virusologiq extends Department {
- constructor() {
- this.name = 'virusologiq'
- }
- }
- class Room {
- constructor(numberOfRoom) {
- this.numberOfRoom = numberOfRoom;
- this.numberOfFreeBeds = BEDS_PER_ROOM;
- this.patients = [];
- }
- }
- class Doctor {
- constructor(name, tel) {
- super(name, tel);
- this.patients = [];
- }
- signOutPatient(patient) {
- this.patients.splice(indexOf(patient), 1);
- }
- makePlanForHealing(patient) {
- if (patient.healingDoctor instanceof Ortoped) {
- patient.diagnosis = 'schupvane';
- patient.medicine = ['gips', 'bint', 'pironi'];
- }
- if (patient.healingDoctor instanceof Kardiolog) {
- patient.diagnosis = 'infarkt';
- patient.medicine = ['magnezii', 'aspirin', 'acetizal'];
- }
- if (patient.healingDoctor instanceof Virusolog) {
- patient.diagnosis = 'kashlica';
- patient.medicine = ['trahizan', 'tantum', 'chesyn'];
- }
- }
- }
- class Ortoped extends Doctor {
- constructor(name, tel) {
- super(name, tel);
- this.specialization = 'ortoped';
- this.department = null;
- }
- }
- class Kardiolog extends Doctor {
- constructor(name, tel) {
- super(name, tel);
- this.specialization = 'kardiolog';
- this.department = null;
- }
- }
- class Virusolog extends Doctor {
- constructor(name, tel) {
- super(name, tel);
- this.specialization = 'virusolog';
- this.department = null;
- }
- }
- class Nurse extends Person {
- constructor(name, tel, experience) {
- super(name, tel);
- this.experience = experience;
- }
- giveMedicine(patient) {
- console.log(this.name + ' gave medicine to ' + patient.name);
- }
- }
- class Patient extends Person {
- constructor(name, tel, age, sex) {
- super(name, tel);
- this.age = age;
- this.sex = sex;
- this.diagnosis = '';
- this.daysOfHealing = 0;
- this.healingDoctor = null;
- }
- }
- var bolnica = new Hospital('Sofia MED');
- var ortopedia = new Ortopediq();
- var staq = new Room(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement