├── README.md └── app.js /README.md: -------------------------------------------------------------------------------- 1 | # hospital-app 2 | A poc for a hospital patient intake process. 3 | 4 | # Instructions 5 | 1) Clone repository 6 | 2) CD into 'hospital-app' 7 | 3) Run 'node app.js' in cli. 8 | 9 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Hospital app 3 | */ 4 | 5 | // Initialize an array of 50 trauma and 50 heart patients 6 | const patients = Array(100).fill().map((_, i) => { 7 | if (i % 2 === 0) { 8 | return { type: 'trauma' } 9 | } 10 | return { type: 'heart' } 11 | }) 12 | 13 | // initialize a hospital object containing information for the various units 14 | const hospital = { 15 | trauma: { 16 | beds: [], 17 | bedQty: 50 18 | }, 19 | heart: { 20 | beds: [], 21 | bedQty: 50 22 | } 23 | } 24 | 25 | // helper functions 26 | const getRemainingBeds = (unit) => { 27 | return unit.bedQty - unit.beds.length 28 | } 29 | 30 | const printHospitalReport = (hospital) => { 31 | const isTramaUnitFull = hospital.trauma.beds.length === hospital.trauma.bedQty ? 'full' : 'not full' 32 | const isHeartUnitFull = hospital.heart.beds.length === hospital.heart.bedQty ? 'full' : 'not full' 33 | console.log(`The trauma unit is ${isTramaUnitFull} - ${hospital.trauma.beds.length} beds occupied.`) 34 | console.log(`The heart unit is ${isHeartUnitFull} - ${hospital.heart.beds.length} beds occupied.`) 35 | } 36 | 37 | // assign each patient to an appropriate unit and bed 38 | patients.map(patient => { 39 | if(patient.type === 'trauma') { 40 | hospital.trauma.beds.push(patient) 41 | console.log(`There are ${getRemainingBeds(hospital.trauma)} ${patient.type} beds left.`) 42 | } else { 43 | hospital.heart.beds.push(patient) 44 | console.log(`There are ${getRemainingBeds(hospital.heart)} ${patient.type} beds left.`) 45 | } 46 | }) 47 | 48 | // output final hospital report 49 | printHospitalReport(hospital) --------------------------------------------------------------------------------