/* * Copyright 2009 IHE International (http://www.ihe.net) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.ihe.swfid.action; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Field; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import net.ihe.gazelle.simulator.common.model.ApplicationConfiguration; import net.ihe.swfid.tools.DcmQRSimulator; import net.ihe.swfid.tools.TestConnection; import org.dcm4che2.data.DicomObject; import org.dcm4che2.data.Tag; import org.dcm4che2.net.ConfigurationException; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.faces.FacesMessages; import org.jboss.seam.log.Log; /** * @author Abderrazek Boufahja > INRIA Rennes IHE development Project * */ @Stateful @Name("searchManager") @Scope(ScopeType.SESSION) public class SearchManager implements SearchManagerLocal, Serializable{ /** * */ private static final long serialVersionUID = -8734567233751607120L; //~ Statics variables and Class initializer //////////////////////////////////////// /** Logger */ @Logger private static Log log; //~ Attribute /////////////////////////////////////////////////////////////////////// private List listTag; private String selectedCriteria; private String selectedQueryValue; private String selectedHost; private Integer selectedPort; private String selectedAET; private String searchResults; //~ getters and setters ///////////////////////////////////////////////////////////// public void setSearchResults(String searchResults) { this.searchResults = searchResults; } public String getSearchResults() { return searchResults; } public String getSelectedQueryValue() { return selectedQueryValue; } public void setSelectedQueryValue(String selectedQueryValue) { this.selectedQueryValue = selectedQueryValue; } public String getSelectedHost() { if(selectedHost==null) selectedHost = ApplicationConfiguration.getValueOfVariable("SWFID-HOST"); return selectedHost; } public void setSelectedHost(String selectedHost) { this.selectedHost = selectedHost; } public Integer getSelectedPort() { if(selectedPort==null) selectedPort = Integer.valueOf(ApplicationConfiguration.getValueOfVariable("SWFID-PORT")); return selectedPort; } public void setSelectedPort(Integer selectedPort) { this.selectedPort = selectedPort; } public String getSelectedAET() { if(selectedAET==null) selectedAET = ApplicationConfiguration.getValueOfVariable("SWFID-AET"); return selectedAET; } public void setSelectedAET(String selectedAET) { this.selectedAET = selectedAET; } public void setSelectedCriteria(String selectedCriteria) { this.selectedCriteria = selectedCriteria; } public String getSelectedCriteria() { return selectedCriteria; } public void setListTag(List listTag) { this.listTag = listTag; } public List getListTag() { if (listTag == null){ listTag = new ArrayList(); Field[] lf = Tag.class.getFields(); for (Field f: lf){ listTag.add(f.getName()); } } Collections.sort(listTag); return listTag; } public static void setLog(Log log) { SearchManager.log = log; } public static Log getLog() { return log; } // methods ///////////////////////////////////////////////////////////////////////// public void initializeCriterias(){ this.searchResults = new String(); } public void searchPatients() throws IOException, ConfigurationException, InterruptedException{ if ( (this.selectedCriteria == null) || (this.selectedHost == null) || (this.selectedPort == null) || (this.selectedQueryValue == null) || (this.selectedAET== null) ){ FacesMessages.instance().add("One criteria of research was not specified."); return; } if ( (this.selectedCriteria.equals("")) || (this.selectedHost.equals("")) || (this.selectedQueryValue.equals("")) || (this.selectedAET.equals("")) ){ FacesMessages.instance().add("One criteria of research was not specified."); return; } this.searchResults = new String(); DcmQRSimulator dqrs = new DcmQRSimulator(); List ldo = dqrs.getListDicomObjectFromTag(this.selectedHost, this.selectedPort.intValue(), this.selectedAET, this.selectedCriteria, this.selectedQueryValue); this.searchResults = this.searchResults + "## Number of Patients : " + ldo.size() + "\n\n"; for (DicomObject dobj:ldo){ this.searchResults = this.searchResults + dobj.toString() + "\n\n"; } } public void testConnexion() { boolean res = TestConnection.testConnection(selectedAET, selectedHost, String.valueOf(selectedPort)); if (res){ FacesMessages.instance().add("Echo DICOM : successful !"); } else{ FacesMessages.instance().add("Echo DICOM : Connection refused."); } } // destroy method /////////////////////////////////////////////////////////////////// @Destroy @Remove public void destroy() { log.info("destroy"); } }