@Test public void shouldThrowErrorIfPatientsToInitiateTreatmentIsVisibleAndIsMissing() throws NoSuchFieldException, IllegalAccessException { RegimenLineItem regimenLineItem = make(a(defaultRegimenLineItem)); regimenLineItem.setPatientsToInitiateTreatment(null); expectedException.expect(DataException.class); expectedException.expectMessage(RNR_VALIDATION_ERROR); RegimenTemplate regimenTemplate = new RegimenTemplate(); RegimenColumn regimenColumn = new RegimenColumn(1l, INITIATED_TREATMENT, INITIATED_TREATMENT, "Number", true,1, 2l); regimenTemplate.setColumns(asList(regimenColumn)); regimenLineItem.validate(regimenTemplate); }
public void validate(RegimenTemplate regimenTemplate) throws NoSuchFieldException, IllegalAccessException { String[] mandatoryVisibleColumns = new String[]{ON_TREATMENT, INITIATED_TREATMENT, STOPPED_TREATMENT}; for (String mandatoryColumn : mandatoryVisibleColumns) { if (regimenTemplate.isRegimenColumnVisible(mandatoryColumn)) { Field field = RegimenLineItem.class.getDeclaredField(mandatoryColumn); field.setAccessible(true); Object fieldValue = field.get(this); if (fieldValue == null) throw new DataException(RNR_VALIDATION_ERROR); } } }
RegimenLineItem extends LineItem { public void validate(RegimenTemplate regimenTemplate) throws NoSuchFieldException, IllegalAccessException { String[] mandatoryVisibleColumns = new String[]{ON_TREATMENT, INITIATED_TREATMENT, STOPPED_TREATMENT}; for (String mandatoryColumn : mandatoryVisibleColumns) { if (regimenTemplate.isRegimenColumnVisible(mandatoryColumn)) { Field field = RegimenLineItem.class.getDeclaredField(mandatoryColumn); field.setAccessible(true); Object fieldValue = field.get(this); if (fieldValue == null) throw new DataException(RNR_VALIDATION_ERROR); } } } }
RegimenLineItem extends LineItem { public void validate(RegimenTemplate regimenTemplate) throws NoSuchFieldException, IllegalAccessException { String[] mandatoryVisibleColumns = new String[]{ON_TREATMENT, INITIATED_TREATMENT, STOPPED_TREATMENT}; for (String mandatoryColumn : mandatoryVisibleColumns) { if (regimenTemplate.isRegimenColumnVisible(mandatoryColumn)) { Field field = RegimenLineItem.class.getDeclaredField(mandatoryColumn); field.setAccessible(true); Object fieldValue = field.get(this); if (fieldValue == null) throw new DataException(RNR_VALIDATION_ERROR); } } } RegimenLineItem(Long rnrId, RegimenCategory category, Long createdBy, Long modifiedBy); }
RegimenLineItem extends LineItem { public void validate(RegimenTemplate regimenTemplate) throws NoSuchFieldException, IllegalAccessException { String[] mandatoryVisibleColumns = new String[]{ON_TREATMENT, INITIATED_TREATMENT, STOPPED_TREATMENT}; for (String mandatoryColumn : mandatoryVisibleColumns) { if (regimenTemplate.isRegimenColumnVisible(mandatoryColumn)) { Field field = RegimenLineItem.class.getDeclaredField(mandatoryColumn); field.setAccessible(true); Object fieldValue = field.get(this); if (fieldValue == null) throw new DataException(RNR_VALIDATION_ERROR); } } } RegimenLineItem(Long rnrId, RegimenCategory category, Long createdBy, Long modifiedBy); void setRegimenFieldsAccordingToTemplate(RegimenTemplate regimenTemplate); void copyCreatorEditableFieldsForRegimen(RegimenLineItem regimenLineItem, RegimenTemplate regimenTemplate); @Override boolean compareCategory(LineItem lineItem); @Override String getCategoryName(); @Override String getValue(String columnName); @Override boolean isRnrLineItem(); void validate(RegimenTemplate regimenTemplate); void populate(RegimenLineItem regimenLineItem); }
RegimenLineItem extends LineItem { public void validate(RegimenTemplate regimenTemplate) throws NoSuchFieldException, IllegalAccessException { String[] mandatoryVisibleColumns = new String[]{ON_TREATMENT, INITIATED_TREATMENT, STOPPED_TREATMENT}; for (String mandatoryColumn : mandatoryVisibleColumns) { if (regimenTemplate.isRegimenColumnVisible(mandatoryColumn)) { Field field = RegimenLineItem.class.getDeclaredField(mandatoryColumn); field.setAccessible(true); Object fieldValue = field.get(this); if (fieldValue == null) throw new DataException(RNR_VALIDATION_ERROR); } } } RegimenLineItem(Long rnrId, RegimenCategory category, Long createdBy, Long modifiedBy); void setRegimenFieldsAccordingToTemplate(RegimenTemplate regimenTemplate); void copyCreatorEditableFieldsForRegimen(RegimenLineItem regimenLineItem, RegimenTemplate regimenTemplate); @Override boolean compareCategory(LineItem lineItem); @Override String getCategoryName(); @Override String getValue(String columnName); @Override boolean isRnrLineItem(); void validate(RegimenTemplate regimenTemplate); void populate(RegimenLineItem regimenLineItem); static final String ON_TREATMENT; static final String INITIATED_TREATMENT; static final String STOPPED_TREATMENT; static final String TYPE_NUMERIC; static final String REMARKS; }