/** * Adds a pattern and a task to the collector. * * @param pattern The scheduling pattern. * @param task The task. * @return An ID for the scheduled operation. */ public synchronized String add(SchedulingPattern pattern, Task task) { String id = GUIDGenerator.generate(); patterns.add(pattern); tasks.add(task); ids.add(id); return id; }
/** * Abstract base representation of a cron4j task. * * <p>Developers can extends this abstract class to build their own tasks. * * <p>Extending Task means, above all, implementing the {@link Task#execute(TaskExecutionContext)} * method. Within this method the task must perform its operation. If the <em>execute()</em> method * returns regularly then the execution is considered to be successfully completed. If * <em>execute()</em> dies throwing a {@link RuntimeException} then the task execution is considered * to be failed. The supplied parameter, which is a {@link TaskExecutionContext} instance, helps the * developer in integrating his task with the scheduler executor. Through the context the developer * can check if the execution has been paused or stopped, and he can also push back some status * informations by calling {@link TaskExecutionContext#setCompleteness(double)} and {@link * TaskExecutionContext#setStatusMessage(String)}. * * <p>If the custom task supports pausing, stopping and/or tracking, that should be notified by * overriding {@link Task#canBePaused()}, {@link Task#canBeStopped()}, {@link * Task#supportsCompletenessTracking()} and/or {@link Task#supportsStatusTracking()}. * * @author Carlo Pelliccia * @since 2.0 */ public abstract class Task { /** The ID for this task. Also used as an instance synchronization lock. */ private Object id = GUIDGenerator.generate(); /** Empty constructor, does nothing. */ public Task() {} /** * It returns the ID for this task. * * @return The ID for this task. */ Object getId() { return id; } /** * Checks whether this task supports pause requests. * * <p>Default implementation returns <em>false</em>. * * <p>Task developers can override this method to let it return a <em>true</em> value, and at the * same time they have to implement the {@link Task#execute(TaskExecutionContext)} method, so that * pause requests are really handled. This can be done calling regularly the {@link * TaskExecutionContext#pauseIfRequested()} method during the task execution. * * @return true if this task can be paused; false otherwise. */ public boolean canBePaused() { return false; } /** * Checks whether this task supports stop requests. * * <p>Default implementation returns <em>false</em>. * * <p>Task developers can override this method to let it return a <em>true</em> value, and at the * same time they have to implement the {@link Task#execute(TaskExecutionContext)} method, so that * stop requests are really handled. This can be done checking regularly the {@link * TaskExecutionContext#isStopped()} method during the task execution. * * @return true if this task can be stopped; false otherwise. */ public boolean canBeStopped() { return false; } /** * Tests whether this task supports status tracking. * * <p>Default implementation returns <em>false</em>. * * <p>The task developer can override this method and returns <em>true</em>, having care to * regularly calling the {@link TaskExecutionContext#setStatusMessage(String)} method during the * task execution. * * @return true if this task, during its execution, provides status message regularly. */ public boolean supportsStatusTracking() { return false; } /** * Tests whether this task supports completeness tracking. * * <p>Default implementation returns <em>false</em>. * * <p>The task developer can override this method and returns <em>true</em>, having care to * regularly calling the {@link TaskExecutionContext#setCompleteness(double)} method during the * task execution. * * @return true if this task, during its execution, provides a completeness value regularly. */ public boolean supportsCompletenessTracking() { return false; } /** * This method is called to require a task execution, and should contain the core routine of any * scheduled task. * * <p>If the <em>execute()</em> method ends regularly the scheduler will consider the execution * successfully completed, and this will be communicated to any {@link SchedulerListener} * interested in it. If the <em>execute()</em> method dies throwing a {@link RuntimeException} the * scheduler will consider it as a failure notification. Any {@link SchedulerListener} will be * notified about the occurred exception. * * @param context The execution context. * @throws RuntimeException Task execution has somehow failed. */ public abstract void execute(TaskExecutionContext context) throws RuntimeException; }
/** * CLAIM送信を行う。 * * @param sendModel 送信するDocuentModel * @throws Exception */ public void send(DiagnosisSendWrapper wrapper) throws Exception { // s.oh^ 2013/12/10 傷病名のCLAIM送信する/しない Properties config = new Properties(); StringBuilder sbPath = new StringBuilder(); sbPath.append(System.getProperty("jboss.home.dir")); sbPath.append(File.separator); sbPath.append("custom.properties"); File f = new File(sbPath.toString()); FileInputStream fin = new FileInputStream(f); InputStreamReader isr = new InputStreamReader(fin, "JISAutoDetect"); config.load(isr); isr.close(); String claimSend = config.getProperty("diagnosis.claim.send"); if (claimSend != null && claimSend.equals("false")) { return; } // s.oh$ // 新規病名 List<RegisteredDiagnosisModel> addedDiagnosis = wrapper.getAddedDiagnosis(); // 更新病名 List<RegisteredDiagnosisModel> updatedDiagnosis = wrapper.getUpdatedDiagnosis(); // minagawa^ LSC 1.4 傷病名の削除 2013/06/24 // 削除病名 List<RegisteredDiagnosisModel> deletedDiagnosis = wrapper.getDeletedDiagnosis(); // minagawa$ // 実際にCLAIM送信する病名 List<RegisteredDiagnosisModel> actualList = new ArrayList<RegisteredDiagnosisModel>(); // 新規病名を送信する if (addedDiagnosis != null && addedDiagnosis.size() > 0) { for (RegisteredDiagnosisModel rdm : addedDiagnosis) { if (isDorcaUpdatedDisease(rdm) || isPureDisease(rdm)) { actualList.add(rdm); } } if (!actualList.isEmpty()) { if (DEBUG) { debug("-------- Send Diagnosis List to add ----------------"); for (RegisteredDiagnosisModel r : actualList) { debug(r.getDiagnosis()); } } } } // 更新された病名を CLAIM 送信する // detuched object のみ if (updatedDiagnosis != null && updatedDiagnosis.size() > 0) { if (DEBUG) { debug("-------- Send Diagnosis List to update ----------------"); for (RegisteredDiagnosisModel r : updatedDiagnosis) { debug(r.getDiagnosis()); } } actualList.addAll(updatedDiagnosis); } // minagawa^ LSC 1.4 傷病名の削除 2013/06/24 if (deletedDiagnosis != null && deletedDiagnosis.size() > 0) { if (DEBUG) { debug("-------- Send Diagnosis List to delete ----------------"); for (RegisteredDiagnosisModel r : updatedDiagnosis) { debug(r.getDiagnosis()); } } actualList.addAll(deletedDiagnosis); } if (actualList.isEmpty()) { return; } // minagawa$ // DocInfo & RD をカプセル化したアイテムを生成する ArrayList<DiagnosisModuleItem> moduleItems = new ArrayList<DiagnosisModuleItem>(); for (RegisteredDiagnosisModel rd : actualList) { DocInfoModel docInfo = new DocInfoModel(); docInfo.setDocId(GUIDGenerator.generate(docInfo)); docInfo.setTitle(IInfoModel.DEFAULT_DIAGNOSIS_TITLE); docInfo.setPurpose(IInfoModel.PURPOSE_RECORD); docInfo.setFirstConfirmDate(ModelUtils.getDateTimeAsObject(rd.getConfirmDate())); docInfo.setConfirmDate(ModelUtils.getDateTimeAsObject(rd.getFirstConfirmDate())); // s.oh^ 2013/05/10 傷病名対応 rd.setDiagnosisCode(HAND_CODE); // ORCAから取り込んだ場合、コードに0000999を設定する // s.oh$ DiagnosisModuleItem mItem = new DiagnosisModuleItem(); mItem.setDocInfo(docInfo); mItem.setRegisteredDiagnosisModule(rd); moduleItems.add(mItem); } // ヘルパー用の値を生成する String confirmDate = wrapper.getConfirmDate(); // ヘルパークラスを生成する DiseaseHelper dhl = new DiseaseHelper(); dhl.setPatientId(wrapper.getPatientId()); // 患者ID dhl.setConfirmDate(confirmDate); // 確定日 dhl.setDiagnosisModuleItems(moduleItems); // RD+DocInfo dhl.setGroupId(GUIDGenerator.generate(dhl)); // GroupId dhl.setDepartment(wrapper.getDepartment()); // 診療科コード dhl.setDepartmentDesc(wrapper.getDepartmentDesc()); // 診療科名 dhl.setCreatorName(wrapper.getCreatorName()); // 担当医名 dhl.setCreatorId(wrapper.getCreatorLicense()); // 担当医コード dhl.setJmariCode(wrapper.getJamariCode()); // JMARI code dhl.setCreatorLicense(wrapper.getCreatorLicense()); // 医療資格 dhl.setFacilityName(wrapper.getFacilityName()); // 施設名 if (DEBUG) { debug("患者ID=" + dhl.getPatientId()); debug("確定日=" + dhl.getConfirmDate()); debug("GroupId=" + dhl.getGroupId()); debug("診療科コード=" + dhl.getDepartment()); debug("診療科名=" + dhl.getDepartmentDesc()); debug("担当医名=" + dhl.getCreatorName()); debug("担当医コード=" + dhl.getCreatorId()); debug("JMARI code=" + dhl.getJmariCode()); debug("医療資格=" + dhl.getCreatorLicense()); debug("施設名=" + dhl.getFacilityName()); } // ログのために基本情報を生成する StringBuilder sb = new StringBuilder(); sb.append(confirmDate).append(" "); sb.append(wrapper.getPatientId()).append(" "); sb.append(wrapper.getPatientName()).append(" "); sb.append(wrapper.getPatientGender()); String baseInfo = sb.toString(); // -------------------------------------------------------- // CLIAM message を生成する // -------------------------------------------------------- VelocityContext context = VelocityHelper.getContext(); context.put(OBJECT_NAME, dhl); StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); Velocity.mergeTemplate(TEMPLATE_NAME, TEMPLATE_ENC, context, bw); bw.flush(); bw.close(); String claimMessage = sw.toString(); // minagawa^ CLAIM Log log(claimMessage); // if (DEBUG) { // debug(claimMessage); // } // minagawa$ // -------------------------------------------------------- // ORCAへ接続する Socket socket = new Socket(host, port); OutputStream out = socket.getOutputStream(); DataOutputStream dout = new DataOutputStream(out); BufferedOutputStream writer = new BufferedOutputStream(dout); InputStream in = socket.getInputStream(); DataInputStream din = new DataInputStream(in); BufferedInputStream reader = new BufferedInputStream(din); // Writes UTF8 data writer.write(claimMessage.getBytes(enc)); writer.write(EOT); writer.flush(); // Reads result int c = reader.read(); if (c == ACK) { sb = new StringBuilder(); sb.append(ACK_STR).append(baseInfo); log(sb.toString()); } else if (c == NAK) { sb = new StringBuilder(); sb.append(NAK_STR).append(baseInfo); log(sb.toString()); } writer.close(); reader.close(); socket.close(); }