public void addWorklistItem( Long studyPk, String templateFile, String humanPerformerCode, Long scheduleDate) throws Exception { String uri = FileUtils.resolve(new File(templatePath, templateFile + ".xml")).toURI().toString(); if (log.isDebugEnabled()) log.debug("load template file: " + uri); Dataset ds = DatasetUtils.fromXML(new InputSource(uri)); ContentManager cm = getContentManager(); // patient Dataset patDS = cm.getPatientForStudy(studyPk.longValue()); if (log.isDebugEnabled()) { log.debug("Patient Dataset:"); log.debug(patDS); } ds.putAll(patDS.subSet(PAT_ATTR_TAGS)); // Dataset sopInstRef = cm.getSOPInstanceRefMacro(studyPk.longValue(), false); String studyIUID = sopInstRef.getString(Tags.StudyInstanceUID); ds.putUI(Tags.SOPInstanceUID, UIDGenerator.getInstance().createUID()); ds.putUI(Tags.StudyInstanceUID, studyIUID); DcmElement inSq = ds.putSQ(Tags.InputInformationSeq); inSq.addItem(sopInstRef); // Scheduled Human Performer Seq DcmElement schedHPSq = ds.putSQ(Tags.ScheduledHumanPerformersSeq); Dataset item = schedHPSq.addNewItem(); DcmElement hpCodeSq = item.putSQ(Tags.HumanPerformerCodeSeq); Dataset dsCode = (Dataset) this.humanPerformer.get(humanPerformerCode); log.info(dsCode); if (dsCode != null) { hpCodeSq.addItem(dsCode); item.putPN(Tags.HumanPerformerName, dsCode.getString(Tags.CodeMeaning)); } // Scheduled Procedure Step Start Date and Time ds.putDT(Tags.SPSStartDateAndTime, new Date(scheduleDate.longValue())); if (log.isDebugEnabled()) { log.debug("GPSPS Dataset:"); log.debug(ds); } addWorklistItem(ds); }
public void handleNotification(Notification notif, Object handback) { String spsuid = (String) notif.getUserData(); Dataset pps = DcmObjectFactory.getInstance().newDataset(); try { Dataset sps; GPWLManager gpwlmgr = getGPWLManager(); sps = gpwlmgr.getWorklistItem(spsuid); String ppsiuid = spsuid + ppsuidSuffix; String status = sps.getString(Tags.GPSPSStatus); pps.putCS(Tags.GPPPSStatus, status); pps.putUI(Tags.SOPInstanceUID, ppsiuid); Date now = new Date(); if ("IN PROGRESS".equals(status)) { try { getGPPPSManager().getGPPPS(ppsiuid); return; // avoid duplicate N_CREATE } catch (Exception e) { } pps.putSH(Tags.PPSID, "PPS" + ppsiuid.hashCode()); pps.putDA(Tags.PPSStartDate, now); pps.putTM(Tags.PPSStartTime, now); pps.putDA(Tags.PPSEndDate); pps.putTM(Tags.PPSEndTime); for (int i = 0; i < N_CREATE_TYPE2_ATTRS.length; i++) { pps.putXX(N_CREATE_TYPE2_ATTRS[i]); } pps.putAll(sps.subSet(N_CREATE_SPS_ATTRS)); copyCode( copyWorkitemCode, sps.getItem(Tags.ScheduledWorkitemCodeSeq), pps.putSQ(Tags.PerformedWorkitemCodeSeq)); copyCode( copyStationNameCode, sps.getItem(Tags.ScheduledStationNameCodeSeq), pps.putSQ(Tags.PerformedStationNameCodeSeq)); copyCode( copyStationClassCode, sps.getItem(Tags.ScheduledStationClassCodeSeq), pps.putSQ(Tags.PerformedStationClassCodeSeq)); copyCode( copyStationGeographicLocationCode, sps.getItem(Tags.ScheduledStationGeographicLocationCodeSeq), pps.putSQ(Tags.PerformedStationGeographicLocationCodeSeq)); copyCode( copyProcessingApplicationsCode, sps.getItem(Tags.ScheduledProcessingApplicationsCodeSeq), pps.putSQ(Tags.PerformedProcessingApplicationsCodeSeq)); } else if ("COMPLETED".equals(status) || "DISCONTINUED".equals(status)) { pps.putDA(Tags.PPSEndDate, now); pps.putTM(Tags.PPSEndTime, now); pps.putAll(gpwlmgr.getOutputInformation(spsuid)); } else { return; } } catch (Exception e) { log.error("Failed to access GP-SPS[" + spsuid + "]", e); return; } for (int i = 0; i < destAETs.length; i++) { PPSOrder order = new PPSOrder(pps, destAETs[i]); try { log.info("Scheduling " + order); jmsDelegate.queue(queueName, order, Message.DEFAULT_PRIORITY, 0L); } catch (Exception e) { log.error("Failed to schedule " + order, e); } } }