*/
@Override
public boolean fixFollowUp() throws ClipsServerException {
HashMap<Integer, FollowDownReason> fdmap = new HashMap<Integer, FollowDownReason>();
FollowupReason upReason = findEntity(FollowupReason.class, 3);
FollowDownReason downReason = findEntity(FollowDownReason.class, 1);
List<FollowDownReason> fdList = findEntityList(FollowDownReason.class);
for (FollowDownReason fd : fdList) {
fdmap.put(Integer.parseInt(fd.getExtKey()), fd);
}
Set<Entry<FollowUpKey, ArrayList<EventKey>>> entrySet = followMap.entrySet();
if (counter == null) {
counter = 0;
}
if (size == null) {
System.out.println("Запись диспансеризаций - начало процесса");
size = followMap.size();
}
for (Iterator<Entry<FollowUpKey, ArrayList<EventKey>>> it = entrySet.iterator(); it.hasNext();) {
Entry<FollowUpKey, ArrayList<EventKey>> entry = it.next();
ArrayList<EventKey> bigEventKeyList = entry.getValue();
//сортируем по дате постановки диагноза
Collections.sort(bigEventKeyList);
ArrayList<ArrayList<EventKey>> dividedList = divideEvents(bigEventKeyList);
for (ArrayList<EventKey> eventKeyList : dividedList) {
ArrayList<Diagnosis> diagList = new ArrayList<Diagnosis>();
for (EventKey eventKey : eventKeyList) {
diagList.add(findEntity(Diagnosis.class, eventKey.diagID));
}
Diagnosis diagUp = diagList.get(0);
/*определяем diagDown - если при последнем диагнозе было снятие с
диспансеризации то diagDown не нулл
* */
Diagnosis diagDown = diagList.get(diagList.size() - 1);
int disp = 0;
int dispSn = 0;
for (EventKey eventKey : eventKeyList) {
if (eventKey.diagID == diagDown.getId()) {
disp = eventKey.disp;
dispSn = eventKey.dispSn;
}
}
if (disp != 4) {
diagDown = null;
}
Followup followup = new Followup();
followup.setDateup(diagUp.getDate());
followup.setDatedown(diagDown == null ? null : diagDown.getDate());
followup.setCollaboratorUp(diagUp.getServiceRender().getDisease().getCollaborator());
followup.setCollaboratorDown(diagDown == null ? null : diagDown.getServiceRender().getDisease().getCollaborator());
followup.setUpReason(upReason);
FollowDownReason fd = fdmap.get(dispSn);
if (fd == null) {
fd = downReason;
}
followup.setDownReason(diagDown == null ? null : fd);
followup.setValue(null);