Advertisement
196040

NVD 1 kolokvium practice 3 oop

Nov 24th, 2021
1,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var hashCode = function (s) {
  2.   return String(s).split("").reduce(function (a, b) { a = ((a << 5) - a) + b.charCodeAt(0); return a & a }, 0);
  3. }
  4.  
  5. class Patient {
  6.   constructor(name) {
  7.     this.name = name;
  8.     this.id = hashCode(name);
  9.     this.positive = true;
  10.   }
  11. }
  12. class CovidPositive extends Patient {
  13.   constructor(name, date, gender, age, municipality, symptoms, respiratory_problem,hyperglycaemia) {
  14.     super(name);
  15.     this.gender = gender;
  16.     this.age = age;
  17.     this.date = date;
  18.     this.municipality = municipality;
  19.     this.symptoms = symptoms;
  20.     this.respiratory_problem = respiratory_problem;
  21.     this.hyperglycaemia = hyperglycaemia;
  22.   }
  23.  
  24.   riskCalc() {
  25.     if (!this.symptoms && this.test && this.diabetes && this.respiratory_problem)
  26.       return "Patient: " + this.id + " " + this.name + " is with high risk";
  27.     if (this.symptoms && this.positive && (this.hyperglycaemia || this.respiratory_problem))
  28.       return "Patient: " + this.id + " " + this.name + " is with average risk";
  29.     if (this.symptoms && this.positive && !this.hyperglycaemia && !this.respiratory_problem)
  30.       return "Patient: " + this.id + " " + this.name + " is with low risk";
  31.     if (!this.symptoms && this.positive && !this.hyperglycaemia && !this.respiratory_problem)
  32.       return "Patient: " + this.id + " " + this.name + " is with low risk (resistant to covid)";
  33.     if (this.symptoms && this.hyperglycaemia && this.respiratory_problem && this.age > 75 || this.age > 50 && this.gender == "male")
  34.       return "Patient: " + this.id + " " + this.name + " is with high risk";
  35.     else return "Patient: " + this.id + " " + this.name + " is with average risk";
  36.   }
  37.   toString() {
  38.     var s = "Patient " + this.id.toString() + " " + this.name.toString() + " is positive/negative";
  39.     return s;
  40.   }
  41. }
  42. class EHospital {
  43.   constructor() {
  44.     this.lista = [];
  45.   }
  46.   add_patient(pacient) {
  47.     this.lista.push(pacient);
  48.   }
  49.   test_patient(pacient) {
  50.     //console.log(pacient.date + " datumot ni treba odnosno denot 15 dena unazad ni trebat");
  51.     var help = pacient.date+"";
  52.     if(help.substring(4,7)=="Dec"){
  53.     pacient.positive = false;
  54.     }
  55.     else pacient.positive=true;
  56.     console.log(pacient.riskCalc());
  57.   } // 23 dekemvri - 9 dekemvri = 14 dena
  58.    // else if(23 - parseInt(pacient.date.substring(8,9) < 14))
  59.     //pacient.positive = false;
  60.   check() {
  61.     for (var i = 0; i < this.lista.length; i++) {
  62.       this.test_patient(this.lista[i]);
  63.     }
  64.   }
  65.   safe_zone(opstina) {
  66.     var negativnicounter = 0;
  67.     var pozitivnicounter = 0;
  68.     for (var i in this.lista) {
  69.         if(this.lista[i].municipality == opstina) {
  70.      if(this.lista[i].positive)
  71.      pozitivnicounter++;
  72.      else negativnicounter++;
  73.     }
  74.     }
  75.     let res = (negativnicounter / (negativnicounter + pozitivnicounter)) * 100;
  76.     console.log("You are in a " + res.toFixed(2) + "% zone.");
  77.   }
  78.   print() {
  79.     for(var i=0;i<this.lista.length;i++){
  80.     var att = this.lista[i];
  81.     console.log("CovidPositive {");
  82.     for(var j in att) {
  83.       if(j == "name" || j == "municipality" || j == "gender") {
  84.         console.log(j + ": " + "'" + att[j] + "',");
  85.         continue;
  86.       }
  87.       if (j==="hyperglycaemia") {
  88.         console.log(j + ": " + att[j] + " }");
  89.       }
  90.       else {
  91.       console.log(j + ": " + att[j] + ",");
  92.       }
  93.     }
  94.   }
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement