code:
App.EndWeek.clinicReport = function() {
	let frag = document.createDocumentFragment();

	const slaves = App.Utils.sortedEmployees(App.Entity.facilities.clinic);
	let devBonus = (V.clinicDecoration !== "standard") ? 1 : 0;
	let healthBonus = 0;
	V.flSex = App.EndWeek.getFLSex(App.Entity.facilities.clinic); // FIXME: should be local, passed as a parameter to saRules

	function nurseText() {
		let r = [];
		let FLsFetish = 0;
		let idleBonus = 0;

		if (S.Nurse) {
			if (S.Nurse.health.condition < 100) {
				improveCondition(S.Nurse, 20);
			}
			if (S.Nurse.devotion <= 60) {
				S.Nurse.devotion++;
			}
			if (S.Nurse.trust < 60) {
				S.Nurse.trust++;
			}

			if (S.Nurse.rules.living !== "luxurious") {
				S.Nurse.rules.living = "luxurious";
			}
			if (S.Nurse.rules.rest !== "restrictive") {
				S.Nurse.rules.rest = "restrictive";
			}

			S.Nurse.devotion += devBonus;
			if (S.Nurse.fetishStrength <= 95) {
				if (S.Nurse.fetish !== "dom") {
					if (fetishChangeChance(S.Nurse) > jsRandom(0, 100)) {
						FLsFetish = 1;
						S.Nurse.fetishKnown = 1;
						S.Nurse.fetish = "dom";
					}
				} else if (S.Nurse.fetishKnown === 0) {
					FLsFetish = 1;
					S.Nurse.fetishKnown = 1;
				} else {
					FLsFetish = 2;
					S.Nurse.fetishStrength += 4;
				}
			}
			const {He, he, His, his, him, wife} = getPronouns(S.Nurse);
			r.push(`${SlaveFullName(S.Nurse)} is serving as the clinical nurse.`);
			if (S.Nurse.relationship === -3 && S.Nurse.devotion > 50) {
				r.push(`${He} does ${his} best to be a caring and nurturing ${wife}.`);
				healthBonus += 2;
			}
			if (FLsFetish === 1) {
				r.push(`${His} job involves giving naked sex slaves orders for their own good. Even though most of these commands are medical rather than sexual, ${he} can be forgiven for not always seeing the difference, and becomes more dominant.`);
			} else if (FLsFetish === 2) {
				r.push(`Every new patient in the clinic is a new target for ${his} authority. <span class="fetish inc">${He} becomes more dominant.</span>`);
			}
			if (setup.nurseCareers.includes(S.Nurse.career)) {
				r.push(`${He} has experience with medicine from ${his} life before ${he} was a slave, and can often recognize conditions before even the medical scanners can.`);
				idleBonus++;
				healthBonus++;
			} else if (S.Nurse.skill.nurse >= V.masteredXP) {
				r.push(`${He} has experience with medicine from working for you, and can often recognize conditions before even the medical scanners can.`);
				idleBonus++;
				healthBonus++;
			} else {
				S.Nurse.skill.nurse += jsRandom(1, Math.ceil((S.Nurse.intelligence+S.Nurse.intelligenceImplant)/15) + 8);
			}
			if (S.Nurse.fetish === "dom") {
				r.push(`${He} raps out commands with the confidence of long and partly sexual experience, so patients are inclined to follow even unpleasant medical instructions.`);
				idleBonus++;
				healthBonus++;
			}
			if (S.Nurse.muscles > 5) {
				r.push(`${He}'s strong enough to gently but firmly restrain resistant slaves, allowing ${him} to be sparing with the inescapable but less healthy restraints.`);
				idleBonus++;
				healthBonus++;
			}
			if (S.Nurse.intelligence+S.Nurse.intelligenceImplant > 50) {
				r.push(`The diagnostic equipment is state-of-the-art, but ${he}'s smart and perceptive enough that on occasion, ${he} can add meaningfully to its medical scans.`);
				idleBonus++;
				healthBonus++;
			}
			if (S.Nurse.face > 40) {
				r.push(`Patients rarely object to seeing ${his} gorgeous face hovering over them.`);
				idleBonus++;
				devBonus++;
			}
			if (S.Nurse.devotion >= 60) {
				healthBonus++;
			}
			for (const slave of slaves) {
				const {He2, His2, he2, his2, him2} = getPronouns(slave).appendSuffix('2');
				if (S.Nurse.rivalryTarget === slave.ID) {
					r.push(`${He} purposefully neglects the needs of ${his} ${rivalryTerm(S.Nurse)}, ${slave.slaveName}, <span class="health dec">hindering ${his2} recovery</span> and deepening their dislike for each other.`);
					slave.devotion--;
					slave.trust--;
					healthDamage(slave, 3);
					if (jsRandom(1, 100) > 65) {
						S.Nurse.rivalry++;
						slave.rivalry++;
					}
				} else if (S.Nurse.relationshipTarget === slave.ID) {
					r.push(`${He} dedicates most of ${his} attention to ${his} ${relationshipTerm(S.Nurse)}, ${slave.slaveName}, making sure ${he2} has everything ${he2} needs and more. This lavish attention detracts from ${his} overall effectiveness.`);
					idleBonus -= 3;
					slave.devotion++;
					slave.trust++;
					improveCondition(slave, 3);
				} else if (areRelated(S.Nurse, slave)) {
					r.push(`${He} makes sure to spend extra time caring for ${his} ${relativeTerm(S.Nurse, slave)}, ${slave.slaveName}.`);
					slave.trust++;
					improveCondition(slave, 1);
				}
				switch (slave.prestigeDesc) {
					case "$He is a famed Free Cities whore, and commands top prices.":
						r.push(`${He} does ${his} best to aid the famous whore, ${slave.slaveName}, making sure to pay special attention to ${his2} worn holes.`);
						improveCondition(slave, 2);
						break;
					case "$He is a famed Free Cities slut, and can please anyone.":
						r.push(`${He} does ${his} best to aid the famous entertainer, ${slave.slaveName}, making sure ${he2} can show off as soon as possible.`);
						improveCondition(slave, 2);
						break;
					case "$He is remembered for winning best in show as a cockmilker.":
						if ((slave.balls > 4) && (slave.dick !== 0)) {
							r.push(`${He} does ${his} best to aid the dribbling ${slave.slaveName}, paying special attention to ${his2} huge cock and balls as well as making sure to milk ${his2}`);
							if (canAchieveErection(slave)) {
								r.push(`erect`);
							}
							r.push(`dick hourly.`);
							improveCondition(slave, 4);
							if (jsRandom(1, 100) > 65) {
								if (S.Nurse.fetish === "none") {
									S.Nurse.fetish = "cumslut"; // FIXME: no player notification on fetish acquisition?
								} else if (S.Nurse.fetish === "cumslut") {
									S.Nurse.fetishStrength += 4;
								}
							}
						}
						break;
					case "$He is remembered for winning best in show as a dairy cow.":
						if ((slave.lactation > 0) && ((slave.boobs-slave.boobsImplant) > 6000)) {
							r.push(`${He} does ${his} best to aid the leaking ${slave.slaveName}, paying special attention to ${his2} huge breasts as well as making sure to milk ${him2} hourly.`);
							improveCondition(slave, 4);
							slave.lactationDuration = 2;
							if (jsRandom(1, 100) > 65) {
								if (S.Nurse.fetish === "none") {
									S.Nurse.fetish = "boobs"; // FIXME: no player notification on fetish acquisition?
								} else if (S.Nurse.fetish === "boobs") {
									S.Nurse.fetishStrength += 4;
								}
							}
						}
						break;
					case "$He is remembered for winning best in show as a breeder.":
						if (slave.bellyPreg >= 1500) {
							r.push(`${He} does ${his} best to aid the pregnant ${slave.slaveName}, paying special attention to ${his2} swollen belly and the welfare of the life within.`);
							improveCondition(slave, 6);
						} else if (slave.ovaries === 1 || slave.mpreg === 1) {
							r.push(`${He} does ${his} best to aid the breeder ${slave.slaveName}, paying special attention to ${his2} fertility and reproductive organs.`);
							improveCondition(slave, 4);
						} else {
							r.push(`${He} lays out plans on how to restore the breeder ${slave.slaveName} to ${his2} former gravid glory.`);
						}
						break;
				}
				if (slave.bellyImplant > -1 && V.clinicInflateBelly === 1) {
					r.push(`
${slave.slaveName} spent a lot of time during the week under IV-like stands with bags of inert filler steadily flowing into ${his2} belly implant, slowly pushing ${his2} belly further and further out. Careful attention, along with several drug injections, were used to make sure ${his2} body was able to safely adjust to the implant's rapid growth.`);
					healthDamage(slave, 10);
					slave.bellyImplant += 5000;
					if (slave.devotion > 50) {
						slave.devotion += 4;
						slave.trust += 3;
					} else if ((slave.devotion >= -20)) {
						slave.trust -= 5;
					} else {
						slave.devotion -= 5;
						slave.trust -= 10;
					}
					if (slave.bellyImplant > (V.arcologies[0].FSTransformationFetishistResearch ? 800000 : 130000)) {
						slave.bellyImplant = (V.arcologies[0].FSTransformationFetishistResearch ? 800000 : 130000);
						r.push(`${He2} is filled to the maximum that ${his2} implant can stand.`);
					}
					r.push(`</div>`);
				}
				if (slave.pregKnown === 1 && slave.preg < slave.pregData.normalBirth && slave.pregControl === "speed up") {
					r.push(`<div class="indent"><span class="slave-name">${slave.slaveName}</span> spends most of ${his2} time on bedrest being filled with rapid gestation agents and concentrated slave food. All ${he2} can do is`);
					if (hasAnyArms(slave) && canSee(slave)) {
						r.push(`watch and feel ${his2} belly pushing further and further out with life.`);
					} else if (canSee(slave)) {
						r.push(`watch ${his2} belly bulging further and further out with life.`);
					} else if (hasAnyArms(slave)) {
						r.push(`feel ${his2} belly pushing further and further out with life beneath ${his2} fingers.`);
					} else {
						r.push(`feel the every growing pressure inside ${his2} abdomen.`);
					}
					r.push(`Careful attention, along with numerous drug injections, are used to make sure ${his2} body is able to safely adjust to ${his2} pregnancy's rapid growth.`);
					healthDamage(slave, 10);
					if (slave.devotion > 50) {
						slave.devotion += 2;
						slave.trust += 1;
					} else if ((slave.devotion >= -20)) {
						slave.trust -= 5;
					} else {
						slave.devotion -= 5;
						slave.trust -= 10;
					}
					if (slave.preg >= slave.pregData.normalBirth && slave.pregControl === "speed up") {
						slave.pregControl = "none";
						r.push(`${His2} child is ready to pop out of ${his2} womb; <span class="yellow">${his2} course of rapid gestation agents is finished.</span>`);
					}
					r.push(`</div>`);
				} else if (slave.preg > 2 && slave.pregKnown === 0) {
					r.push(`During ${his} tests, ${he} discovers that ${slave.slaveName} <span class="lime">is pregnant.</span>`);
					slave.pregKnown = 1;
				}
			}

			if (slaves.length < V.clinic && !slaveResting(S.Nurse)) {
				const _idlePay = jsRandom(1, 10) + ((V.clinic - slaves.length) * (jsRandom(150, 170) + (idleBonus * 10)));
				cashX(_idlePay, "clinic", S.Nurse);
				r.push(`
Since ${he} doesn't have enough patients to occupy all of ${his} time, ${V.clinicName} takes in citizens' slaves on a contract basis and ${he} helps them too, earning ${cashFormat(_idlePay)}.
`);
			}
		}

		return r.join(" ");
	}

	const nurseEffects = App.UI.DOM.appendNewElement("p", frag, '', "indent");
	$(nurseEffects).append(nurseText());

	if (slaves.length > 0) {
		const intro = App.UI.DOM.appendNewElement("p", frag, '', "indent");
		if (slaves.length > 1) {
			$(intro).append(`<strong>There are ${slaves.length} slaves receiving treatment in the clinic.</strong>`);
		} else {
			$(intro).append(`<strong>There is one slave receiving treatment in the clinic.</strong>`);
		}
	}

	if (S.Nurse) {
		const slave = S.Nurse;
		V.i = V.slaveIndices[slave.ID];
		App.Utils.setLocalPronouns(slave); // need this for the includes
		/* apply following SA passages to facility leader */
		if (V.showEWD !== 0) {
			const nurseEntry = App.UI.DOM.appendNewElement("div", frag, '', "slave-report");
			if (V.seeImages && V.seeReportImages) {
				App.UI.DOM.appendNewElement("div", nurseEntry, App.Art.SlaveArtElement(slave, 0, 0), ["imageRef", "tinyImg"]);
			}
			nurseEntry.append(App.EndWeek.favoriteIcon(slave), " ");
			$(nurseEntry).append(`<span class='slave-name'>${SlaveFullName(slave)}</span> is serving as the clinical nurse.`);
			$(nurseEntry).append(App.SlaveAssignment.standardSlaveReport(slave, false));
		} else {
			App.SlaveAssignment.standardSlaveReport(slave, true);
		}
	}

	let restedSlaves = 0;
	for (const slave of slaves) {
		V.i = V.slaveIndices[slave.ID];
		if (slave.devotion < 45) {
			slave.devotion += 4;
		}
		slave.devotion += devBonus;

		if (slave.health.condition < -80) {
			improveCondition(slave, 20 + (V.curativeUpgrade * 10) + healthBonus);
		} else if (slave.health.condition < -40) {
			improveCondition(slave, 10 + (V.curativeUpgrade * 10) + healthBonus);
		} else if (slave.health.condition < 0) {
			improveCondition(slave, 7 + (V.curativeUpgrade * 10) + healthBonus);
		} else if (slave.health.condition < 90) {
			improveCondition(slave, 3 + (V.curativeUpgrade * 10) + healthBonus);
		}

		/* the clinic is a well-equipped medical facility and can allow the Nurse or player to
		* directly cure serious wounds caused by injury and surgery with minimal side effects */
		if (slave.health.shortDamage >= 10) {
			if (S.Nurse) {
				healthCure(slave, 5 + healthBonus);
			} else {
				healthCure(slave, V.PC.skill.medicine / 15); /* maximum of 6...even a bad full-time nurse will be better than a player doctor */
			}
		}

		switch (V.clinicDecoration) {
			case "Eugenics":
			case "Gender Fundamentalist":
			case "Gender Radicalist":
			case "Hedonistic":
			case "Intellectual Dependency":
			case "Maturity Preferentialist":
			case "Paternalist":
			case "Petite Admiration":
			case "Repopulation Focus":
			case "Slimness Enthusiast":
			case "Statuesque Glorification":
			case "Youth Preferentialist":
				slave.rules.living = "luxurious";
				break;
			case "Arabian Revivalist":
			case "Aztec Revivalist":
			case "Chattel Religionist":
			case "Chinese Revivalist":
			case "Edo Revivalist":
			case "Egyptian Revivalist":
			case "Roman Revivalist":
				slave.rules.living = "normal";
				break;
			default:
				slave.rules.living = "spare";
		}

		if (S.Nurse) {
			if ((V.clinicSpeedGestation === 1) && (slave.pregKnown === 1)) {
				slave.pregControl = "speed up";
			}
			if ((slave.chem > 10) && (V.clinicUpgradeFilters >= 1)) {
				if (slave.health.health > -50 && (V.clinicUpgradePurge > 0)) {
					slave.chem -= 100 * V.clinicUpgradePurge;
					healthDamage(slave, 15);
				}
				slave.chem = Math.max(slave.chem - 5, 0);
			}
			if (slave.lactation > 0) {
				slave.boobs -= slave.boobsMilk;
				slave.boobsMilk = 0;
			}
		}

		/* Evaluate why the slave even needs to be here, and eject her if she doesn't */
		const {He, he, his} = getPronouns(slave);
		let remainReason = "";
		if (slave.health.illness > 0) {
			remainReason = `${He} stays in the clinic since ${he} is still sick.`;
		} else if (slave.health.shortDamage >= 20) {
			remainReason = `${He} stays in the clinic to recover from ${his} injuries.`;
		} else if (slave.health.condition <= 40) {
			remainReason = `${He} stays in the clinic since ${his} health is still poor.`;
		} else if (S.Nurse && (slave.chem > 15) && (V.clinicUpgradeFilters === 1)) {
			remainReason = `${He} stays in the clinic as unhealthy chemicals are still being flushed from ${his} system.`;
		} else if (S.Nurse && (slave.pregKnown === 1) && (V.clinicSpeedGestation > 0 || slave.pregControl === "speed up")) {
			remainReason = `${He} stays in the clinic to hurry ${his} pregnancy along safely.`;
		} else if (S.Nurse && (V.clinicObservePregnancy === 1) && (slave.pregAdaptation * 1000 < slave.bellyPreg || slave.preg > slave.pregData.normalBirth / 1.33)) {
			remainReason = `${He} stays in the clinic waiting for the child to be born.`;
		} else if (S.Nurse && (V.clinicInflateBelly > 0) && (slave.bellyImplant >= 0) && (slave.bellyImplant <= (V.arcologies[0].FSTransformationFetishistResearch ? 800000 : 130000))) {
			remainReason = `${He} stays in the clinic as ${his} implants can still receive more filling.`;
		} else {
			const reassignment = App.UI.DOM.appendNewElement("p", frag, '');
			const {he, his} = getPronouns(slave);
			let r = [];
			r.push(`<span class="slave-name">${slave.slaveName}</span> has been cured${(S.Nurse && V.clinicUpgradeFilters > 0) ? ' and purified' : ''},`);
			r.push(`<span class="noteworthy">`);
			if (V.assignmentRecords[slave.ID]) {
				const oldJob = V.assignmentRecords[slave.ID];
				assignJobSafely(slave, oldJob);
				if (slave.choosesOwnAssignment === 1) {
					r.push(`and ${he} is resting before choosing another task.`);
				} else if (slave.assignment === "rest") {
					if (oldJob !== "rest") {
						r.push(`and since ${he} was unable to return to ${his} old task to ${oldJob}, ${his} assignment has defaulted to rest.`);
					} else {
						r.push(`so ${he} has returned to rest.`);
					}
				} else {
					r.push(`so ${he} goes back to ${slave.assignment}.`);
				}
			} else {
				r.push(`so ${his} assignment has defaulted to rest.`);
				removeJob(slave, "get treatment in the clinic");
			}
			r.push(`</span>`);
			restedSlaves++;
			$(reassignment).append(r.join(" "));
			continue;
		}

		App.Utils.setLocalPronouns(slave); // need this for the includes
		if (V.showEWD !== 0) {
			const slaveEntry = App.UI.DOM.appendNewElement("div", frag, '', "slave-report");
			if (V.seeImages && V.seeReportImages) {
				App.UI.DOM.appendNewElement("div", slaveEntry, App.Art.SlaveArtElement(slave, 0, 0), ["imageRef", "tinyImg"]);
			}
			slaveEntry.append(App.EndWeek.favoriteIcon(slave), " ");
			$(slaveEntry).append(`<span class='slave-name'>${SlaveFullName(slave)}</span> `);
			if (slave.choosesOwnAssignment === 2) {
				$(slaveEntry).append(App.SlaveAssignment.choosesOwnJob(slave));
			} else {
				$(slaveEntry).append(`is receiving treatment in ${V.clinicName}.`);
			}
			const patientContent = App.UI.DOM.appendNewElement("div", slaveEntry, '', "indent");
			$(patientContent).append(`${He} ${App.SlaveAssignment.rest(slave)} `);
			$(patientContent).append(remainReason);
			$(slaveEntry).append(App.SlaveAssignment.standardSlaveReport(slave, false));
		} else {
			// discard return values silently
			App.SlaveAssignment.choosesOwnJob(slave);
			App.SlaveAssignment.rest(slave);
			App.SlaveAssignment.standardSlaveReport(slave, true);
		}
	}

	if (restedSlaves > 0) {
		const rested = App.UI.DOM.appendNewElement("p", frag, '', "indent");
		rested.append((restedSlaves === 1) ? `One slave has` : `${restedSlaves} slaves have`, " been returned to ");
		App.UI.DOM.appendNewElement("span", rested, `health${(S.Nurse && V.clinicUpgradeFilters > 0) ? ' and purity' : ''}`, "green");
		rested.append(` and will be released from the clinic before the end of the week.`);

		if (V.clinicDecoration !== "standard") {
			const decorationEffects = App.UI.DOM.appendNewElement("p", frag, '', "indent");
			$(decorationEffects).append(`${capFirstChar(V.clinicName)}'s ${V.clinicDecoration} atmosphere <span class="hotpink">had an impact on them</span> while they were getting treatment.`);
		}
	}

	return frag;
};