@Test public void behavesNormallyWithNullMeasurement() throws ComponentLookupException { BaseObject measurement2 = mock(BaseObject.class); BaseObject measurement3 = null; BaseObject measurement4 = mock(BaseObject.class); this.objects.add(measurement2); this.objects.add(measurement3); this.objects.add(measurement4); when(measurement2.getDateValue(DATE_PROPERTY_NAME)).thenReturn(new Date()); when(measurement4.getDateValue(DATE_PROPERTY_NAME)).thenReturn(new Date()); this.mocker.getComponentUnderTest().onEvent(this.event, this.source, this.data); verify(this.measurement).setFloatValue(eq(AGE_PROPERTY_NAME), anyFloat()); verify(measurement2).setFloatValue(eq(AGE_PROPERTY_NAME), anyFloat()); verify(measurement4).setFloatValue(eq(AGE_PROPERTY_NAME), anyFloat()); }
@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);  }