001/* ***** BEGIN LICENSE BLOCK ***** 002 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 003 * 004 * The contents of this file are subject to the Mozilla Public License Version 005 * 1.1 (the "License"); you may not use this file except in compliance with 006 * the License. You may obtain a copy of the License at 007 * http://www.mozilla.org/MPL/ 008 * 009 * Software distributed under the License is distributed on an "AS IS" basis, 010 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 011 * for the specific language governing rights and limitations under the 012 * License. 013 * 014 * The Original Code is part of dcm4che, an implementation of DICOM(TM) in 015 * Java(TM), hosted at https://github.com/gunterze/dcm4che. 016 * 017 * The Initial Developer of the Original Code is 018 * Agfa Healthcare. 019 * Portions created by the Initial Developer are Copyright (C) 2012 020 * the Initial Developer. All Rights Reserved. 021 * 022 * Contributor(s): 023 * See @authors listed below 024 * 025 * Alternatively, the contents of this file may be used under the terms of 026 * either the GNU General Public License Version 2 or later (the "GPL"), or 027 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 028 * in which case the provisions of the GPL or the LGPL are applicable instead 029 * of those above. If you wish to allow use of your version of this file only 030 * under the terms of either the GPL or the LGPL, and not to allow others to 031 * use your version of this file under the terms of the MPL, indicate your 032 * decision by deleting the provisions above and replace them with the notice 033 * and other provisions required by the GPL or the LGPL. If you do not delete 034 * the provisions above, a recipient may use your version of this file under 035 * the terms of any one of the MPL, the GPL or the LGPL. 036 * 037 * ***** END LICENSE BLOCK ***** */ 038package org.dcm4che3.tool.qc.test; 039 040import org.apache.commons.cli.MissingArgumentException; 041import org.dcm4che3.data.*; 042import org.dcm4che3.tool.common.test.TestResult; 043import org.dcm4che3.tool.common.test.TestTool; 044import org.dcm4che3.tool.qc.QC; 045import org.dcm4che3.tool.qc.QCOperation; 046import org.dcm4che3.tool.qc.QCUpdateScope; 047 048import java.util.ArrayList; 049 050/** 051 * @author Hesham Elbadawi <bsdreko@gmail.com> 052 * 053 */ 054 055public class QCTool implements TestTool { 056 private QC qc; 057 private TestResult result; 058 059 public QCTool(String url, QCOperation operation, Code code, String targetStudyUID) { 060 qc = new QC(url, code, operation); 061 qc.setTargetStudyUID(targetStudyUID); 062 } 063 064 public QCTool(String url, QCOperation operation, String codeString, String targetStudyUID) { 065 this(url, operation, decodeCode(codeString), targetStudyUID); 066 } 067 068 private static Code decodeCode(String codeString) { 069 Code code = null; 070 String[] codeComponents = codeString.split(":"); 071 if(codeComponents.length < 3) { 072 throw new IllegalArgumentException("Code string specified must contain at least value, scheme designator and meaning"); 073 } else { 074 if(codeComponents.length == 3) { 075 code = new Code(codeComponents[0], codeComponents[2], null,codeComponents[1]); 076 } else if(codeComponents.length == 4) { 077 code = new Code(codeComponents[0], codeComponents[2], codeComponents[3], codeComponents[1]); 078 } 079 } 080 081 return code; 082 } 083 084 @Override 085 public void init(TestResult result) { 086 this.result = result; 087 } 088 089 @Override 090 public TestResult getResult() { 091 return this.result; 092 } 093 /** 094 * merge. 095 * Calls the tool to merge a study into the target patient. 096 * 097 * @param testDescription 098 * the test description 099 * @param mergeUIDs 100 * the sop instance uids of the studies to merge 101 * @param targetStudyAttrs 102 * the target study attributes to be updated 103 * @param targetSeriesAttrs 104 * the target series attributes to be updated 105 * @param pid 106 * the patient ID of the target patient 107 */ 108 public void merge(String testDescription, 109 ArrayList<String> mergeUIDs, Attributes targetStudyAttrs, 110 Attributes targetSeriesAttrs, IDWithIssuer pid) { 111 qc.setMergeUIDs(mergeUIDs); 112 qc.setTargetSeriesAttrs(targetSeriesAttrs); 113 qc.setTargetStudyAttrs(targetStudyAttrs); 114 qc.setPid(pid); 115 QCResult tmpResult = qc.performOperation(testDescription, qc); 116 init(tmpResult); 117 } 118 119 /** 120 * split. 121 * Calls the tool to split some instances specified by moveUIDs. 122 * 123 * @param testDescription 124 * the test description 125 * @param moveUIDs 126 * the uids for the moved instances 127 * @param targetStudyAttrs 128 * the target study attributes to be updated 129 * @param targetSeriesAttrs 130 * the target series attributes to be updated 131 * @param pid 132 * patient ID 133 */ 134 public void split(String testDescription, ArrayList<String> moveUIDs, 135 Attributes targetStudyAttrs, Attributes targetSeriesAttrs, 136 IDWithIssuer pid) { 137 qc.setMoveUIDs(moveUIDs); 138 qc.setTargetSeriesAttrs(targetSeriesAttrs); 139 qc.setTargetStudyAttrs(targetStudyAttrs); 140 qc.setPid(pid); 141 QCResult tmpResult = qc.performOperation(testDescription, qc); 142 init(tmpResult); 143 } 144 /** 145 * segment. 146 * Calls the tool to either move some instances specified by moveUIDs or clone some instances specified by cloneUIDs. 147 * 148 * @param testDescription 149 * the test description 150 * @param moveUIDs 151 * the uids for the moved instances 152 * @param cloneUIDs 153 * the uids for the cloned instance 154 * @param targetStudyAttrs 155 * the target study attributes to be updated 156 * @param targetSeriesAttrs 157 * the target series attributes to be updated 158 * @param pid 159 * patient ID 160 */ 161 public void segment(String testDescription, ArrayList<String> moveUIDs, 162 ArrayList<String> cloneUIDs,Attributes targetStudyAttrs, 163 Attributes targetSeriesAttrs,IDWithIssuer pid) { 164 qc.setMoveUIDs(moveUIDs); 165 qc.setCloneUIDs(cloneUIDs); 166 qc.setTargetSeriesAttrs(targetSeriesAttrs); 167 qc.setTargetStudyAttrs(targetStudyAttrs); 168 qc.setPid(pid); 169 QCResult tmpResult = qc.performOperation(testDescription, qc); 170 init(tmpResult); 171 } 172 /** 173 * updateAttributes. 174 * Calls the tool to update instances identified by their uids 175 * in the updateData with metadata also specified in the updateData. 176 * Will not update UIDS. 177 * 178 * @param testDescription 179 * the test description 180 * @param updateScope 181 * the scope can be any scope specified in QCUpdateScope 182 * @param updateData 183 * Attributes used to identify and update objects 184 */ 185 public void updateAttributes(String testDescription, QCUpdateScope updateScope, 186 Attributes updateData) { 187 qc.setUpdateScope(updateScope); 188 qc.setUpdateAttrs(updateData); 189 190 QCResult tmpResult = qc.performOperation(testDescription, qc); 191 init(tmpResult); 192 } 193 194 /** 195 * delete. 196 * Calls the tool to delete studies, series or instance 197 * specified in the deleteParams string. 198 * Can specify patient data instead in the form 199 * patientID:localIssuer:UniversalEntityUID:UniversalEntityUIDType. 200 * Must specify boolean true in case of patient 201 * 202 * @param testDescription 203 * the test description 204 * @param deleteParams 205 * the string separated by colons for the object to delete 206 * @param patient 207 * boolean specifying if the deleteParams are that of a patient 208 */ 209 public void delete(String testDescription, String deleteParams, boolean patient) { 210 if(patient) 211 try { 212 qc.setPid(QC.toIDWithIssuer(deleteParams)); 213 }catch (MissingArgumentException e) { 214 215 } 216 qc.setDeleteParams(deleteParams); 217 QCResult tmpResult = qc.performOperation(testDescription, qc); 218 init(tmpResult); 219 } 220 221 public void deleteMulti(String testDescription, String[] deleteParams) { 222 223 if (deleteParams == null) 224 return; 225 226 MultipleQCResult results = new MultipleQCResult(); 227 228 for (String param : deleteParams) { 229 qc.setDeleteParams(param); 230 QCResult tmpResult = qc.performOperation(testDescription, qc); 231 results.getResults().add(tmpResult); 232 } 233 234 init(results); 235 } 236 237 /** 238 * performPatientOperation. 239 * Calls the tool to perform one of the patient operations specified 240 * Patient operations can be any of QCOperation that start with 241 * PATIENT_ 242 * 243 * @param testDescription 244 * the test description 245 * @param sourcePatientAttrs 246 * the attributes with id and optionally issuer of the patient 247 * used as source patient in the process 248 * @param targetPatientAttrs 249 * the attributes with id and optionally issuer of the patient 250 * used as target patient in the process 251 */ 252 public void performPatientOperation(String testDescription, Attributes sourcePatientAttrs, Attributes targetPatientAttrs) { 253 qc.setSourcePatientAttributes(sourcePatientAttrs); 254 qc.setTargetPatientAttributes(targetPatientAttrs); 255 QCResult tmpResult = qc.performOperation(testDescription, qc); 256 init(tmpResult); 257 } 258 259 /** 260 * reject. 261 * Calls the tool to reject studies, series or instance 262 * 263 * @param testDescription 264 * the test description 265 * @param rOrUIDs 266 * the list of SOPUIDs 267 */ 268 public void reject(String testDescription, ArrayList<String> rOrUIDs) { 269 qc.setRrUIDs(rOrUIDs); 270 QCResult tmpResult = qc.performOperation(testDescription, qc); 271 init(tmpResult); 272 } 273 274 /** 275 * restore. 276 * Calls the tool to restore a set of instances from being rejected. 277 * Configuration of the archive must allow this code to override previous one. 278 * 279 * @param testDescription 280 * the test description 281 * @param rOrUIDs 282 * the list of SOPUIDs 283 */ 284 public void restore(String testDescription, ArrayList<String> rOrUIDs) { 285 qc.setRrUIDs(rOrUIDs); 286 QCResult tmpResult = qc.performOperation(testDescription, qc); 287 init(tmpResult); 288 } 289 290 /** 291 * updateAttributes. 292 * Calls the tool to update instances identified by their uids 293 * in the updateData with metadata also specified in the updateData. 294 * Will not update UIDS. 295 * 296 * @param testDescription 297 * the test description 298 * @param updateScope 299 * the scope can be any scope specified in QCUpdateScope 300 * @param updateData 301 * Attributes used to identify and update objects 302 */ 303 public void quickFixLinkMWL(String testDescription, Attributes mwlAttributes, IDWithIssuer pid) { 304 qc.setUpdateAttrs(mwlAttributes); 305 qc.setPid(pid); 306 307 QCResult tmpResult = qc.performOperation(testDescription, qc); 308 init(tmpResult); 309 } 310 311}