List of usage examples for java.util Calendar after
public boolean after(Object when)
Calendar
represents a time after the time represented by the specified Object
. From source file:oscar.form.study.hsfo2.pageUtil.XMLTransferUtil.java
/** * this method in fact generate all xml for one patient. it all patient data and all visit datas to xml * /*w w w .j av a2 s . c o m*/ * @param site * @param pd * @param baseLineVd * : the baseLine visit data, namely the initial patient data * @throws Exception */ public void addPatientToSite(Site site, Hsfo2Patient pd, Hsfo2Visit baseLineVd, Calendar startDate, Calendar endDate) { if (baseLineVd == null) baseLineVd = (new HSFODAO()).getPatientBaseLineVisitData(pd); //If the baseline form not completed if (baseLineVd == null) return; String startDateStr = String.valueOf(startDate.get(Calendar.YEAR)) + "-" + String.valueOf(startDate.get(Calendar.MONTH) + 1) + "-" + String.valueOf(startDate.get(Calendar.DATE)); String endDateStr = String.valueOf(endDate.get(Calendar.YEAR)) + "-" + String.valueOf(endDate.get(Calendar.MONTH) + 1) + "-" + String.valueOf(endDate.get(Calendar.DATE)); String dateString2 = dformat2.format(pd.getConsentDate()); //e.g. "2012-03-13" Date signedDate = getSignedDate(pd.getPatient_Id(), startDateStr, endDateStr); if (signedDate == null) return; String dateString1 = dformat1.format(signedDate); //e.g. "2012-03-13T08:48:50" final XmlCalendar when = new XmlCalendar(dateString1); final String who = getSignedProvider(pd.getPatient_Id(), startDateStr, endDateStr); XmlCalendar dob = new XmlCalendar(dformat2.format(pd.getBirthDate())); //final Calendar visitDate = ConvertUtil.dateToCalendar( baseLineVd.getVisitDate_Id() ); final XmlCalendar visitDate = new XmlCalendar(dformat2.format(baseLineVd.getVisitDate_Id())); // add patient SitePatient patient = site.addNewSitePatient(); patient.setEmrPatientKey(pd.getPatient_Id()); // DatConsentDate dcd = patient.addNewDatConsentDate(); // dcd.setValue(new XmlCalendar(dateString2)); // // dcd.setSignedWhen(when); // // dcd.setSignedWho(who); // // DatDropDate ddd = patient.addNewDatDropDate(); // ddd.setSignedWhen(when); // ddd.setSignedWho(who); // // TxtEmrHcpID tehid = patient.addNewTxtEmrHcpID(); // DemographicData demoData = new DemographicData(); // String providerId=demoData.getDemographic(patient.getEmrPatientKey()).getProviderNo(); // if (pd.getEmrHCPId() == null) // tehid.setValue(""); // else // tehid.setValue(pd.getEmrHCPId()); /* get EmrHcpId from demographic table, not hsfo_patient table */ // if (providerId == null) // tehid.setValue(""); // else // tehid.setValue(providerId); // tehid.setSignedWhen(when); // tehid.setSignedWho(who); // ---- Initial section (unnamed): 8 fields are obtained independently of HSF HMP forms. //8 fields for patient demographics and EmrHcpID (each minOccurs=?1? and maxOccurs=?1?): //These data are obtained independently of HFS HMP forms // Surname TxtSurname tsn = patient.addNewTxtSurname(); tsn.setValue(pd.getLName()); tsn.setSignedWhen(when); tsn.setSignedWho(who); // GivenNames TxtGivenNames tgn = patient.addNewTxtGivenNames(); tgn.setValue(pd.getFName()); tgn.setSignedWhen(when); tgn.setSignedWho(who); DatBirthDate dbd = patient.addNewDatBirthDate(); dbd.setValue(dob); dbd.setSignedWhen(when); dbd.setSignedWho(who); SelSex ss = patient.addNewSelSex(); String sex = pd.getSex(); if ("m".equalsIgnoreCase(sex)) ss.setValue(StringSex.MALE); else ss.setValue(StringSex.FEMALE); ss.setSignedWhen(when); ss.setSignedWho(who); // Txt_EmrHcpID { TxtEmrHcpID hcpID = patient.addNewTxtEmrHcpID(); if (pd.getEmrHCPId() == null) hcpID.setValue(""); else hcpID.setValue(pd.getEmrHCPId()); hcpID.setSignedWhen(when); hcpID.setSignedWho(who); } //Txt_PostalCode { TxtPostalCode tpcfsa = patient.addNewTxtPostalCode(); tpcfsa.setValue(ConvertUtil.toUpperCase(pd.getPostalCode())); tpcfsa.setSignedWhen(when); tpcfsa.setSignedWho(who); } // sel_HsfHmpStatus { SelHsfHmpStatus hsfHmpStatus = patient.addNewSelHsfHmpStatus(); String status = pd.getStatusInHmp(); if ("Enrolled".equalsIgnoreCase(status)) status = "Enrolled"; else if ("NotEnrolled".equalsIgnoreCase(status)) status = "NotEnrolled"; hsfHmpStatus.setValue(org.hsfo.v2.StringHsfHmpStatus.Enum.forString(status)); hsfHmpStatus.setSignedWhen(when); hsfHmpStatus.setSignedWho(who); } // dat_HsfHmpStatusDate { DatHsfHmpStatusDate hsfHmpStatusDate = patient.addNewDatHsfHmpStatusDate(); //hsfHmpStatusDate.setValue( ConvertUtil.dateToCalendar( pd.getDateOfHmpStatus() ) ); hsfHmpStatusDate.setValue(new XmlCalendar(dformat2.format(pd.getDateOfHmpStatus()))); hsfHmpStatusDate.setSignedWhen(when); hsfHmpStatusDate.setSignedWho(who); } // ----- form_HsfHmpFlowsheet_Baseline section ------ //The fields are from HSF HMP Baseline only: //These data are obtained only once, on HSF HMPs baseline form Calendar visitDateValue = Calendar.getInstance(); visitDateValue.setTime(baseLineVd.getVisitDate_Id()); if (visitDateValue.after(startDate) && visitDateValue.before(endDate)) { addBaseLineData(patient, pd, baseLineVd, when, who); } // ------form_HsfHmpFlowsheet section ------ // Fields from both HSF HMP Baseline and Follow-up: //These data are obtained repeatedly on HSF HMP forms, always on the baseline form //first and then again serially on any number of successive follow-up forms. //The effective date of these data is captured in the sections VisitDate_key? attribute. addAllPatientVisit(patient, pd.getPatient_Id(), startDateStr, endDateStr); // ----- Final section: Fields for patient medical diagnoses, family history, physical exam results and lab test ----- //These data are obtained either directly on HSF HMPs Baseline and Follow-up forms or //independently of HSF HMP forms at any number of other times during patient care. //Each of these data have a valueDate? attribute that captures the effective date of the //value? attribute, for example, the date when the lab test result was measured or the //the patient provided the answer, or the measurement on physical exam was taken. addAllPatientVisitFinalSection(patient, pd.getPatient_Id(), startDateStr, endDateStr, startDate, endDate, visitDateValue, visitDate, when, who); }
From source file:org.broadleafcommerce.core.offer.service.processor.AbstractBaseProcessor.java
/** * Removes all out of date offers. If an offer does not have a start date, or the start * date is a later date, that offer will be removed. Offers without a start date should * not be processed. If the offer has a end date that has already passed, that offer * will be removed. Offers without a end date will be processed if the start date * is prior to the transaction date./* w w w.j a v a2s .com*/ * * @param offers * @return List of Offers with valid dates */ protected List<Offer> removeOutOfDateOffers(List<Offer> offers) { List<Offer> offersToRemove = new ArrayList<Offer>(); for (Offer offer : offers) { TimeZone timeZone = getOfferTimeZoneProcessor().getTimeZone(offer); Calendar current = timeZone == null ? SystemTime.asCalendar() : SystemTime.asCalendar(timeZone); Calendar start = null; if (offer.getStartDate() != null) { LocalDateTime startDate = new LocalDateTime(offer.getStartDate()); start = timeZone == null ? new GregorianCalendar() : new GregorianCalendar(timeZone); start.set(Calendar.YEAR, startDate.getYear()); start.set(Calendar.MONTH, startDate.getMonthOfYear() - 1); start.set(Calendar.DAY_OF_MONTH, startDate.getDayOfMonth()); start.set(Calendar.HOUR_OF_DAY, startDate.getHourOfDay()); start.set(Calendar.MINUTE, startDate.getMinuteOfHour()); start.set(Calendar.SECOND, startDate.getSecondOfMinute()); start.get(Calendar.HOUR_OF_DAY);//do not delete this line start.get(Calendar.MINUTE); if (LOG.isTraceEnabled()) { LOG.debug("Offer: " + offer.getName() + " timeZone:" + timeZone + " startTime:" + start.getTime() + " currentTime:" + current.getTime()); } } Calendar end = null; if (offer.getEndDate() != null) { LocalDateTime endDate = new LocalDateTime(offer.getEndDate()); end = timeZone == null ? new GregorianCalendar() : new GregorianCalendar(timeZone); end.set(Calendar.YEAR, endDate.getYear()); end.set(Calendar.MONTH, endDate.getMonthOfYear() - 1); end.set(Calendar.DAY_OF_MONTH, endDate.getDayOfMonth()); end.set(Calendar.HOUR_OF_DAY, endDate.getHourOfDay()); end.set(Calendar.MINUTE, endDate.getMinuteOfHour()); end.set(Calendar.SECOND, endDate.getSecondOfMinute()); end.get(Calendar.HOUR_OF_DAY);//do not delete this line end.get(Calendar.MINUTE); if (LOG.isTraceEnabled()) { LOG.debug("Offer: " + offer.getName() + " endTime:" + start.getTime()); } } if ((offer.getStartDate() == null) || (start.after(current))) { offersToRemove.add(offer); } else if (offer.getEndDate() != null && end.before(current)) { offersToRemove.add(offer); } } // remove all offers in the offersToRemove list from original offers list for (Offer offer : offersToRemove) { offers.remove(offer); } return offers; // return offers; }
From source file:org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment.java
/** * Creates dialog// w w w . j a v a2 s . c o m */ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Activity activity = getActivity(); mMessenger = getArguments().getParcelable(ARG_MESSENGER); long creation = getArguments().getLong(ARG_CREATION); long expiry = getArguments().getLong(ARG_EXPIRY); final Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationCal.setTimeInMillis(creation * 1000); Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiryCal.setTimeInMillis(expiry * 1000); // date picker works with default time zone, we need to convert from UTC to default timezone creationCal.setTimeZone(TimeZone.getDefault()); expiryCal.setTimeZone(TimeZone.getDefault()); // Explicitly not using DatePickerDialog here! // DatePickerDialog is difficult to customize and has many problems (see old git versions) CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.expiry_date_dialog_title); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.edit_subkey_expiry_dialog, null); alert.setView(view); final CheckBox noExpiry = (CheckBox) view.findViewById(R.id.edit_subkey_expiry_no_expiry); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.edit_subkey_expiry_date_picker); final TextView currentExpiry = (TextView) view.findViewById(R.id.edit_subkey_expiry_current_expiry); final LinearLayout expiryLayout = (LinearLayout) view.findViewById(R.id.edit_subkey_expiry_layout); noExpiry.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { expiryLayout.setVisibility(View.GONE); } else { expiryLayout.setVisibility(View.VISIBLE); } } }); if (expiry == 0L) { noExpiry.setChecked(true); expiryLayout.setVisibility(View.GONE); currentExpiry.setText(R.string.btn_no_date); } else { noExpiry.setChecked(false); expiryLayout.setVisibility(View.VISIBLE); currentExpiry.setText(DateFormat.getDateFormat(getActivity()).format(expiryCal.getTime())); } // date picker works based on default time zone Calendar todayCal = Calendar.getInstance(TimeZone.getDefault()); if (creationCal.after(todayCal)) { // NOTE: This is just for the rare cases where creation is _after_ today // Min Date: Creation date + 1 day Calendar creationCalPlusOne = (Calendar) creationCal.clone(); creationCalPlusOne.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(creationCalPlusOne.getTime().getTime()); datePicker.init(creationCalPlusOne.get(Calendar.YEAR), creationCalPlusOne.get(Calendar.MONTH), creationCalPlusOne.get(Calendar.DAY_OF_MONTH), null); } else { // Min Date: today + 1 day // at least one day after creation (today) todayCal.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(todayCal.getTime().getTime()); datePicker.init(todayCal.get(Calendar.YEAR), todayCal.get(Calendar.MONTH), todayCal.get(Calendar.DAY_OF_MONTH), null); } alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); long expiry; if (noExpiry.isChecked()) { expiry = 0L; } else { Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault()); //noinspection ResourceType selectedCal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); // date picker uses default time zone, we need to convert to UTC selectedCal.setTimeZone(TimeZone.getTimeZone("UTC")); long numDays = (selectedCal.getTimeInMillis() / 86400000) - (creationCal.getTimeInMillis() / 86400000); if (numDays <= 0) { Activity activity = getActivity(); if (activity != null) { Notify.create(activity, R.string.error_expiry_past, Style.ERROR).show(); } return; } expiry = selectedCal.getTime().getTime() / 1000; } Bundle data = new Bundle(); data.putSerializable(MESSAGE_DATA_EXPIRY, expiry); sendMessageToHandler(MESSAGE_NEW_EXPIRY, data); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return alert.show(); }
From source file:com.FFLive.MySQLConnection.java
public boolean nextGWStarted(String gw) { boolean started = true; try {// ww w . j a v a2s . c om int GW = Integer.parseInt(gw.trim()) + 1; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery("SELECT starts FROM status WHERE Gameweek=" + GW); Calendar now = Calendar.getInstance(); while (rs.next()) { Calendar yes = (new DateParser(rs.getString("starts"))).convertDate(); if (now.after(yes)) { started = true; break; } else { //Gameweek has not started started = false; } } statement.close(); } catch (SQLException sql) { Main.log.ln(2); Main.log.log(2, "Error Checking Gameweek Status\n"); Main.log.log(2, sql); } return started; }
From source file:oscar.form.study.hsfo2.pageUtil.XMLTransferUtil.java
public void addFinalSection(Hsfo2Visit baseLineVd, SitePatient patient, String patientId, Calendar startDate, Calendar endDate, Calendar visitDateValue, XmlCalendar visitDate, XmlCalendar when, String who) { if (visitDateValue.after(startDate) && visitDateValue.before(endDate)) { {/* w ww . ja v a 2 s .c om*/ // sel_HtnDx_type String hdt = baseLineVd.getHtnDxType(); StringHtnDxType.Enum dxType = StringHtnDxType.X; if ("PrimaryHtn".equalsIgnoreCase(hdt)) dxType = StringHtnDxType.PRIMARY_HTN; if ("ElevatedBpReadings".equalsIgnoreCase(hdt)) dxType = StringHtnDxType.ELEVATED_BP_READINGS; else // if ("null".equalsIgnoreCase(hdt)) dxType = StringHtnDxType.X; SelHtnDxType element = patient.addNewSelHtnDxType(); element.setValue(dxType); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Dyslipidemia BHxDyslipidemia element = patient.addNewBHxDyslipidemia(); element.setValue(baseLineVd.isDyslipid()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_DM BHxDM element = patient.addNewBHxDM(); element.setValue(baseLineVd.isDiabetes()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Kidney BHxKidney element = patient.addNewBHxKidney(); element.setValue(baseLineVd.isKidneyDis()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Obesity BHxObesity element = patient.addNewBHxObesity(); element.setValue(baseLineVd.isObesity()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_CHD BHxCHD element = patient.addNewBHxCHD(); element.setValue(baseLineVd.isCHD()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_StrokeTIA BHxStrokeTIA element = patient.addNewBHxStrokeTIA(); element.setValue(baseLineVd.isStroke_TIA()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_Hx_Depression BHxDepression element = patient.addNewBHxDepression(); element.setValue(baseLineVd.isDepression()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Htn BFamHxHtn element = patient.addNewBFamHxHtn(); element.setValue(baseLineVd.isFamHx_Htn()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Dyslipidemia BFamHxDyslipidemia element = patient.addNewBFamHxDyslipidemia(); element.setValue(baseLineVd.isFamHx_Dyslipid()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_DM BFamHxDM element = patient.addNewBFamHxDM(); element.setValue(baseLineVd.isFamHx_Diabetes()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Kidney BFamHxKidney element = patient.addNewBFamHxKidney(); element.setValue(baseLineVd.isFamHx_KidneyDis()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Obesity BFamHxObesity element = patient.addNewBFamHxObesity(); element.setValue(baseLineVd.isFamHx_Obesity()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_CHD BFamHxCHD element = patient.addNewBFamHxCHD(); element.setValue(baseLineVd.isFamHx_CHD()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_StrokeTIA BFamHxStrokeTIA element = patient.addNewBFamHxStrokeTIA(); element.setValue(baseLineVd.isFamHx_Stroke_TIA()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } { // b_FamHx_Depression BFamHxDepression element = patient.addNewBFamHxDepression(); element.setValue(baseLineVd.isFamHx_Depression()); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getSBP() > 0) { // cmp_BP CmpBP element = patient.addNewCmpBP(); element.setSystolic(Integer.valueOf(baseLineVd.getSBP())); element.setDiastolic(Integer.valueOf(baseLineVd.getDBP())); element.setAutoOfficeMonitor(toYesNo(baseLineVd.isMonitor())); element.setValueDate(visitDate); // FIXME:???? which value date to set?? element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getHeight() > 0) { // dbl_Height_cm double height = baseLineVd.getHeight(); String heightUnit = baseLineVd.getHeight_unit(); if ("inch".equalsIgnoreCase(heightUnit)) { // convert inch to cm height *= 2.54; } DblHeightCm element = patient.addNewDblHeightCm(); element.setValue(height); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getWeight() > 0) { // dbl_Weight_kg double weight = baseLineVd.getWeight(); String weightUnit = baseLineVd.getWeight_unit(); if ("lb".equalsIgnoreCase(weightUnit)) { // convert lb to kg weight *= 0.45359237; } DblWeightKg element = patient.addNewDblWeightKg(); element.setValue(weight); element.setValueDate(visitDate); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getWaist() > 0) { // dbl_WaistCircumf_cm double waist = baseLineVd.getWaist(); String waistUnit = baseLineVd.getWaist_unit(); if ("inch".equalsIgnoreCase(waistUnit)) { // convert inch to cm waist *= 2.54; } DblWaistCircumfCm element = patient.addNewDblWaistCircumfCm(); element.setValue(waist); element.setSignedWhen(when); element.setSignedWho(who); element.setValueDate(visitDate); } } if (baseLineVd.getTC_HDL_LabresultsDate() != null) { final XmlCalendar labWorkSection1Date = new XmlCalendar( dformat2.format(baseLineVd.getTC_HDL_LabresultsDate())); Calendar labDate1 = Calendar.getInstance(); labDate1.setTime(baseLineVd.getTC_HDL_LabresultsDate()); if (labDate1.after(startDate) && labDate1.before(endDate)) { if (baseLineVd.getLDL() > 0) { // dbl_LDL_mM DblLDLMM element = patient.addNewDblLDLMM(); element.setValue(baseLineVd.getLDL()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getTC_HDL() > 0) { // dbl_TCtoHDL DblTCtoHDL element = patient.addNewDblTCtoHDL(); element.setValue(baseLineVd.getTC_HDL()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getHDL() > 0) { // dbl_HDL_mM DblHDLMM element = patient.addNewDblHDLMM(); element.setValue(baseLineVd.getHDL()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getTriglycerides() > 0) { // dbl_Triglycerides_mM DblTriglyceridesMM element = patient.addNewDblTriglyceridesMM(); element.setValue(baseLineVd.getTriglycerides()); element.setValueDate(labWorkSection1Date); element.setSignedWhen(when); element.setSignedWho(who); } } } if (baseLineVd.getA1C_LabresultsDate() != null) { final XmlCalendar labWorkSection2Date = new XmlCalendar( dformat2.format(baseLineVd.getA1C_LabresultsDate())); Calendar labDate2 = Calendar.getInstance(); labDate2.setTime(baseLineVd.getA1C_LabresultsDate()); if (labDate2.after(startDate) && labDate2.before(endDate)) { if (baseLineVd.getA1C() > 0) { // dbl_A1C_fraction DblA1CFraction element = patient.addNewDblA1CFraction(); element.setValue(baseLineVd.getA1C() / 100); element.setValueDate(labWorkSection2Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getFBS() > 0) { // dbl_FBS_mM DblFBSMM element = patient.addNewDblFBSMM(); element.setValue(baseLineVd.getFBS()); element.setValueDate(labWorkSection2Date); element.setSignedWhen(when); element.setSignedWho(who); } } } if (baseLineVd.getEgfrDate() != null) { final XmlCalendar labWorkSection3Date = new XmlCalendar(dformat2.format(baseLineVd.getEgfrDate())); //final Calendar labWorkSection3Date = ConvertUtil.dateToCalendar( baseLineVd.getEgfrDate() ); //the UI use EGFR date Calendar labDate3 = Calendar.getInstance(); labDate3.setTime(baseLineVd.getEgfrDate()); if (labDate3.after(startDate) && labDate3.before(endDate)) { if (baseLineVd.getEgfr() > 0) { // int_eGFR_mLPerMin IntEGFRMLPerMin element = patient.addNewIntEGFRMLPerMin(); element.setValue(baseLineVd.getEgfr()); element.setValueDate(labWorkSection3Date); element.setSignedWhen(when); element.setSignedWho(who); } if (baseLineVd.getAcr() > 0) { // dbl_ACR_mgPermmol DblACRMgPermmol element = patient.addNewDblACRMgPermmol(); element.setValue(baseLineVd.getAcr()); element.setValueDate(labWorkSection3Date); element.setSignedWhen(when); element.setSignedWho(who); } // HsfSiteCode_key } } }
From source file:pl.psnc.dl.wf4ever.sms.SemanticMetadataServiceImplTest.java
/** * Test method for//from w w w .j a va 2 s.c o m * {@link pl.psnc.dl.wf4ever.sms.SemanticMetadataServiceImpl#getManifest(java.net.URI, org.openrdf.rio.RDFFormat)} . * * @throws IOException * @throws SQLException * @throws NamingException * @throws ClassNotFoundException * @throws URISyntaxException */ @Test public final void testGetManifest() throws IOException, ClassNotFoundException, NamingException, SQLException, URISyntaxException { SemanticMetadataService sms = new SemanticMetadataServiceImpl(userProfile, false); try { Assert.assertNull("Returns null when manifest does not exist", sms.getManifest(researchObject, RDFFormat.RDFXML)); Calendar before = Calendar.getInstance(); sms.createResearchObject(researchObject); Calendar after = Calendar.getInstance(); OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); model.read(sms.getManifest(researchObject, RDFFormat.RDFXML), null); Individual manifest = model.getIndividual(researchObject.getManifestUri().toString()); Individual ro = model.getIndividual(researchObject.getUri().toString()); Assert.assertNotNull("Manifest must contain ro:Manifest", manifest); Assert.assertNotNull("Manifest must contain ro:ResearchObject", ro); Assert.assertTrue("Manifest must be a ro:Manifest", manifest.hasRDFType(RO.NAMESPACE + "Manifest")); Assert.assertTrue("RO must be a ro:ResearchObject", ro.hasRDFType(RO.NAMESPACE + "ResearchObject")); Literal createdLiteral = manifest.getPropertyValue(DCTerms.created).asLiteral(); Assert.assertNotNull("Manifest must contain dcterms:created", createdLiteral); Assert.assertEquals("Date type is xsd:dateTime", XSDDatatype.XSDdateTime, createdLiteral.getDatatype()); Calendar created = ((XSDDateTime) createdLiteral.getValue()).asCalendar(); Assert.assertTrue("Created is a valid date", !before.after(created) && !after.before(created)); // Resource creatorResource = manifest.getPropertyResourceValue(DCTerms.creator); // Assert.assertNotNull("Manifest must contain dcterms:creator", creatorResource); // Individual creator = creatorResource.as(Individual.class); // Assert.assertTrue("Creator must be a foaf:Agent", creator.hasRDFType("http://xmlns.com/foaf/0.1/Agent")); // Assert.assertEquals("Creator name must be correct", "RODL", creator.getPropertyValue(foafName).asLiteral() // .getString()); Resource creatorResource = ro.getPropertyResourceValue(DCTerms.creator); Assert.assertNotNull("RO must contain dcterms:creator", creatorResource); OntModel userModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_LITE_MEM); userModel.read(sms.getNamedGraph(new URI(creatorResource.getURI()), RDFFormat.RDFXML), ""); Individual creator = userModel.getIndividual(creatorResource.getURI()); Assert.assertTrue("Creator must be a foaf:Agent", creator.hasRDFType("http://xmlns.com/foaf/0.1/Agent")); Assert.assertEquals("Creator name must be correct", userProfile.getName(), creator.getPropertyValue(FOAF.name).asLiteral().getString()); } finally { sms.close(); } }
From source file:org.gatein.wcm.services.impl.WcmServiceImpl.java
@Schedule(hour = "*", minute = "*/" + Wcm.TIMEOUTS.TIMER) void checkUnlocks() { try {//from ww w . j a v a 2s . c om List<Lock> lockList = em.createNamedQuery("listLocks").getResultList(); for (Lock l : lockList) { Calendar created = (Calendar) l.getCreated().clone(); created.add(Calendar.MINUTE, Wcm.TIMEOUTS.LOCKS); Calendar now = Calendar.getInstance(); if (now.after(created)) { log.info("Timeout for lock: " + l); em.remove(l); } } } catch (Exception e) { log.warning("Error querying/deleting locks"); e.printStackTrace(); } }
From source file:com.dell.asm.asmcore.asmmanager.util.firmwarerepository.FirmwareUtil.java
/** * Runs an inventory job and blocks until it completes. Return true if it finishes or false if it timesout. * /*from w w w .j a v a2 s . c om*/ * @param device the device to run and block on the inventory job. * @throws JobManagerException * @throws InterruptedException */ public boolean runInventoryJobAndBlockUntilComplete(final DeviceInventoryEntity device) throws JobManagerException, InterruptedException { boolean successful = true; logger.debug("FirmwareUtil's runInventoryJobAndBlockUntilComplete starting for " + device.getRefId()); final JobDetail updateInventoryJob = this.scheduleInventoryJobImmediately(device); final String updateInventoryJobName = updateInventoryJob.getKey().getName(); JobStatus invJobStatus; final Calendar now = Calendar.getInstance(); final Calendar endTime = Calendar.getInstance(); endTime.add(Calendar.MINUTE, 5); // set the end time to 5 min from now do { Thread.sleep(20 * 1000); // every 20 seconds invJobStatus = JobStatus.valueOf(historyMgr.getExecHistoryStatus(updateInventoryJobName)); now.setTime(new Date()); } while ((JobStatus.STARTING.equals(invJobStatus) || JobStatus.IN_PROGRESS.equals(invJobStatus)) && (endTime.after(now))); if (!JobStatus.SUCCESSFUL.equals(invJobStatus)) { // inventory job failed or timed out logger.error("Inventory job failed or timed out!"); successful = false; } logger.info( "FirmwareUtil's runInventoryJobAndBlockUntilComplete is complete for device " + device.getRefId()); return successful; }
From source file:org.kuali.kfs.module.purap.document.service.impl.PurchaseOrderServiceImpl.java
/** * @see org.kuali.kfs.module.purap.document.service.PurchaseOrderService#autoCloseRecurringOrders() *//*from w ww . ja v a 2s .c o m*/ @Override public boolean autoCloseRecurringOrders() { LOG.debug("autoCloseRecurringOrders() started"); boolean shouldSendEmail = true; MailMessage message = new MailMessage(); String parameterEmail = parameterService.getParameterValueAsString(AutoCloseRecurringOrdersStep.class, PurapParameterConstants.AUTO_CLOSE_RECURRING_PO_TO_EMAIL_ADDRESSES); if (StringUtils.isEmpty(parameterEmail)) { // Don't stop the show if the email address is wrong, log it and continue. LOG.error( "autoCloseRecurringOrders(): parameterEmail is missing, we'll not send out any emails for this job."); shouldSendEmail = false; } if (shouldSendEmail) { message = setMessageAddressesAndSubject(message, parameterEmail); } StringBuffer emailBody = new StringBuffer(); // There should always be a "AUTO_CLOSE_RECURRING_ORDER_DT" // row in the table, this method sets it to "mm/dd/yyyy" after processing. String recurringOrderDateString = parameterService.getParameterValueAsString( AutoCloseRecurringOrdersStep.class, PurapParameterConstants.AUTO_CLOSE_RECURRING_PO_DATE); boolean validDate = true; java.util.Date recurringOrderDate = null; try { recurringOrderDate = dateTimeService.convertToDate(recurringOrderDateString); } catch (ParseException pe) { validDate = false; } if (StringUtils.isEmpty(recurringOrderDateString) || recurringOrderDateString.equalsIgnoreCase("mm/dd/yyyy") || (!validDate)) { if (recurringOrderDateString.equalsIgnoreCase("mm/dd/yyyy")) { if (LOG.isDebugEnabled()) { LOG.debug("autoCloseRecurringOrders(): mm/dd/yyyy " + "was found in the Application Settings table. No orders will be closed, method will end."); } if (shouldSendEmail) { emailBody.append("The AUTO_CLOSE_RECURRING_ORDER_DT found in the Application Settings table " + "was mm/dd/yyyy. No recurring PO's were closed."); } } else { if (LOG.isDebugEnabled()) { LOG.debug("autoCloseRecurringOrders(): An invalid autoCloseRecurringOrdersDate " + "was found in the Application Settings table: " + recurringOrderDateString + ". Method will end."); } if (shouldSendEmail) { emailBody.append( "An invalid AUTO_CLOSE_RECURRING_ORDER_DT was found in the Application Settings table: " + recurringOrderDateString + ". No recurring PO's were closed."); } } if (shouldSendEmail) { sendMessage(message, emailBody.toString()); } LOG.info("autoCloseRecurringOrders() ended"); return false; } LOG.info( "autoCloseRecurringOrders() The autoCloseRecurringOrdersDate found in the Application Settings table was " + recurringOrderDateString); if (shouldSendEmail) { emailBody.append("The autoCloseRecurringOrdersDate found in the Application Settings table was " + recurringOrderDateString + "."); } Calendar appSettingsDate = dateTimeService.getCalendar(recurringOrderDate); Timestamp appSettingsDay = new Timestamp(appSettingsDate.getTime().getTime()); Calendar todayMinusThreeMonths = getTodayMinusThreeMonths(); Timestamp threeMonthsAgo = new Timestamp(todayMinusThreeMonths.getTime().getTime()); if (appSettingsDate.after(todayMinusThreeMonths)) { LOG.info("autoCloseRecurringOrders() The appSettingsDate: " + appSettingsDay + " is after todayMinusThreeMonths: " + threeMonthsAgo + ". The program will end."); if (shouldSendEmail) { emailBody.append("\n\nThe autoCloseRecurringOrdersDate: " + appSettingsDay + " is after todayMinusThreeMonths: " + threeMonthsAgo + ". The program will end."); sendMessage(message, emailBody.toString()); } LOG.info("autoCloseRecurringOrders() ended"); return false; } List<AutoClosePurchaseOrderView> closeList = purchaseOrderDao .getAutoCloseRecurringPurchaseOrders(getExcludedVendorChoiceCodes()); // we need to eliminate the AutoClosePurchaseOrderView whose workflowdocument status is not OPEN.. // KFSMI-7533 List<AutoClosePurchaseOrderView> purchaseOrderAutoCloseList = filterDocumentsForAppDocStatusOpen(closeList); LOG.info("autoCloseRecurringOrders(): " + purchaseOrderAutoCloseList.size() + " PO's were returned for processing."); int counter = 0; for (AutoClosePurchaseOrderView poAutoClose : purchaseOrderAutoCloseList) { LOG.info("autoCloseRecurringOrders(): Testing PO ID " + poAutoClose.getPurapDocumentIdentifier() + ". recurringPaymentEndDate: " + poAutoClose.getRecurringPaymentEndDate()); if (poAutoClose.getRecurringPaymentEndDate().before(threeMonthsAgo)) { String newStatus = PurapConstants.PurchaseOrderStatuses.APPDOC_PENDING_CLOSE; String annotation = "This recurring PO was automatically closed in batch."; String documentType = PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT; PurchaseOrderDocument document = getPurchaseOrderByDocumentNumber(poAutoClose.getDocumentNumber()); boolean rulePassed = kualiRuleService.applyRules(new AttributedRouteDocumentEvent("", document)); boolean success = true; if (success) { ++counter; if (counter == 1) { emailBody.append( "\n\nThe following recurring Purchase Orders will be closed by auto close recurring batch job \n"); } LOG.info("autoCloseRecurringOrders() PO ID " + poAutoClose.getPurapDocumentIdentifier() + " will be closed."); createNoteForAutoCloseOrders(document, annotation); createAndRoutePotentialChangeDocument(poAutoClose.getDocumentNumber(), documentType, annotation, null, newStatus); if (shouldSendEmail) { emailBody.append("\n\n" + counter + " PO ID: " + poAutoClose.getPurapDocumentIdentifier() + ", End Date: " + poAutoClose.getRecurringPaymentEndDate() + ", Status: " + poAutoClose.getApplicationDocumentStatus() + ", VendorChoice: " + poAutoClose.getVendorChoiceCode() + ", RecurringPaymentType: " + poAutoClose.getRecurringPaymentTypeCode()); } } else { // If it was unsuccessful, we have to clear the error map in the GlobalVariables so that the previous // error would not still be lingering around and the next PO in the list can be validated. GlobalVariables.getMessageMap().clearErrorMessages(); } } } if (counter == 0) { LOG.info("\n\nNo recurring PO's fit the conditions for closing."); if (shouldSendEmail) { emailBody.append("\n\nNo recurring PO's fit the conditions for closing."); } } if (shouldSendEmail) { sendMessage(message, emailBody.toString()); } resetAutoCloseRecurringOrderDateParameter(); LOG.debug("autoCloseRecurringOrders() ended"); return true; }
From source file:com.peterbochs.instrument.InstrumentPanel.java
private void runTimer() { if (interruptTimer != null) { interruptTimer.cancel();//from w w w.j a v a 2 s . com } interruptTimer = new Timer(); interruptTimer.schedule(new TimerTask() { Hashtable<Long, Integer> oldInterruptRecords; public void run() { try { synchronized (allSeries) { ArrayList<Long> list = Collections.list(InterruptSocketServer.interruptRecords.keys()); Date d = new Date(); // int noOfFrame = getTimeframe() / getSpeed(); oldInterruptRecords = (Hashtable<Long, Integer>) InterruptSocketServer.interruptRecords .clone(); ((InterruptTableModel) jInterruptTable.getModel()).fireTableDataChanged(); for (int x = 0; x < list.size(); x++) { long interuptNoL = list.get(x); int interruptNo = (int) interuptNoL; if (allSeries.get(interruptNo) != null) { TimeSeries series = allSeries.get(interruptNo); List<TimeSeriesDataItem> items = series.getItems(); for (int z = items.size() - 1; z >= 0; z--) { RegularTimePeriod pd = items.get(z).getPeriod(); Calendar cal1 = Calendar.getInstance(); cal1.add(Calendar.MILLISECOND, -1 * getTimeframe()); Calendar cal2 = Calendar.getInstance(); cal2.setTime(pd.getEnd()); if (cal1.after(cal2)) { series.delete(pd); } } series.add(new Millisecond(d), InterruptSocketServer.interruptRecords.get(interuptNoL) - oldInterruptRecords.get(interuptNoL)); // InterruptSocketServer.interruptRecords.put(interuptNoL, 0); } else { TimeSeries newSeries = new TimeSeries("Int 0x" + Integer.toHexString(interruptNo)); interruptDataset.addSeries(newSeries); allSeries.put(interruptNo, newSeries); } } interruptChart.fireChartChanged(); } } catch (Exception ex) { ex.printStackTrace(); } } }, 0, getSpeed()); }