Search in sources :

Example 1 with XformGroup

use of org.akaza.openclinica.domain.xform.XformGroup in project OpenClinica by OpenClinica.

the class XformMetaDataService method executeIndividualCrf.

public void executeIndividualCrf(ExecuteIndividualCrfObject eicObject) {
    for (OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef : eicObject.formLayoutDefs) {
        List<String> fileLinks = null;
        String vForm = "";
        RestTemplate rest = new RestTemplate();
        if (eicObject.form != null) {
            List<FormVersion> versions = eicObject.form.getVersions();
            for (FormVersion version : versions) {
                if (version.getName().equals(formLayoutDef.getOID())) {
                    fileLinks = version.getFileLinks();
                    for (String fileLink : fileLinks) {
                        if (fileLink.endsWith(VERSION)) {
                            vForm = rest.getForObject(fileLink, String.class);
                            break;
                        }
                    }
                    if (!eicObject.errors.hasErrors()) {
                        ObjectMapper mapper = new ObjectMapper();
                        TypeReference<List<XformGroup>> mapType = new TypeReference<List<XformGroup>>() {
                        };
                        List<XformGroup> jsonList = null;
                        try {
                            jsonList = mapper.readValue(vForm, mapType);
                        } catch (JsonParseException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (JsonMappingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        XformContainer xformContainer = new XformContainer();
                        xformContainer.setGroups(jsonList);
                        eicObject.setContainer(xformContainer);
                        if (eicObject.errors.hasErrors()) {
                            return;
                        }
                        // Save meta-data in database
                        saveFormMetadata(eicObject, version, eicObject.container, formLayoutDef, fileLinks);
                    }
                }
            }
        }
    }
}
Also used : OCodmComplexTypeDefinitionFormLayoutDef(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutDef) XformGroup(org.akaza.openclinica.domain.xform.XformGroup) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) XformContainer(org.akaza.openclinica.domain.xform.XformContainer) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) FormVersion(org.akaza.openclinica.service.dto.FormVersion) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with XformGroup

use of org.akaza.openclinica.domain.xform.XformGroup in project OpenClinica by OpenClinica.

the class XformMetaDataService method createGroups.

private void createGroups(XformContainer container, CrfBean crf, CrfVersion crfVersion, FormLayout formLayout, Section section, UserAccountBean ub, Errors errors) throws Exception {
    Integer itemOrdinal = 1;
    ArrayList<String> usedGroupOids = new ArrayList<String>();
    ArrayList<String> usedItemOids = new ArrayList<String>();
    // for (Group htmlGroup : htmlGroups) {
    for (XformGroup xformGroup : container.getGroups()) {
        // XformGroup xformGroup = container.findGroupByRef(htmlGroup.getRef());
        ItemGroup itemGroup = itemGroupDao.findByNameCrfId(xformGroup.getGroupName(), crf);
        if (itemGroup == null) {
            itemGroup = new ItemGroup();
            itemGroup.setName(xformGroup.getGroupName());
            itemGroup.setLayoutGroupPath(xformGroup.getGroupPath());
            itemGroup.setCrf(crf);
            itemGroup.setStatus(org.akaza.openclinica.domain.Status.AVAILABLE);
            itemGroup.setUserAccount(userDao.findById(ub.getId()));
            itemGroup.setOcOid(xformGroup.getGroupOid());
            usedGroupOids.add(itemGroup.getOcOid());
            itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
        } else {
            itemGroup.setName(xformGroup.getGroupName());
            itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
        }
        boolean isRepeating = xformGroup.isRepeating();
        for (XformItem xformItem : xformGroup.getItems()) {
            Item item = createItem(xformGroup, xformItem, crf, ub, usedItemOids, errors);
            if (item != null) {
                ResponseType responseType = getResponseType(xformItem);
                ResponseSet responseSet = responseSetService.getResponseSet(xformItem, crfVersion, responseType, item, errors);
                // add if statement
                ItemFormMetadata ifmd = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
                if (ifmd == null) {
                    ifmd = createItemFormMetadata(xformItem, item, responseSet, section, crfVersion, itemOrdinal);
                } else {
                    ifmd.setRequired(xformItem.isRequired());
                    ifmd.setLeftItemText(xformItem.getLeftItemText());
                    ifmd.setItem(item);
                    ifmd.setResponseSet(responseSet);
                    ifmd = itemFormMetadataDao.saveOrUpdate(ifmd);
                }
                ArrayList<VersioningMap> vm = versioningMapDao.findByVersionIdFormLayoutIdAndItemId(crfVersion.getCrfVersionId(), formLayout.getFormLayoutId(), item.getItemId(), itemOrdinal);
                if (vm.size() == 0) {
                    createVersioningMap(crfVersion, item, formLayout, xformItem.getItemOrderInForm());
                }
                //
                ItemGroupMetadata igmd = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
                if (igmd == null) {
                    igmd = createItemGroupMetadata(item, crfVersion, itemGroup, isRepeating, itemOrdinal);
                }
                itemOrdinal++;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) XformGroup(org.akaza.openclinica.domain.xform.XformGroup) ResponseSet(org.akaza.openclinica.domain.datamap.ResponseSet) ItemFormMetadata(org.akaza.openclinica.domain.datamap.ItemFormMetadata) VersioningMap(org.akaza.openclinica.domain.datamap.VersioningMap) ResponseType(org.akaza.openclinica.domain.datamap.ResponseType) Item(org.akaza.openclinica.domain.datamap.Item) XformItem(org.akaza.openclinica.domain.xform.XformItem) FileItem(org.apache.commons.fileupload.FileItem) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) XformItem(org.akaza.openclinica.domain.xform.XformItem) ItemGroup(org.akaza.openclinica.domain.datamap.ItemGroup) ItemGroupMetadata(org.akaza.openclinica.domain.datamap.ItemGroupMetadata)

Aggregations

ArrayList (java.util.ArrayList)2 XformGroup (org.akaza.openclinica.domain.xform.XformGroup)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 List (java.util.List)1 Item (org.akaza.openclinica.domain.datamap.Item)1 ItemFormMetadata (org.akaza.openclinica.domain.datamap.ItemFormMetadata)1 ItemGroup (org.akaza.openclinica.domain.datamap.ItemGroup)1 ItemGroupMetadata (org.akaza.openclinica.domain.datamap.ItemGroupMetadata)1 ResponseSet (org.akaza.openclinica.domain.datamap.ResponseSet)1 ResponseType (org.akaza.openclinica.domain.datamap.ResponseType)1 VersioningMap (org.akaza.openclinica.domain.datamap.VersioningMap)1 XformContainer (org.akaza.openclinica.domain.xform.XformContainer)1 XformItem (org.akaza.openclinica.domain.xform.XformItem)1 FormVersion (org.akaza.openclinica.service.dto.FormVersion)1 FileItem (org.apache.commons.fileupload.FileItem)1 DiskFileItem (org.apache.commons.fileupload.disk.DiskFileItem)1