通知护士患者必须服用的药物的频率

时间:2016-09-26 17:40:52

标签: java list design-patterns notifications frequency

当您从药房获得处方时,有一个与药物相关的开始日期。药物也有预定的频率,告诉你何时服用剂量。频率有相当常见的模式。你可以每4小时服用一次。你可以每天服用一次。您可以在用餐时或睡前服用。您也可以将它们带到PRN或“根据需要”。许多药物也停止了。您可能需要服用药物7天。您可能需要服用一定剂量的剂量。您也可以在余生中服用药物。假设您必须实施一个系统,告诉护士何时应该接受药物治疗。您如何为处理开始日期,结束日期和频率的药物制定计划表?

我已经完成了基本设计..但我仍然坚持实施日程安排功能(通知功能,通知护士的医药频率)

我的解决方案是

频率等级

    package patientmedicine;

公共班级频率{

public PartoftheDay part;
public enum PartoftheDay
{
    Morning,
    Afternoon,
    Evening,
    Night
}

public Frequency( PartoftheDay part ) {
    this.part = part;

} 

public PartoftheDay getPart() {
    return part;
}
public void setPart(PartoftheDay part) {
    this.part = part;
}

}

医学课

    package patientmedicine;

import java.util.List;

公共类医学{

private String name;
private String disease;
private String composition;
private String details;
private List<Frequency> frequencyList;



public List<Frequency> getFrequencyList() {
    return frequencyList;
}

public void setFrequencyList(List<Frequency> frequencyList) {
    this.frequencyList = frequencyList;
}

public String getName() {
    return name;
}

public Medicine(String name, String composition, String details) {
    this.name = name;
    this.setComposition(composition);
    this.setDetails(details);

}

public void setName(String name) {
    this.name = name;
}
public String getDisease() {
    return disease;
}
public void setDisease(String disease) {
    this.disease = disease;
}

/**
 * @return the composition
 */
public String getComposition() {
    return composition;
}

/**
 * @param composition the composition to set
 */
public void setComposition(String composition) {
    this.composition = composition;
}

/**
 * @return the details
 */
public String getDetails() {
    return details;
}

/**
 * @param details the details to set
 */
public void setDetails(String details) {
    this.details = details;
}

}

患者类

    package patientmedicine;

import java.util.List;

公共类患者{

private String name;
private String disease;
private List<Medicine> medicineList;



public Patient(String name, String disease) {
    this.setName(name);
    this.setDisease(disease);

}



public List<Medicine> getMedicineList() {
    return medicineList;
}



public void setMedicineList(List<Medicine> medicineList) {
    this.medicineList = medicineList;
}



/**
 * @return the name
 */
public String getName() {
    return name;
}

/**
 * @param name the name to set
 */
public void setName(String name) {
    this.name = name;
}

/**
 * @return the disease
 */
public String getDisease() {
    return disease;
}

/**
 * @param disease the disease to set
 */
public void setDisease(String disease) {
    this.disease = disease;
}

}

计划类

    package patientmedicine;

import java.util.ArrayList; import java.util.List;

import patientmedicine.Frequency.PartoftheDay;

公共课程{     // private List patientList;

public static void main(String[] args) {

    List<Frequency> freque1 = new ArrayList<Frequency>();
    freque1.add(new Frequency(PartoftheDay.Morning));
    freque1.add(new Frequency(PartoftheDay.Evening));

    // List<Medicine> medicine = new ArrayList<Medicine>();
    Medicine med1 = new Medicine("Paracetemol", "38g", "For fever");
    med1.setFrequencyList(freque1);

    List<Frequency> freque2 = new ArrayList<Frequency>();
    freque2.add(new Frequency(PartoftheDay.Morning));
    freque2.add(new Frequency(PartoftheDay.Evening));

    Medicine med2 = new Medicine("Ibuprofen", "38g", "For body pains");
    med2.setFrequencyList(freque2);

    List<Medicine> medicineList = new ArrayList<Medicine>();
    medicineList.add(med1);
    medicineList.add(med2);

    Patient patient1 = new Patient("Deepthi", "For body pains");
    patient1.setMedicineList(medicineList);

    List<Patient> patientList = new ArrayList<Patient>();
    patientList.add(patient1);

    for (Patient patientt : patientList) {
        System.out.println(patientt.getDisease());
        System.out.println(patientt.getName());

        for (Medicine medi : patientt.getMedicineList()) {

            System.out.println(medi.getDetails() + medi.getComposition()
                    + medi.getName());

            for (Frequency freq : medi.getFrequencyList()) {
                System.out.println(freq.getPart());
            }

        }

    }

}

}

