use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class SPSSReportBean method getMetadataFile.
public StringBuffer getMetadataFile(SPSSVariableNameValidator svnv, ExtractBean eb) {
itemNames.clear();
// Is it necessary to
String[] attributes = createAttributes(eb);
// validate
// StudyGroupClassBean
// names? YW
String[] attributeTypes = createAttributeTypes(eb);
StringBuffer answer = new StringBuffer();
answer.append("* NOTE: If you have put this file in a different folder \n" + "* from the associated data file, you will have to change the FILE \n" + "* location on the line below to point to the physical location of your data file.\n");
answer.append("GET DATA " + "/TYPE = TXT" + "/FILE = '" + getDatFileName() + "' " + "/DELCASE = LINE " + "/DELIMITERS = \"\\t\" " + "/ARRANGEMENT = DELIMITED " + "/FIRSTCASE = " + FIRSTCASE + " " + // since
"/IMPORTCASE = ALL ");
if (data.size() <= 0) {
answer.append(".\n");
} else {
ArrayList columns = (ArrayList) data.get(this.COLUMNS_IND);
int startItem = columns.size() - items.size();
logger.debug("--> generated start item " + startItem + " from " + columns.size() + " minus " + items.size());
answer.append("/VARIABLES = \n");
int index;
for (int i = 0; i < columns.size(); i++) {
String itemName = (String) columns.get(i);
// YW << Why do we need "V_" here? Right now it has been
// removed, because:
// This "V_" exists in .sps file but not exists in .dat file.
// String varLabel = "V_" + itemName;
String varLabel = svnv.getValidName(itemName);
itemNames.add(varLabel);
// builtin attributes
if (i < startItem) {
if (varLabel.startsWith("Gender")) {
gender = true;
}
index = builtinIndex(varLabel, attributes);
logger.debug("varLabel[" + varLabel + "] index[" + index + "] attributeTypes[" + attributeTypes[1] + "]");
answer.append("\t" + varLabel + " " + attributeTypes[index]);
// >> tbh #5524
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
ItemBean ib = dih.getItem();
// << tbh
if (attributeTypes[index].equals("A")) {
int len = getDataColumnMaxLen(i);
if (len == 0) {
// mininum length required by spss
len = 1;
}
// >> tbh #5524
ArrayList metas = ib.getItemMetas();
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
ArrayList options = rsb.getOptions();
for (int l = 0; l < options.size(); l++) {
ResponseOptionBean ro = (ResponseOptionBean) options.get(l);
if (ro.getText().length() > len) {
len = ro.getText().length();
}
}
}
// << tbh
if (len > 8) {
len = 8;
}
answer.append(len);
}
answer.append("\n");
}
// YW >>
}
// items
logger.debug("--> looking at " + startItem + " out of " + columns.size());
for (int i = startItem; i < columns.size(); i++) {
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i - startItem);
ItemBean ib = dih.getItem();
// YW <<
String varLabel = (String) itemNames.get(i);
int dataTypeId = ib.getItemDataTypeId();
// String.
if (dataTypeId == 9) {
// date
answer.append("\t" + varLabel + " ADATE10\n");
} else if (dataTypeId == 7) {
// float
answer.append("\t" + varLabel + " F8.2\n");
} else if (dataTypeId == 6 && isIntType(ib)) {
// pure int data
// type for one
// item.
answer.append("\t" + varLabel + " F8.0\n");
} else {
// string
// YW >>
int len = getDataColumnMaxLen(i);
if (len == 0) {
// mininum length required by spss
len = 1;
}
ArrayList metas = ib.getItemMetas();
int optionCount = 0;
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
if (rsb.getResponseType().equals(ResponseType.CHECKBOX) || rsb.getResponseType().equals(ResponseType.RADIO) || rsb.getResponseType().equals(ResponseType.SELECT) || rsb.getResponseType().equals(ResponseType.SELECTMULTI)) {
optionCount++;
}
// tbh >> #5524: all possible response value options should be reviewed so that length is OK
ArrayList options = rsb.getOptions();
for (int l = 0; l < options.size(); l++) {
ResponseOptionBean ro = (ResponseOptionBean) options.get(l);
if (ro.getText().length() > len) {
len = ro.getText().length();
}
}
// << tbh
}
if (optionCount == metas.size()) {
// value labels
if (len > 8) {
len = 8;
}
}
answer.append("\t" + varLabel + " A" + len + "\n");
}
}
answer.append(".\n");
answer.append("VARIABLE LABELS\n");
// builtin attributes
for (int i = 0; i < startItem; ++i) {
String varLabel = (String) itemNames.get(i);
if ((String) descriptions.get(itemNames.get(i)) != null) {
answer.append("\t" + varLabel + " \"" + (String) descriptions.get(itemNames.get(i)) + "\"\n");
} else {
for (int j = 0; j < eb.getStudyGroupClasses().size(); ++j) {
answer.append("\t" + varLabel + " \"" + (String) descriptions.get(((StudyGroupClassBean) eb.getStudyGroupClasses().get(j)).getName()) + "\"\n");
}
}
}
// items
for (int i = startItem; i < itemNames.size(); i++) {
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i - startItem);
ItemBean ib = dih.getItem();
String varLabel = (String) itemNames.get(i);
answer.append("\t" + varLabel + " \"" + ib.getDescription() + "\"\n");
}
answer.append(".\n");
answer.append("VALUE LABELS\n");
if (isGender()) {
answer.append("\t" + "Gender" + "\n");
answer.append("\t" + "'M'" + " \"" + "Male" + "\"\n");
answer.append("\t" + "'F'" + " \"" + "Female" + "\"\n\t/\n");
}
for (int i = 0; i < items.size(); i++) {
String temp = "";
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
ItemBean ib = dih.getItem();
String varLabel = (String) itemNames.get(i + startItem);
temp += "\t" + varLabel + "\n";
boolean allOption = true;
ArrayList metas = ib.getItemMetas();
HashMap optionMap = new LinkedHashMap();
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
if (rsb.getResponseType().equals(ResponseType.TEXT) || rsb.getResponseType().equals(ResponseType.FILE) || rsb.getResponseType().equals(ResponseType.TEXTAREA)) {
// has text response, dont show value labels
allOption = false;
break;
} else {
for (int j = 0; j < rsb.getOptions().size(); j++) {
ResponseOptionBean ob = (ResponseOptionBean) rsb.getOptions().get(j);
String key = ob.getValue();
if (optionMap.containsKey(key)) {
ArrayList a = (ArrayList) optionMap.get(key);
if (!a.contains(ob.getText())) {
a.add(ob.getText());
optionMap.put(key, a);
}
} else {
ArrayList a = new ArrayList();
a.add(ob.getText());
optionMap.put(key, a);
}
}
}
}
Iterator it = optionMap.keySet().iterator();
while (it.hasNext()) {
String value = (String) it.next();
ArrayList a = (ArrayList) optionMap.get(value);
String texts = "";
if (a.size() > 1) {
for (int n = 0; n < a.size(); n++) {
texts += (String) a.get(n);
if (n < a.size() - 1) {
texts += "/";
}
}
} else {
texts = (String) a.get(0);
}
if (value.length() > 8) {
value = value.substring(0, 8);
}
if (isValueText(value)) {
temp += "\t'" + value + "' \"" + texts + "\"\n";
} else {
temp += "\t" + value + " \"" + texts + "\"\n";
}
}
if (allOption) {
answer.append(temp + "\t/\n");
}
}
}
answer.append(".\n EXECUTE.\n");
return answer;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class SPSSReportBean method isIntType.
// YW
private boolean isIntType(ItemBean ib) {
ArrayList metas = ib.getItemMetas();
for (int k = 0; k < metas.size(); k++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(k);
ResponseSetBean rsb = ifmb.getResponseSet();
if (rsb.getResponseType().equals(ResponseType.TEXT) || rsb.getResponseType().equals(ResponseType.TEXTAREA)) {
return true;
}
}
return false;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ItemDAO method findAllActiveByCRF.
public ArrayList findAllActiveByCRF(CRFBean crf) {
HashMap variables = new HashMap();
this.setTypesExpected();
// crf_version_id
this.setTypeExpected(14, TypeNames.INT);
// version name
this.setTypeExpected(15, TypeNames.STRING);
variables.put(new Integer(1), new Integer(crf.getId()));
String sql = digester.getQuery("findAllActiveByCRF");
ArrayList alist = this.select(sql, variables);
ArrayList al = new ArrayList();
Iterator it = alist.iterator();
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
ItemBean eb = (ItemBean) this.getEntityFromHashMap(hm);
Integer versionId = (Integer) hm.get("crf_version_id");
String versionName = (String) hm.get("cvname");
ItemFormMetadataBean imf = new ItemFormMetadataBean();
imf.setCrfVersionName(versionName);
// logger.info("versionName" + imf.getCrfVersionName());
imf.setCrfVersionId(versionId.intValue());
eb.setItemMeta(imf);
al.add(eb);
}
return al;
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ItemFormMetadataDAO method findByItemIdAndCRFVersionId.
public ItemFormMetadataBean findByItemIdAndCRFVersionId(int itemId, int crfVersionId) {
this.setTypesExpected();
// TODO note to come back here, tbh
// version name
this.setTypeExpected(28, TypeNames.STRING);
// add more here for display, tbh 082007
// group_label
this.setTypeExpected(29, TypeNames.STRING);
// repeat_max
this.setTypeExpected(30, TypeNames.INT);
// section_name
this.setTypeExpected(31, TypeNames.STRING);
logMe("Current Thread:::" + Thread.currentThread() + "types Expected?");
HashMap<Integer, Object> variables = new HashMap<Integer, Object>();
variables.put(new Integer(1), new Integer(itemId));
variables.put(new Integer(2), new Integer(crfVersionId));
String sql = digester.getQuery("findByItemIdAndCRFVersionId");
logMe("Thread?" + Thread.currentThread() + "SQL?" + sql + "variables?" + variables);
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
ItemFormMetadataBean ifmb = new ItemFormMetadataBean();
HashMap hm = new HashMap();
if (it.hasNext()) {
hm = (HashMap) it.next();
ifmb = (ItemFormMetadataBean) this.getEntityFromHashMap(hm);
}
// EntityBean eb =
// this.executeFindByPKQuery("findByItemIdAndCRFVersionId", variables);
/*
* if (!ifmb.isActive()) { return new ItemFormMetadataBean(); } else {
*/
// ItemFormMetadataBean ifmb = (ItemFormMetadataBean) eb;
String versionName = (String) hm.get("cvname");
String groupLabel = (String) hm.get("group_label");
String sectionName = (String) hm.get("section_name");
Integer repeatMax = (Integer) hm.get("repeat_max");
int repeatMaxInt = repeatMax != null ? repeatMax.intValue() : 0;
// caught an NPE here, tbh 082007?
// new Integer((Integer)hm.get("repeat_max")).intValue();
ifmb.setCrfVersionName(versionName);
ifmb.setGroupLabel(groupLabel);
// logger.info(">>>added group name: "+groupLabel);
ifmb.setSectionName(sectionName);
// logger.info("<<<added section name: "+sectionName);
ifmb.setRepeatMax(repeatMaxInt);
// return (ItemFormMetadataBean) eb;
return ifmb;
// }
}
use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.
the class ItemFormMetadataDAO method findAllItemsRequiredAndHiddenByCrfVersionId.
public ArrayList<ItemFormMetadataBean> findAllItemsRequiredAndHiddenByCrfVersionId(int crfVersionId) {
ArrayList<ItemFormMetadataBean> answer = new ArrayList<ItemFormMetadataBean>();
this.setTypesExpected();
HashMap<Integer, Object> variables = new HashMap<Integer, Object>();
variables.put(new Integer(1), new Integer(crfVersionId));
String sql = digester.getQuery("findAllItemsRequiredAndHiddenByCrfVersionId");
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
while (it.hasNext()) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) this.getEntityFromHashMap((HashMap) it.next());
answer.add(ifmb);
}
return answer;
}
Aggregations