// Path: app/jobs/Downloader.java
// public static enum Format {
// 	dcm, //DICOM
// 	nii, //NIfTI
// 	img  //Analyze
// }
// 
// Path: app/models/Files.java
// @Entity
// public class Files extends DomainModel {
// 
// 	public String filepath;
// 	public long file_size;
// 	@ManyToOne
// 	@JoinColumn(name="instance_fk")
// 	public Instance instance;
// 
// 	public String toDownloadString() {
// 		return String.format("%s_%s", instance.series.toDownloadString(), StringUtils.leftPad(instance.inst_no, 3, '0'));
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return String.format("%s", pk);
// 	}
// }
// 
// Path: app/models/ProjectAssociation.java
// @Entity
// public class ProjectAssociation extends Model {
// 
// 	@Index(name="participationid")
// 	public String participationID;
// 	@ManyToOne
// 	public Project project;
// 	@ManyToOne
// 	public Study study;
// 
// 	public ProjectAssociation(Project project, Study study) {
// 		this.project = project;
// 		this.study = study;
// 	}
// 
// }
// 
// Path: app/models/Series.java
// @Entity
// public class Series extends DomainModel {
// 
// 	public String series_no;
// 	public String series_iuid;
// 	public String station_name;
// 	public String series_desc;
// 	public String modality;
// 	@ManyToOne
// 	@JoinColumn(name="study_fk")
// 	public Study study;
// 	@OneToMany(mappedBy = "series")
// 	public Set<Instance> instances;
// 
// 	public String toDownloadString() {
// 		return String.format("%s_%s_%s", study.toDownloadString(), series_no, series_desc).replaceAll("\\W+", "");
// 	}
// 
// }
// 
// Path: app/models/Study.java
// @Entity
// //@NamedNativeQuery(name = "nativeSQL", query = "select * from study", resultClass = Study.class)
// public class Study extends DomainModel {
// 
// 	public String study_id;
// 	public String study_desc;
// 	public Date study_datetime;
// 	public String study_custom1;
// 	public Date created_time;
// 	@ManyToOne
// 	@JoinColumn(name="patient_fk")
// 	public Patient patient;
// 	@OneToMany(mappedBy = "study")
// 	public Set<Series> series;
// 	@OneToMany(mappedBy = "study")
// 	public Set<ProjectAssociation> projectAssociations;
// 
// 	public List<ProjectAssociation> getProjectAssociations() {
// 		return ProjectAssociation.find("select projectAssociation from Project project, in(project.projectAssociations) projectAssociation where projectAssociation.study = ?", this).fetch();
// 	}
// 
// 	public String toDownloadString() {
// 		List<String> parts = new ArrayList<String>();
// 		List<ProjectAssociation> projectAssociations = getProjectAssociations();
// 		if (projectAssociations.size() > 0) {
// 			ProjectAssociation projectAssociation = projectAssociations.iterator().next();
// 			if (projectAssociation.participationID != null && !projectAssociation.participationID.isEmpty()) {
// 				parts.add(projectAssociation.participationID);
// 			}
// 			parts.add(projectAssociation.project.name);
// 		}
// 		parts.add(new SimpleDateFormat("yyyyMMddHHmm").format(study_datetime));
// 		String station_name = getStation_name();
// 		if (station_name != null) {
// 			parts.add(station_name);
// 		}
// 		return StringUtils.join(parts, "_").replaceAll("\\W+", "");
// 	}
// 
// 	public String getStation_name() {
// 		Series scannedSeries = (Series) CollectionUtils.find(series, new Predicate() {
// 			@Override
// 			public boolean evaluate(Object arg0) {
// 				return ((Series) arg0).station_name != null;
// 			}
// 		});
// 		return scannedSeries == null ? null : scannedSeries.station_name;
// 	}
// 
// }


import java.io.File;
import jobs.Downloader.Format;
import models.Files;
import models.ProjectAssociation;
import models.Series;
import models.Study;
package util;



public class Download {

