PageRenderTime 32ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/VeyoHealth/dcm4che-2.0.27/dcm4che-audit/src/main/java/org/dcm4che2/audit/message/ParticipantObject.java

https://bitbucket.org/masoudn/veyohealth
Java | 499 lines | 371 code | 73 blank | 55 comment | 30 complexity | 3e561309e4ea85ca91eddd25d7a9cf77 MD5 | raw file
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is part of dcm4che, an implementation of DICOM(TM) in
  15. * Java(TM), hosted at http://sourceforge.net/projects/dcm4che.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Gunter Zeilinger, Huetteldorferstr. 24/10, 1150 Vienna/Austria/Europe.
  19. * Portions created by the Initial Developer are Copyright (C) 2002-2005
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. * See listed authors below.
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either the GNU General Public License Version 2 or later (the "GPL"), or
  27. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. package org.dcm4che2.audit.message;
  39. import java.io.IOException;
  40. import java.io.UnsupportedEncodingException;
  41. import java.io.Writer;
  42. import java.util.ArrayList;
  43. import java.util.Collections;
  44. import java.util.List;
  45. /**
  46. * Identifies instances of data or objects that have been accessed.
  47. *
  48. * @author Gunter Zeilinger <gunterze@gmail.com>
  49. * @version $Revision: 6823 $ $Date: 2008-08-21 14:58:03 +0200 (Thu, 21 Aug 2008) $
  50. * @since Nov 17, 2006
  51. */
  52. public class ParticipantObject extends BaseElement {
  53. private final IDTypeCode idTypeCode;
  54. private Name name;
  55. private Query query;
  56. private final ArrayList<Detail> details = new ArrayList<Detail>();
  57. private final ArrayList<ParticipantObjectDescription> descs =
  58. new ArrayList<ParticipantObjectDescription>();
  59. /** Create a participant object identified by the given id,
  60. * of type specified by idTypeCode. Additionally, participant details
  61. * can be added afterwards to specify the participant more completely.
  62. */
  63. public ParticipantObject(String id, IDTypeCode idTypeCode) {
  64. super("ParticipantObjectIdentification");
  65. if (idTypeCode == null) {
  66. throw new NullPointerException("idTypeCode");
  67. }
  68. addAttribute("ParticipantObjectID", id, false);
  69. this.idTypeCode = idTypeCode;
  70. }
  71. /** Returns the id specified for this object when it was created */
  72. public final String getParticipantObjectID() {
  73. return (String) getAttribute("ParticipantObjectID");
  74. }
  75. public final IDTypeCode getParticipantObjectIDTypeCode() {
  76. return idTypeCode;
  77. }
  78. public final TypeCode getParticipantObjectTypeCode() {
  79. return (TypeCode) getAttribute("ParticipantObjectTypeCode");
  80. }
  81. public final ParticipantObject setParticipantObjectTypeCode(TypeCode code) {
  82. addAttribute("ParticipantObjectTypeCode", code, true);
  83. return this;
  84. }
  85. public final TypeCodeRole getParticipantObjectTypeCodeRole() {
  86. return (TypeCodeRole) getAttribute("ParticipantObjectTypeCodeRole");
  87. }
  88. public final ParticipantObject setParticipantObjectTypeCodeRole(
  89. TypeCodeRole code) {
  90. addAttribute("ParticipantObjectTypeCodeRole", code, true);
  91. return this;
  92. }
  93. public final DataLifeCycle getParticipantObjectDataLifeCycle() {
  94. return (DataLifeCycle) getAttribute("ParticipantObjectDataLifeCycle");
  95. }
  96. public final ParticipantObject setParticipantObjectDataLifeCycle(
  97. DataLifeCycle code) {
  98. addAttribute("ParticipantObjectDataLifeCycle", code, true);
  99. return this;
  100. }
  101. public final String getParticipantObjectSensitivity() {
  102. return (String) getAttribute("ParticipantObjectSensitivity");
  103. }
  104. public final ParticipantObject setParticipantObjectSensitivity(
  105. String sensitivity) {
  106. addAttribute("ParticipantObjectSensitivity", sensitivity, true);
  107. return this;
  108. }
  109. public final String getParticipantObjectName() {
  110. return name != null ? name.value() : null;
  111. }
  112. public final ParticipantObject setParticipantObjectName(String name) {
  113. if (name == null || name.length() == 0) {
  114. this.name = null;
  115. } else {
  116. if (this.query != null) {
  117. throw new IllegalStateException(
  118. "Cannot set ParticipantObjectName and ParticipantObjectQuery");
  119. }
  120. this.name = new Name(name);
  121. }
  122. return this;
  123. }
  124. public final byte[] getParticipantObjectQuery() {
  125. return query != null ? query.value() : null;
  126. }
  127. public final ParticipantObject setParticipantObjectQuery(byte[] query) {
  128. if (query == null || query.length == 0) {
  129. this.query = null;
  130. } else {
  131. if (this.name != null) {
  132. throw new IllegalStateException("Cannot set ParticipantObjectName " +
  133. "and ParticipantObjectQuery");
  134. }
  135. this.query = new Query(query);
  136. }
  137. return this;
  138. }
  139. public List<Detail> getParticipantObjectDetails() {
  140. return Collections.unmodifiableList(details);
  141. }
  142. public ParticipantObject addParticipantObjectDetail(String type,
  143. String value) {
  144. details.add(new Detail(type, value));
  145. return this;
  146. }
  147. public ParticipantObject addParticipantObjectDetail(String type,
  148. byte[] value) {
  149. details.add(new Detail(type, value));
  150. return this;
  151. }
  152. public List<ParticipantObjectDescription>
  153. getParticipantObjectDescriptions() {
  154. return Collections.unmodifiableList(descs);
  155. }
  156. public ParticipantObject addParticipantObjectDescription(
  157. ParticipantObjectDescription desc) {
  158. if (desc == null) {
  159. throw new NullPointerException();
  160. }
  161. descs.add(desc);
  162. return this;
  163. }
  164. @Override
  165. protected boolean isEmpty() {
  166. return false;
  167. }
  168. @Override
  169. protected void outputContent(Writer out) throws IOException {
  170. idTypeCode.output(out);
  171. if (name != null) {
  172. name.output(out);
  173. }
  174. if (query != null) {
  175. query.output(out);
  176. }
  177. outputChilds(out, details);
  178. outputChilds(out, descs);
  179. }
  180. public static ParticipantObject createPatient(String id, String name) {
  181. ParticipantObject pat = new ParticipantObject(id, IDTypeCode.PATIENT_ID);
  182. pat.setParticipantObjectTypeCode(TypeCode.PERSON);
  183. pat.setParticipantObjectTypeCodeRole(TypeCodeRole.PATIENT);
  184. pat.setParticipantObjectName(name);
  185. return pat;
  186. }
  187. /**
  188. * Create a participant object with type code STUDY_INSTANCE_UID,
  189. * and the specified description (which maybe null).
  190. * @param uid Study Instance UID
  191. * @param desc (null) Description including patient name/id
  192. */
  193. public static ParticipantObject createStudy(String uid,
  194. ParticipantObjectDescription desc) {
  195. ParticipantObject study = new ParticipantObject(uid,
  196. IDTypeCode.STUDY_INSTANCE_UID);
  197. study.setParticipantObjectTypeCode(TypeCode.SYSTEM);
  198. study.setParticipantObjectTypeCodeRole(TypeCodeRole.REPORT);
  199. if (desc != null) {
  200. study.addParticipantObjectDescription(desc);
  201. }
  202. return study;
  203. }
  204. public static ParticipantObject createDataRepository(String uri) {
  205. ParticipantObject obj = new ParticipantObject(uri, IDTypeCode.URI);
  206. obj.setParticipantObjectTypeCode(TypeCode.SYSTEM);
  207. obj.setParticipantObjectTypeCodeRole(TypeCodeRole.DATA_REPOSITORY);
  208. return obj;
  209. }
  210. public static ParticipantObject createQuerySOPClass(String cuid,
  211. String tsuid, byte[] query) {
  212. ParticipantObject queryObj = new ParticipantObject(cuid,
  213. IDTypeCode.SOP_CLASS_UID);
  214. queryObj.setParticipantObjectTypeCode(TypeCode.SYSTEM);
  215. queryObj.setParticipantObjectTypeCodeRole(TypeCodeRole.REPORT);
  216. queryObj.setParticipantObjectQuery(query);
  217. queryObj.addParticipantObjectDetail("TransferSyntax", tsuid);
  218. return queryObj;
  219. }
  220. public static ParticipantObject createSecurityAuditLog(String uri) {
  221. ParticipantObject obj = new ParticipantObject(uri, IDTypeCode.URI);
  222. obj.setParticipantObjectTypeCode(TypeCode.SYSTEM);
  223. obj.setParticipantObjectTypeCodeRole(TypeCodeRole.SECURITY_RESOURCE);
  224. obj.setParticipantObjectName("Security Audit Log");
  225. return obj;
  226. }
  227. public static ParticipantObject createAlertSubject(String id,
  228. IDTypeCode idTypeCode, String desc) {
  229. ParticipantObject obj = new ParticipantObject(id, idTypeCode);
  230. obj.setParticipantObjectTypeCode(TypeCode.SYSTEM);
  231. obj.addParticipantObjectDetail("AlertDescription", desc);
  232. return obj;
  233. }
  234. public static ParticipantObject createAlertSubjectWithURI(String uri,
  235. String desc) {
  236. return createAlertSubject(uri, IDTypeCode.URI, desc);
  237. }
  238. public static ParticipantObject createAlertSubjectWithNodeID(String nodeID,
  239. String desc) {
  240. return createAlertSubject(nodeID, IDTypeCode.NODE_ID, desc);
  241. }
  242. public static class IDTypeCode extends CodeElement {
  243. public static final IDTypeCode MEDIAL_RECORD_NUMBER =
  244. new IDTypeCode("1");
  245. public static final IDTypeCode PATIENT_ID = new IDTypeCode("2");
  246. public static final IDTypeCode ENCOUNTER_NUMBER = new IDTypeCode("3");
  247. public static final IDTypeCode ENROLLEE_NUMBER = new IDTypeCode("4");
  248. public static final IDTypeCode SOCIAL_SECURITY_NUMBER =
  249. new IDTypeCode("5");
  250. public static final IDTypeCode ACCOUNT_NUMBER = new IDTypeCode("6");
  251. public static final IDTypeCode GUARANTOR_NUMBER = new IDTypeCode("7");
  252. public static final IDTypeCode REPORT_NAME = new IDTypeCode("8");
  253. public static final IDTypeCode REPORT_NUMBER = new IDTypeCode("9");
  254. public static final IDTypeCode SEARCH_CRITERIA = new IDTypeCode("10");
  255. public static final IDTypeCode USER_IDENTIFIER = new IDTypeCode("11");
  256. public static final IDTypeCode URI = new IDTypeCode("12");
  257. public static final IDTypeCode STUDY_INSTANCE_UID =
  258. new IDTypeCode("110180","DCM","Study Instance UID");
  259. public static final IDTypeCode SOP_CLASS_UID =
  260. new IDTypeCode("110181","DCM","SOP Class UID");
  261. public static final IDTypeCode NODE_ID =
  262. new IDTypeCode("110182","DCM","Node ID");
  263. private IDTypeCode(String typeCode) {
  264. super("ParticipantObjectIDTypeCode", typeCode);
  265. }
  266. public IDTypeCode(String code, String codeSystemName,
  267. String displayName) {
  268. super("ParticipantObjectIDTypeCode", code, codeSystemName, displayName);
  269. }
  270. }
  271. public static class TypeCode {
  272. private final String value;
  273. public static final TypeCode PERSON = new TypeCode("1");
  274. public static final TypeCode SYSTEM = new TypeCode("2");
  275. public static final TypeCode ORGANIZATION = new TypeCode("3");
  276. public static final TypeCode OTHER = new TypeCode("4");
  277. private TypeCode(final String value) {
  278. this.value = value;
  279. }
  280. @Override
  281. public String toString() {
  282. return value;
  283. }
  284. }
  285. public static class TypeCodeRole {
  286. private final String value;
  287. public static final TypeCodeRole PATIENT = new TypeCodeRole("1");
  288. public static final TypeCodeRole LOCATION = new TypeCodeRole("2");
  289. public static final TypeCodeRole REPORT = new TypeCodeRole("3");
  290. public static final TypeCodeRole RESOURCE = new TypeCodeRole("4");
  291. public static final TypeCodeRole MASTER_FILE = new TypeCodeRole("5");
  292. public static final TypeCodeRole USER = new TypeCodeRole("6");
  293. public static final TypeCodeRole LIST = new TypeCodeRole("7");
  294. public static final TypeCodeRole DOCTOR = new TypeCodeRole("8");
  295. public static final TypeCodeRole SUBSCRIBER = new TypeCodeRole("9");
  296. public static final TypeCodeRole GUARANTOR = new TypeCodeRole("10");
  297. public static final TypeCodeRole SECURITY_USER_ENTITY =
  298. new TypeCodeRole("11");
  299. public static final TypeCodeRole SECURITY_USER_GROUP =
  300. new TypeCodeRole("12");
  301. public static final TypeCodeRole SECURITY_RESOURCE =
  302. new TypeCodeRole("13");
  303. public static final TypeCodeRole SECURITY_GRANULARITY_DEFINITION =
  304. new TypeCodeRole("14");
  305. public static final TypeCodeRole PROVIDER = new TypeCodeRole("15");
  306. public static final TypeCodeRole DATA_DESTINATION =
  307. new TypeCodeRole("16");
  308. public static final TypeCodeRole DATA_REPOSITORY =
  309. new TypeCodeRole("17");
  310. public static final TypeCodeRole SCHEDULE = new TypeCodeRole("18");
  311. public static final TypeCodeRole CUSTOMER = new TypeCodeRole("19");
  312. public static final TypeCodeRole JOB = new TypeCodeRole("20");
  313. public static final TypeCodeRole JOB_STREAM = new TypeCodeRole("21");
  314. public static final TypeCodeRole TABLE = new TypeCodeRole("22");
  315. public static final TypeCodeRole ROUTING_CRITERIA =
  316. new TypeCodeRole("23");
  317. public static final TypeCodeRole QUERY = new TypeCodeRole("24");
  318. private TypeCodeRole(final String value) {
  319. this.value = value;
  320. }
  321. @Override
  322. public String toString() {
  323. return value;
  324. }
  325. }
  326. public static class DataLifeCycle {
  327. private final String value;
  328. public static final DataLifeCycle CREATION = new DataLifeCycle("1");
  329. public static final DataLifeCycle IMPORT = new DataLifeCycle("2");
  330. public static final DataLifeCycle AMENDMENT = new DataLifeCycle("3");
  331. public static final DataLifeCycle VERIFICATION = new DataLifeCycle("4");
  332. public static final DataLifeCycle TRANSLATION = new DataLifeCycle("5");
  333. public static final DataLifeCycle ACCESS = new DataLifeCycle("6");
  334. public static final DataLifeCycle DE_IDENTIFICATION =
  335. new DataLifeCycle("7");
  336. public static final DataLifeCycle AGGREGATION = new DataLifeCycle("8");
  337. public static final DataLifeCycle REPORT = new DataLifeCycle("9");
  338. public static final DataLifeCycle EXPORT = new DataLifeCycle("10");
  339. public static final DataLifeCycle DISCLOSURE = new DataLifeCycle("11");
  340. public static final DataLifeCycle RECEIPT_OF_DISCLOSURE =
  341. new DataLifeCycle("12");
  342. public static final DataLifeCycle ARCHIVING = new DataLifeCycle("13");
  343. public static final DataLifeCycle LOGICAL_DELETION =
  344. new DataLifeCycle("14");
  345. public static final DataLifeCycle PHYSICAL_DESTRUCTION =
  346. new DataLifeCycle("15");
  347. private DataLifeCycle(final String value) {
  348. this.value = value;
  349. }
  350. @Override
  351. public String toString() {
  352. return value;
  353. }
  354. }
  355. private static class Name extends BaseElement {
  356. private final String value;
  357. private Name(String value) {
  358. super("ParticipantObjectName");
  359. if (value.length() == 0) {
  360. throw new IllegalArgumentException("value cannot be empty");
  361. }
  362. this.value = value;
  363. }
  364. public final String value() {
  365. return value;
  366. }
  367. @Override
  368. protected boolean isEmpty() {
  369. return false;
  370. }
  371. @Override
  372. protected void outputContent(Writer out) throws IOException {
  373. outputEscaped(out, value, "'");
  374. }
  375. }
  376. private static class Query extends BaseElement {
  377. private final byte[] value;
  378. private Query(byte[] value) {
  379. super("ParticipantObjectQuery");
  380. if (value.length == 0) {
  381. throw new IllegalArgumentException("value cannot be empty");
  382. }
  383. this.value = value.clone();
  384. }
  385. public final byte[] value() {
  386. return value.clone();
  387. }
  388. @Override
  389. protected boolean isEmpty() {
  390. return false;
  391. }
  392. @Override
  393. protected void outputContent(Writer out) throws IOException {
  394. out.write(Base64Encoder.encode(value));
  395. }
  396. }
  397. public static class Detail extends BaseElement {
  398. public Detail(String type, byte[] value) {
  399. super("ParticipantObjectDetail");
  400. addAttribute("type", type, false);
  401. addAttribute("value", value.clone(), false);
  402. }
  403. public Detail(String type, String value) {
  404. super("ParticipantObjectDetail");
  405. addAttribute("type", type, false);
  406. try {
  407. addAttribute("value", value.getBytes("UTF-8"), false);
  408. } catch (UnsupportedEncodingException e) {
  409. throw new Error(e);
  410. }
  411. }
  412. public final String getType() {
  413. return (String) getAttribute("type");
  414. }
  415. public final byte[] getValue() {
  416. return ((byte[]) getAttribute("value")).clone();
  417. }
  418. public final String getValueAsString() {
  419. try {
  420. return new String((byte[]) getAttribute("value"), "UTF-8");
  421. } catch (UnsupportedEncodingException e) {
  422. throw new Error(e);
  423. }
  424. }
  425. }
  426. }