/** * @see java.lang.Object#toString() */ @Override public String toString() { return getaIsToB() + "/" + getbIsToA(); }
@Override public String toString() { String relType = getRelationshipType() == null ? "NULL" : getRelationshipType().getaIsToB(); return personA + " is the " + relType + " of " + personB; }
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) * @should fail validation if aIsToB(or A is To B) is null or empty or whitespace * @should fail validation if bIsToA(or B is To A) is null or empty or whitespace * @should fail validation if description is null or empty or whitespace * @should pass validation if all required fields are set * @should fail validation if relationshipTypeName already exist * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ @Override public void validate(Object obj, Errors errors) { RelationshipType relationshipType = (RelationshipType) obj; if (relationshipType == null) { errors.rejectValue("relationshipType", "error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "aIsToB", "RelationshipType.aIsToB.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bIsToA", "RelationshipType.bIsToA.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "RelationshipType.description.required"); RelationshipType exist = Context.getPersonService().getRelationshipTypeByName( relationshipType.getaIsToB() + "/" + relationshipType.getbIsToA()); if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(relationshipType.getUuid(), exist.getUuid())) { errors.reject("duplicate.relationshipType"); } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "aIsToB", "bIsToA", "description", "retireReason"); } } }
String output = "<update tableName=\"relationship_type\"><column name=\"uuid\" value=\"" + type.getUuid() + "\"/><where> relationship_type_id = '" + type.getRelationshipTypeId() + "' and a_is_to_b = '" + type.getaIsToB().replace("'", "\\'") + "' and b_is_to_a = '" + type.getbIsToA().replace("'", "\\'") + "'</where></update>"; System.out.println(output);
boolean patientCanBeEitherPerson = relType.getbIsToA().equals(relType.getaIsToB());
@PropertyGetter("displayAIsToB") public String getDisplayAIsToBe(RelationshipType delegate) { String localization = getLocalization(delegate.getUuid(), "aIsToB"); if (localization != null) { return localization; } else { return StringUtils.isEmpty(delegate.getaIsToB()) ? "" : delegate.getaIsToB(); } }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<RelationshipType> doSearch(RequestContext context) { String queryString = context.getParameter("q"); List<RelationshipType> allRelationshipTypes = Context.getPersonService().getAllRelationshipTypes(); List<RelationshipType> unRetiredRelationshipTypes = new ArrayList<RelationshipType>(); for (RelationshipType relationshipType : allRelationshipTypes) { if (!relationshipType.isRetired() && (relationshipType.getaIsToB().contains(queryString) || relationshipType.getbIsToA().contains( queryString))) unRetiredRelationshipTypes.add(relationshipType); } return new NeedsPaging<RelationshipType>(unRetiredRelationshipTypes, context); }
/** * Fetches a relationshipType by uuid, if no match is found, it tries to look up one with a * matching name with the assumption that the passed parameter is a relationshipType name * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public RelationshipType getByUniqueId(String uuid) { RelationshipType relationshipType = Context.getPersonService().getRelationshipTypeByUuid(uuid); if (relationshipType == null) { List<RelationshipType> relationshipTypes = Context.getPersonService().getAllRelationshipTypes(); for (RelationshipType possibleRelationshipType : relationshipTypes) { if (possibleRelationshipType.getaIsToB().equalsIgnoreCase(uuid) || possibleRelationshipType.getbIsToA().equalsIgnoreCase(uuid)) { relationshipType = possibleRelationshipType; break; } } } return relationshipType; }
/** * @param relationship * @return relationship type and start date */ @PropertyGetter("display") public String getDisplayString(Relationship relationship) { String relType = relationship.getRelationshipType() == null ? "NULL" : relationship.getRelationshipType() .getaIsToB(); return relationship.getPersonA().getGivenName() + " is the " + relType + " of " + relationship.getPersonB().getGivenName(); }
List<RelationshipType> relationshipTypes = personService.getAllRelationshipTypes(); for (RelationshipType temp : relationshipTypes) { if (temp.getbIsToA().equalsIgnoreCase(relation) || temp.getaIsToB().equalsIgnoreCase(relation)) { relationshipType = temp; break;
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("display", getObject().toString()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("aIsToB", getObject().getaIsToB()); assertPropEquals("bIsToA", getObject().getbIsToA()); assertPropEquals("displayAIsToB", getObject().getaIsToB()); assertPropEquals("displayBIsToA", getObject().getbIsToA()); assertPropEquals("retired", getObject().isRetired()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("display", getObject().toString()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("aIsToB", getObject().getaIsToB()); assertPropEquals("bIsToA", getObject().getbIsToA()); assertPropEquals("displayAIsToB", getObject().getaIsToB()); assertPropEquals("displayBIsToA", getObject().getbIsToA()); assertPropEquals("retired", getObject().isRetired()); assertPropEquals("weight", getObject().getWeight()); assertPropPresent("auditInfo"); }