	public static void study(Study study, File tmpDir, Format format, Boolean preferMultiframe, String niftiMultiframeScript) throws Exception {
// Path: app/jobs/Downloader.java
// public static enum Format {
// 	dcm, //DICOM
// 	nii, //NIfTI
// 	img  //Analyze
// }
// 
// Path: app/models/Files.java
// @Entity
// public class Files extends DomainModel {
// 
// 	public String filepath;
// 	public long file_size;
// 	@ManyToOne
// 	@JoinColumn(name="instance_fk")
// 	public Instance instance;
// 
// 	public String toDownloadString() {
// 		return String.format("%s_%s", instance.series.toDownloadString(), StringUtils.leftPad(instance.inst_no, 3, '0'));
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return String.format("%s", pk);
// 	}
// }
// 
// Path: app/models/ProjectAssociation.java
// @Entity
// public class ProjectAssociation extends Model {
// 
// 	@Index(name="participationid")
// 	public String participationID;
// 	@ManyToOne
// 	public Project project;
// 	@ManyToOne
// 	public Study study;
// 
// 	public ProjectAssociation(Project project, Study study) {
// 		this.project = project;
// 		this.study = study;
// 	}
// 
// }
// 
// Path: app/models/Series.java
// @Entity
// public class Series extends DomainModel {
// 
// 	public String series_no;
// 	public String series_iuid;
// 	public String station_name;
// 	public String series_desc;
// 	public String modality;
// 	@ManyToOne
// 	@JoinColumn(name="study_fk")
// 	public Study study;
// 	@OneToMany(mappedBy = "series")
// 	public Set<Instance> instances;
// 
// 	public String toDownloadString() {
// 		return String.format("%s_%s_%s", study.toDownloadString(), series_no, series_desc).replaceAll("\\W+", "");
// 	}
// 
// }
// 
// Path: app/models/Study.java
// @Entity
// //@NamedNativeQuery(name = "nativeSQL", query = "select * from study", resultClass = Study.class)
// public class Study extends DomainModel {
// 
// 	public String study_id;
// 	public String study_desc;
// 	public Date study_datetime;
// 	public String study_custom1;
// 	public Date created_time;
// 	@ManyToOne
// 	@JoinColumn(name="patient_fk")
// 	public Patient patient;
// 	@OneToMany(mappedBy = "study")
// 	public Set<Series> series;
// 	@OneToMany(mappedBy = "study")
// 	public Set<ProjectAssociation> projectAssociations;
// 
// 	public List<ProjectAssociation> getProjectAssociations() {
// 		return ProjectAssociation.find("select projectAssociation from Project project, in(project.projectAssociations) projectAssociation where projectAssociation.study = ?", this).fetch();
// 	}
// 
// 	public String toDownloadString() {
// 		List<String> parts = new ArrayList<String>();
// 		List<ProjectAssociation> projectAssociations = getProjectAssociations();
// 		if (projectAssociations.size() > 0) {
// 			ProjectAssociation projectAssociation = projectAssociations.iterator().next();
// 			if (projectAssociation.participationID != null && !projectAssociation.participationID.isEmpty()) {
// 				parts.add(projectAssociation.participationID);
// 			}
// 			parts.add(projectAssociation.project.name);
// 		}
// 		parts.add(new SimpleDateFormat("yyyyMMddHHmm").format(study_datetime));
// 		String station_name = getStation_name();
// 		if (station_name != null) {
// 			parts.add(station_name);
// 		}
// 		return StringUtils.join(parts, "_").replaceAll("\\W+", "");
// 	}
// 
// 	public String getStation_name() {
// 		Series scannedSeries = (Series) CollectionUtils.find(series, new Predicate() {
// 			@Override
// 			public boolean evaluate(Object arg0) {
// 				return ((Series) arg0).station_name != null;
// 			}
// 		});
// 		return scannedSeries == null ? null : scannedSeries.station_name;
// 	}
// 
// }


// Path: app/util/Download.java
import java.io.File;
import jobs.Downloader.Format;
import models.Files;
import models.ProjectAssociation;
import models.Series;
import models.Study;

package util;



public class Download {

	public static void study(Study study, File tmpDir, Format format, Boolean preferMultiframe, String niftiMultiframeScript) throws Exception {
		for (Series series : study.series) {