@Test public void checkAgeIsCorrectlyCalculated() throws ParseException, ComponentLookupException { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); String birthDateString = "01-01-2015 12:00:00"; Date birthDate = dateFormat.parse(birthDateString); when(this.patientRecordObj.getDateValue(DATE_OF_BIRTH_PROPERTY_NAME)).thenReturn(birthDate); String measureDateString = "01-01-2016 12:00:00"; Date measureDate = dateFormat.parse(measureDateString); when(this.measurement.getDateValue(DATE_PROPERTY_NAME)).thenReturn(measureDate); this.mocker.getComponentUnderTest().onEvent(this.event, this.source, this.data); verify(this.measurement).setFloatValue(eq(AGE_PROPERTY_NAME), eq(365 / 30.4375f)); measureDateString = "01-01-2035 12:00:00"; measureDate = dateFormat.parse(measureDateString); when(this.measurement.getDateValue(DATE_PROPERTY_NAME)).thenReturn(measureDate); this.mocker.getComponentUnderTest().onEvent(this.event, this.source, this.data); verify(this.measurement).setFloatValue(eq(AGE_PROPERTY_NAME), eq((365 * 20 + 5) / 30.4375f)); measureDateString = "01-03-2016 12:00:00"; measureDate = dateFormat.parse(measureDateString); when(this.measurement.getDateValue(DATE_PROPERTY_NAME)).thenReturn(measureDate); this.mocker.getComponentUnderTest().onEvent(this.event, this.source, this.data); verify(this.measurement).setFloatValue(eq(AGE_PROPERTY_NAME), eq((31 + 29 + 365) / 30.4375f)); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Date birthDate = patientRecordObj.getDateValue("date_of_birth"); List<BaseObject> objects = doc.getXObjects(CLASS_REFERENCE); if (objects == null || objects.isEmpty()) { return; } for (BaseObject measurement : objects) { if (measurement == null) { continue; } else if ("birth".equals(measurement.getStringValue("type"))) { measurement.setFloatValue(AGE_PROPERTY_NAME, 0); measurement.removeField(DATE_PROPERTY_NAME); continue; } Date measurementDate = measurement.getDateValue(DATE_PROPERTY_NAME); if (measurementDate == null || birthDate == null) { measurement.removeField(AGE_PROPERTY_NAME); } else { measurement.setFloatValue(AGE_PROPERTY_NAME, Days.daysBetween(new DateTime(birthDate), new DateTime(measurementDate)).getDays() / 30.4375f); } } }
MeasurementAgeUpdater extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Date birthDate = patientRecordObj.getDateValue("date_of_birth"); List<BaseObject> objects = doc.getXObjects(CLASS_REFERENCE); if (objects == null || objects.isEmpty()) { return; } for (BaseObject measurement : objects) { if (measurement == null) { continue; } else if ("birth".equals(measurement.getStringValue("type"))) { measurement.setFloatValue(AGE_PROPERTY_NAME, 0); measurement.removeField(DATE_PROPERTY_NAME); continue; } Date measurementDate = measurement.getDateValue(DATE_PROPERTY_NAME); if (measurementDate == null || birthDate == null) { measurement.removeField(AGE_PROPERTY_NAME); } else { measurement.setFloatValue(AGE_PROPERTY_NAME, Days.daysBetween(new DateTime(birthDate), new DateTime(measurementDate)).getDays() / 30.4375f); } } } }
MeasurementAgeUpdater extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Date birthDate = patientRecordObj.getDateValue("date_of_birth"); List<BaseObject> objects = doc.getXObjects(CLASS_REFERENCE); if (objects == null || objects.isEmpty()) { return; } for (BaseObject measurement : objects) { if (measurement == null) { continue; } else if ("birth".equals(measurement.getStringValue("type"))) { measurement.setFloatValue(AGE_PROPERTY_NAME, 0); measurement.removeField(DATE_PROPERTY_NAME); continue; } Date measurementDate = measurement.getDateValue(DATE_PROPERTY_NAME); if (measurementDate == null || birthDate == null) { measurement.removeField(AGE_PROPERTY_NAME); } else { measurement.setFloatValue(AGE_PROPERTY_NAME, Days.daysBetween(new DateTime(birthDate), new DateTime(measurementDate)).getDays() / 30.4375f); } } } MeasurementAgeUpdater(); }
MeasurementAgeUpdater extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Date birthDate = patientRecordObj.getDateValue("date_of_birth"); List<BaseObject> objects = doc.getXObjects(CLASS_REFERENCE); if (objects == null || objects.isEmpty()) { return; } for (BaseObject measurement : objects) { if (measurement == null) { continue; } else if ("birth".equals(measurement.getStringValue("type"))) { measurement.setFloatValue(AGE_PROPERTY_NAME, 0); measurement.removeField(DATE_PROPERTY_NAME); continue; } Date measurementDate = measurement.getDateValue(DATE_PROPERTY_NAME); if (measurementDate == null || birthDate == null) { measurement.removeField(AGE_PROPERTY_NAME); } else { measurement.setFloatValue(AGE_PROPERTY_NAME, Days.daysBetween(new DateTime(birthDate), new DateTime(measurementDate)).getDays() / 30.4375f); } } } MeasurementAgeUpdater(); @Override void onEvent(Event event, Object source, Object data); }
MeasurementAgeUpdater extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Date birthDate = patientRecordObj.getDateValue("date_of_birth"); List<BaseObject> objects = doc.getXObjects(CLASS_REFERENCE); if (objects == null || objects.isEmpty()) { return; } for (BaseObject measurement : objects) { if (measurement == null) { continue; } else if ("birth".equals(measurement.getStringValue("type"))) { measurement.setFloatValue(AGE_PROPERTY_NAME, 0); measurement.removeField(DATE_PROPERTY_NAME); continue; } Date measurementDate = measurement.getDateValue(DATE_PROPERTY_NAME); if (measurementDate == null || birthDate == null) { measurement.removeField(AGE_PROPERTY_NAME); } else { measurement.setFloatValue(AGE_PROPERTY_NAME, Days.daysBetween(new DateTime(birthDate), new DateTime(measurementDate)).getDays() / 30.4375f); } } } MeasurementAgeUpdater(); @Override void onEvent(Event event, Object source, Object data);  }