/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.delegate.directory.complex;
import beans.directory.mkb10.DirectoryMKB10BeanRemote;
import beans.directory.mkb10.MKBCode;
import beans.directory.mkb10.MKBParser;
import cli_fmw.delegate.directory.DirectoryItemRO;
import beans.directory.mkb10.entity.Mkb10Details;
import cli_fmw.delegate.directory.DirectoryItemRecursive;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.Selector;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
/**
* Делегат, предоставляющий доступ к одной строке таблицы MKB10
* @author ViP
*/
public class DirectoryMKB10Item extends
DirectoryItemRecursive<
DirectoryMKB10Item,
Mkb10Details> {
private MKBCode decodedCode;
/**
* сделал public иначе как создавать новые итемы, все методы были протектед
* @param details
*/
public DirectoryMKB10Item(Mkb10Details details) {
super(details);
}
/**
* Оповещать или нет санэпидемстанци о заболевании
* @return
*/
public boolean getMustNotify() {
return getDetails().mustNotify;
}
/**
* Оповещать или нет санэпидемстанци о заболевании
* @param notify
* @throws ClipsException
*/
public void setMustNotify(boolean notify) throws ClipsException {
if(isInDirectory()) {
Mkb10Details newDetails = getDetailsCopy();
newDetails.mustNotify = notify;
saveDetails(newDetails);
} else {
getDetails().mustNotify = notify;
}
}
/**
* Является ли заболевание инфекционным
* @return
*/
public boolean isInfectious() {
return getDetails().infectious;
}
/**
* Является ли заболевание инфекционным
* @param boolean infectious
* @throws ClipsException
*/
public void setInfectious(boolean infectious) throws ClipsException {
if (isInDirectory()) {
Mkb10Details newDetails = getDetailsCopy();
newDetails.infectious = infectious;
saveDetails(newDetails);
} else {
getDetails().infectious = infectious;
}
}
/**
* Код заболевания
* @return
*/
public String getDiseaseCode() {
return getDetails().code;
}
/**
* Код заболевания
* @param code
* @throws ClipsException
*/
public void setDiseaseCode(String code) throws ClipsException {
decodedCode = null;
if(isInDirectory()) {
Mkb10Details newDetails = getDetailsCopy();
newDetails.code = code;
saveDetails(newDetails);
} else {
getDetails().code = code;
}
}
public String getShortTitle() {
return getDetails().shortTitle;
}
public void setShortTitle(String shortTitle) throws ClipsException {
if (isInDirectory()) {
Mkb10Details newDetails = getDetailsCopy();
newDetails.shortTitle = shortTitle;
saveDetails(newDetails);
} else {
getDetails().shortTitle = shortTitle;
}
}
@Override
public String toString() {
if(getDiseaseCode() != null && !getDiseaseCode().isEmpty()) {
return getDiseaseCode() + " - " + getTitle();
}
return getTitle();
}
@Override
public int compareTo(DirectoryItemRO item) {
return getDiseaseCode().compareTo(((DirectoryMKB10Item)item).getDiseaseCode());
}
public boolean isChild(DirectoryMKB10Item item) {
DirectoryMKB10Item thisItem = this;
while (thisItem.getParent() != null) {
thisItem = thisItem.getParent();
if (thisItem.getID() == item.getID()) {
return true;
}
}
return false;
}
public MKBCode getDecodedCode() throws ParseException {
if (decodedCode == null){
decodedCode = MKBParser.decodeWellFormed(getDiseaseCode());
}
return decodedCode;
}
public void validateRecursive() throws ParseException, ClipsException{
Selector<DirectoryMKB10Item> items = getItems();
validateList(items, getDecodedCode());
int size = items.size();
for (int i = 0; i < size; i++){
DirectoryMKB10Item item = items.get(i);
item.validateRecursive();
}
}
static void validateList(Selector<DirectoryMKB10Item> items, MKBCode parent) throws ParseException, ClipsException{
int size = items.size();
MKBCode last = null;
for (int i = 0; i < size; i++){
DirectoryMKB10Item item = items.get(i);
if (item.getID() == 0){
continue;
}
MKBCode mKBCode = item.getDecodedCode();
if (parent != null
&& (parent.advanceCompare(mKBCode) != MKBCode.CompareResould.contains
|| mKBCode.advanceCompare(parent) != MKBCode.CompareResould.inside)){
throw new ClipsException("Код " + parent + " не содержит в себе код " + mKBCode);
}
if (last != null
&& (last.advanceCompare(mKBCode) != MKBCode.CompareResould.less
|| mKBCode.advanceCompare(last) != MKBCode.CompareResould.more)){
throw new ClipsException("Код " + mKBCode + " пересекается с кодом " + last + ", или неправильно расположен");
}
}
}
/**
* Соответствует ли тип диагноза травме
* @return
*/
public boolean isTrauma(){
return getDiseaseCode() != null ? (getDiseaseCode().startsWith("S") || getDiseaseCode().startsWith("T")) : false;
}
public boolean isHealthy(){
return getDiseaseCode() != null ? getDiseaseCode().startsWith("Z") : false;
}
}