package com.lantone.qc.pub.model.doc;

import com.lantone.qc.pub.model.doc.ward.AttendingDoctorWardDoc;
import com.lantone.qc.pub.model.doc.ward.DirectorDoctorWardDoc;
import com.lantone.qc.pub.model.doc.ward.GeneralDoctorWardDoc;
import com.lantone.qc.pub.model.label.ThreeLevelWardLabel;
import com.lantone.qc.pub.util.StringUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.*;

/**
 * @ClassName : ThreeLevelWardDoc
 * @Description : 查房记录文档
 * @Author : 楼辉荣
 * @Date: 2020-03-03 19:04
 */
@Getter
@Setter
public class ThreeLevelWardDoc extends ModelDoc {
    private List<ThreeLevelWardLabel> threeLevelWardLabel = new ArrayList<>();
    //所有的查房记录
    private List<ThreeLevelWardDoc> allDoctorWradDocs = new ArrayList<>();
    //主任医师查房
    private List<DirectorDoctorWardDoc> directorDoctorWardDocs = new ArrayList<>();
    //主治医师查房
    private List<AttendingDoctorWardDoc> attendingDoctorWardDocs = new ArrayList<>();
    //普通医师查房
    private List<GeneralDoctorWardDoc> generalDoctorWardDocs = new ArrayList<>();

    /**
     * 总的查房记录集合
     * @param allDoctorWradDoc
     */
    public void addAllDoctorWradDoc(ThreeLevelWardDoc allDoctorWradDoc) {
        if (StringUtil.isBlank(allDoctorWradDoc.getStructureMap().get("查房日期"))){
            return;
        }
        Map<Date, ThreeLevelWardDoc> dateRecord = new TreeMap<>(new Comparator<Date>() {
            @Override
            public int compare(Date o1, Date o2) {
                // 升序排列
                return o1.compareTo(o2);
            }
        });//按时间key排序，查房记录
        dateRecord.put(StringUtil.parseDateTime(allDoctorWradDoc.getStructureMap().get("查房日期")), allDoctorWradDoc);
        allDoctorWradDocs.stream().forEach(
                doc ->  dateRecord.put(StringUtil.parseDateTime(doc.getStructureMap().get("查房日期")), doc)
        );

        List<ThreeLevelWardDoc> docs = new ArrayList<>(dateRecord.values());
        allDoctorWradDocs = docs;
    }

    public void addDirectorDoctorWardDoc(DirectorDoctorWardDoc directorDoctorWardDoc) {
        if (StringUtil.isBlank(directorDoctorWardDoc.getStructureMap().get("查房日期"))){
            return;
        }
        Map<Date, DirectorDoctorWardDoc> dateRecord = new TreeMap<>(new Comparator<Date>() {
            @Override
            public int compare(Date o1, Date o2) {
                // 升序排列
                return o1.compareTo(o2);
            }
        });//按时间key排序，存放查房记录
        dateRecord.put(StringUtil.parseDateTime(directorDoctorWardDoc.getStructureMap().get("查房日期")), directorDoctorWardDoc);
        directorDoctorWardDocs.stream().forEach(
             doc ->  dateRecord.put(StringUtil.parseDateTime(doc.getStructureMap().get("查房日期")), doc)
        );

        List<DirectorDoctorWardDoc> docs = new ArrayList<>(dateRecord.values());
        directorDoctorWardDocs = docs;
    }

    public void addAttendingDoctorWardDoc(AttendingDoctorWardDoc attendingDoctorWardDoc) {
        if (StringUtil.isBlank(attendingDoctorWardDoc.getStructureMap().get("查房日期"))){
            return;
        }
        Map<Date, AttendingDoctorWardDoc> dateRecord = new TreeMap<>(new Comparator<Date>() {
            @Override
            public int compare(Date o1, Date o2) {
                // 升序排列
                return o1.compareTo(o2);
            }
        });//按时间key排序，存放查房记录
        dateRecord.put(StringUtil.parseDateTime(attendingDoctorWardDoc.getStructureMap().get("查房日期")), attendingDoctorWardDoc);
        attendingDoctorWardDocs.stream().forEach(
                doc ->  dateRecord.put(StringUtil.parseDateTime(doc.getStructureMap().get("查房日期")), doc)
        );

        List<AttendingDoctorWardDoc> docs = new ArrayList<>(dateRecord.values());
        attendingDoctorWardDocs = docs;
    }

    public void addGeneralDoctorWardDoc(GeneralDoctorWardDoc generalDoctorWardDoc) {
        if (StringUtil.isBlank(generalDoctorWardDoc.getStructureMap().get("查房日期"))){
            return;
        }
        Map<Date, GeneralDoctorWardDoc> dateRecord = new TreeMap<>(new Comparator<Date>() {
            @Override
            public int compare(Date o1, Date o2) {
                // 升序排列
                return o1.compareTo(o2);
            }
        });//按时间key排序，存放查房记录
        dateRecord.put(StringUtil.parseDateTime(generalDoctorWardDoc.getStructureMap().get("查房日期")), generalDoctorWardDoc);
        generalDoctorWardDocs.stream().forEach(
                doc ->  dateRecord.put(StringUtil.parseDateTime(doc.getStructureMap().get("查房日期")), doc)
        );

        List<GeneralDoctorWardDoc> docs = new ArrayList<>(dateRecord.values());
        generalDoctorWardDocs = docs;

    }
}