2016-09-26 83 views
0

當您從藥房獲得處方時,會有與藥物相關的開始日期。藥物也有預定的頻率,告訴你什麼時候服用這些劑量。頻率有相當常見的模式。你可以每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; 

進口的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; 
} 

}

Patient類

package patientmedicine; 

進口的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; 

進口的java.util.ArrayList; import java.util.List;

進口patientmedicine.Frequency.PartoftheDay;

公開課程程序{0}私人列表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()); 
      } 

     } 

    } 

} 

}

+0

我的錯誤道歉。刪除JS –

+1

您是否介意編輯您的問題,並提供一些更清晰的問題,以解決您遇到的問題?你想達到什麼目的?你是如何試圖完成這個的?你堅持什麼部分? –

+0

我已經實施了採取耐心藥物和頻率的類..但我堅持實施時間表功能(通知功能,通知護士關於患者必須採取的藥頻率每天) –

回答

2

下面是一個使用監聽器周杰倫提出的部分實現。你可以將這個骨架代碼合併到你的部分實現中。

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 
+0

我正要寫出完全相同的實現,但你已經做到了。做得好。我可以把這個放入公共回購嗎? – Jay

+0

是的,這很好,周杰倫,謝謝你的想法。如果你不介意,請相信我。 – akubot

+0

當然。如果你不介意的話,你可以爲它做出貢獻。我把我的例子放在那裏。它也有一些不錯的實現;) – Jay