package aufgabe4; import java.util.Date; import java.util.random.RandomGenerator; /** * Generic test class for implementing a simple patient system for hospitals * _ _ _ _ * __ ___ __(_) |_| |_ ___ _ __ | |__ _ _ * \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | | * \ V V /| | | | |_| || __/ | | | | |_) | |_| | * \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, | * |___/ * ____ __ __ _ * / ___|_ _____ _ __ \ \ / /__ __ _ ___| | * \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ | * ___) \ V / __/ | | | \ V / (_) | (_| | __/ | * |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_| * |___/ * Licensed under the GPLv2 License, Version 2.0 (the "License"); * Copyright (c) Sven Vogel */ @SuppressWarnings("unused") public class Patient extends Object { private final String name; private final String familyName; private final Date birthday; // date the patient was delivered to the hospital private Date admission; // date the patient was finished private Date release; // universally unique identifier private long uuid; /** * Constructs a new Patient * @param name the name of the patient * @param familyName the family name of the patient * @param birthday the date the patient was born */ public Patient(String name, String familyName, Date birthday) { this.name = name; this.familyName = familyName; this.birthday = birthday; this.admission = new Date(); this.uuid = RandomGenerator.getDefault().nextLong(); } /** * Mark the patient as released. Sets the released date to now */ public void release() { this.release = new Date(); } /** * Reset the release date to null and set the admission day to now * the uuid will be regenerated */ public void admission() { this.release = null; this.admission = new Date(); this.uuid = RandomGenerator.getDefault().nextLong(); } public String getName() { return name; } public String getFamilyName() { return familyName; } public Date getBirthday() { return birthday; } public Date getAdmission() { return admission; } public Date getRelease() { return release; } public long getUuid() { return uuid; } /** * returns true if the other object is a patient with equal name and family name else false * @param obj the other object ot compare to * @return true if the other object is a patient with equal name and family name else false */ @Override public boolean equals(Object obj) { if (obj instanceof Patient other) { return this.name.equals(other.getName()) && this.familyName.equals(other.getFamilyName()); } return false; } @Override public String toString() { return String.format("[Patient: %s %s, admission: %s, uuid: %s, released: %s]", name, familyName, admission.toString(), uuid, release == null ? "" : release.toString()); } }