/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (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.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is part of dcm4che, an implementation of DICOM(TM) in * Java(TM), hosted at http://sourceforge.net/projects/dcm4che. * * The Initial Developer of the Original Code is * Accurate Software Design, LLC. * Portions created by the Initial Developer are Copyright (C) 2006-2008 * the Initial Developer. All Rights Reserved. * * Contributor(s): * See listed authors below. * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ package org.dcm4chee.archive.entity; import java.io.Serializable; import java.util.Calendar; import java.util.Collection; import java.util.Date; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.PrePersist; import javax.persistence.PreUpdate; import javax.persistence.Table; import javax.persistence.Transient; import javax.persistence.Version; import org.dcm4che3.data.Attributes; import org.dcm4che3.data.DatePrecision; import org.dcm4che3.data.Tag; import org.dcm4che3.soundex.FuzzyStr; import org.dcm4che3.util.DateUtils; /** * @author Damien Evans <damien.daddy@gmail.com> * @author Justin Falk <jfalkmu@gmail.com> * @author Gunter Zeilinger <gunterze@gmail.com> * @version $Revision$ $Date$ * @since Feb 29, 2008 */ @Entity @Table(name = "mwl_item") public class MWLItem implements Serializable { public static final String SCHEDULED = "SCHEDULED"; public static final String ARRIVED = "ARRIVED"; public static final String READY = "READY"; public static final String STARTED = "STARTED"; public static final String DEPARTED = "DEPARTED"; public static final String COMPLETED = "COMPLETED"; public static final String DISCONTINUED = "DISCONTINUED"; private static final long serialVersionUID = 5655030469102270878L; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "pk") private long pk; @Version @Column(name = "version") private long version; //@Basic(optional = false) @Column(name = "created_time", updatable = false) private Date createdTime; //@Basic(optional = false) @Column(name = "updated_time") private Date updatedTime; //@Basic(optional = false) @Column(name = "sps_id") private String scheduledProcedureStepID; //@Basic(optional = false) @Column(name = "req_proc_id") private String requestedProcedureID; //@Basic(optional = false) @Column(name = "study_iuid") private String studyInstanceUID; @Column(name = "accession_no") private String accessionNumber; //@Basic(optional = false) @Column(name = "modality") private String modality; //@Basic(optional = false) @Column(name = "sps_start_date") private String scheduledStartDate; //@Basic(optional = false) @Column(name = "sps_start_time") private String scheduledStartTime; //@Basic(optional = false) @Column(name = "sps_status") private String status; @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval = true, optional = false) @JoinColumn(name = "dicomattrs_fk") private AttributesBlob attributesBlob; @Transient private Attributes cachedAttributes; @OneToOne(cascade=CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "perf_phys_name_fk") private PersonName scheduledPerformingPhysicianName; @OneToMany(mappedBy = "mwlItem", cascade = CascadeType.ALL, orphanRemoval = true) private Collection<ScheduledStationAETitle> scheduledStationAETs; @ManyToOne(optional = false) @JoinColumn(name = "patient_fk") private Patient patient; public long getPk() { return pk; } public Date getCreatedTime() { return createdTime; } public Date getUpdatedTime() { return updatedTime; } public String getScheduledProcedureStepID() { return scheduledProcedureStepID; } public String getRequestedProcedureID() { return requestedProcedureID; } public String getStudyInstanceUID() { return studyInstanceUID; } public String getAccessionNumber() { return accessionNumber; } public String getModality() { return modality; } public String getScheduledStartDate() { return scheduledStartDate; } public String getScheduledStartTime() { return scheduledStartTime; } public PersonName getScheduledPerformingPhysicianName() { return scheduledPerformingPhysicianName; } public String getStatus() { return status; } public Patient getPatient() { return patient; } public void setPatient(Patient patient) { this.patient = patient; } public Collection<ScheduledStationAETitle> getScheduledStationAETs() { return scheduledStationAETs; } public void setScheduledStationAETs( Collection<ScheduledStationAETitle> scheduledStationAETs) { this.scheduledStationAETs = scheduledStationAETs; } public long getVersion() { return version; } public void setVersion(long version) { this.version = version; } @Override public String toString() { return "MWLItem[pk=" + pk + ", spsid=" + scheduledProcedureStepID + ", rpid=" + requestedProcedureID + ", suid=" + studyInstanceUID + ", accno=" + accessionNumber + ", modality=" + modality + ", performer=" + scheduledPerformingPhysicianName + ", start=" + scheduledStartDate + scheduledStartTime + ", status=" + status + "]"; } @PrePersist public void onPrePersist() { Date now = new Date(); createdTime = now; updatedTime = now; } @PreUpdate public void onPreUpdate() { updatedTime = new Date(); } public AttributesBlob getAttributesBlob() { return attributesBlob; } public Attributes getAttributes() throws BlobCorruptedException { return attributesBlob.getAttributes(); } public void setAttributes(Attributes attrs, FuzzyStr fuzzyStr, String nullValue) { Attributes spsItem = attrs .getNestedDataset(Tag.ScheduledProcedureStepSequence); if (spsItem == null) { throw new IllegalArgumentException( "Missing Scheduled Procedure Step Sequence (0040,0100) Item"); } scheduledProcedureStepID = spsItem.getString(Tag.ScheduledProcedureStepID); modality = Utils.upper(spsItem.getString(Tag.Modality, nullValue)); Date dt = spsItem.getDate(Tag.ScheduledProcedureStepStartDateAndTime); if (dt != null) { scheduledStartDate = DateUtils.formatDA(null, dt); scheduledStartTime = spsItem.containsValue(Tag.ScheduledProcedureStepStartTime) ? DateUtils.formatTM(null, dt) : nullValue; } else { scheduledStartDate = nullValue; scheduledStartTime = nullValue; } scheduledPerformingPhysicianName = PersonName.valueOf( attrs.getString(Tag.ScheduledPerformingPhysicianName), fuzzyStr, nullValue, scheduledPerformingPhysicianName); status = spsItem.getString(Tag.ScheduledProcedureStepStatus, SCHEDULED); requestedProcedureID = attrs.getString(Tag.RequestedProcedureID); studyInstanceUID = attrs.getString(Tag.StudyInstanceUID); accessionNumber = attrs.getString(Tag.AccessionNumber); if (attributesBlob == null) attributesBlob = new AttributesBlob(attrs); else attributesBlob.setAttributes(attrs); } }