1 个答案:

答案 0 :(得分:2)

这是Jay建议使用监听器的部分实现。您可以将此骨架代码合并到部分实现中。

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

interface AlarmListener {
    void notify(Frequency.PartoftheDay time, String msg);
}

class Nurse implements AlarmListener {
    private String name;
    private Set<Frequency.PartoftheDay> times = new HashSet<>();

    Nurse(String name) {
        this.name = name;
    }

    // Add times of day that this nurse will be notified
    public void addTime(Frequency.PartoftheDay time) {
        this.times.add(time);
    }

    public void notify(Frequency.PartoftheDay time, String msg) {
        if (times.contains(time)) {
            System.out.println("Nurse " + name + ", you are being notified of event:  " + msg);
        }
    }

    @Override
    public String toString() {
        StringBuffer b = new StringBuffer();
        b.append(name).append(":  scheduled for\n");
        for (Frequency.PartoftheDay time : times) {
            b.append("  ").append(time).append("\n");
        }

        return b.toString();
    }
}

class Scheduler {
    List<AlarmListener> alarmListenerList = new ArrayList<>();

    public void addListener(AlarmListener alarmListener) {
        alarmListenerList.add(alarmListener);
    }

    public void rollCall() {
        System.out.println("Roll call:");
        for (AlarmListener a : alarmListenerList) {
            System.out.println(a.toString());
        }
    }

    public void notifyListeners(Frequency.PartoftheDay time) {
        for (AlarmListener a : alarmListenerList) {
            a.notify(time, time.name());
        }
    }
}

class Frequency {
    public enum PartoftheDay
    {
        Morning,
        Afternoon,
        Evening,
        Night
    }
    public PartoftheDay part;
}

public class Main {
    public static void main(String[] args) {
        Nurse alice = new Nurse("Alice");
        alice.addTime(Frequency.PartoftheDay.Morning);
        alice.addTime(Frequency.PartoftheDay.Afternoon);

        Nurse bob = new Nurse("Bob");
        bob.addTime(Frequency.PartoftheDay.Afternoon);
        bob.addTime(Frequency.PartoftheDay.Evening);

        Scheduler scheduler = new Scheduler();
        scheduler.addListener(alice);
        scheduler.addListener(bob);

        // Show who is scheduled to respond to alarms and when
        scheduler.rollCall();

        // Do this if "Morning" has arrived
        System.out.println("Morning now! ----------------");
        scheduler.notifyListeners(Frequency.PartoftheDay.Morning);
        System.out.println("");

        // Do this if "Afternoon" has arrived
        System.out.println("Afternoon now! --------------");
        scheduler.notifyListeners(Frequency.PartoftheDay.Afternoon);
        System.out.println("");

        // Do this if "Evening" has arrived
        System.out.println("Evening now! --------------");
        scheduler.notifyListeners(Frequency.PartoftheDay.Evening);
    }
}

输出:

Roll call:
Alice:  scheduled for
  Morning
  Afternoon

Bob:  scheduled for
  Afternoon
  Evening

Morning now! ----------------
Nurse Alice, you are being notified of event:  Morning

Afternoon now! --------------
Nurse Alice, you are being notified of event:  Afternoon
Nurse Bob, you are being notified of event:  Afternoon

Evening now! --------------
Nurse Bob, you are being notified of event:  Evening
相关问题