private boolean isConceptProposal(String identifier) { return OpenmrsUtil.nullSafeEquals(identifier, OpenmrsConstants.PROPOSED_CONCEPT_IDENTIFIER); }
private void markAsDirty(Object oldValue, Object newValue) { //Should we ignore the case for Strings? if (!isDirty() && obsId != null && !OpenmrsUtil.nullSafeEquals(oldValue, newValue)) { dirty = true; } }
/** * Gets an allergy with a given id * * @param allergyId the allergy id * @return the allergy with a matching id */ public Allergy getAllergy(Integer allergyId) { for (Allergy allergy : allergies) { if (OpenmrsUtil.nullSafeEquals(allergy.getAllergyId(), allergyId)) { return allergy; } } return null; }
/** * Gets an allergy reaction with a given id * * @param allergyReactionId the allergy reaction id * @return the allergy reaction with a matching id */ public AllergyReaction getAllergyReaction(Integer allergyReactionId) { for (AllergyReaction reaction : reactions) { if (OpenmrsUtil.nullSafeEquals(reaction.getAllergyReactionId(), allergyReactionId)) { return reaction; } } return null; }
/** * Gets the explicitly specified short name for a locale. * * @param locale locale for which to find a short name * @return the short name, or null if none has been explicitly set */ public ConceptName getShortNameInLocale(Locale locale) { ConceptName bestMatch = null; if (locale != null && !getShortNames().isEmpty()) { for (ConceptName shortName : getShortNames()) { Locale nameLocale = shortName.getLocale(); if (nameLocale.equals(locale)) { return shortName; } // test for partially locale match - any language matches takes precedence over country matches. if (OpenmrsUtil.nullSafeEquals(locale.getLanguage(), nameLocale.getLanguage())) { bestMatch = shortName; } else if (bestMatch == null && StringUtils.isNotBlank(locale.getCountry()) && locale.getCountry().equals(nameLocale.getCountry())) { bestMatch = shortName; } } } return bestMatch; }
private boolean fieldsAreSimilar(Field field, Field fieldToBeReplaced) { return (OpenmrsUtil.nullSafeEquals(field.getName(), fieldToBeReplaced.getName()) && OpenmrsUtil.nullSafeEquals(field.getSelectMultiple(), fieldToBeReplaced.getSelectMultiple()) && OpenmrsUtil.nullSafeEquals(field.getFieldType(), fieldToBeReplaced.getFieldType()) && OpenmrsUtil.nullSafeEquals(field.getConcept(), fieldToBeReplaced.getConcept()) && OpenmrsUtil.nullSafeEquals(field.getTableName(), fieldToBeReplaced.getTableName()) && OpenmrsUtil.nullSafeEquals(field.getDefaultValue(), fieldToBeReplaced.getDefaultValue()) && field.getRetired() != null && !field.getRetired()); }
|| (!OpenmrsUtil.nullSafeEquals(parsedProficientLocalesProperty, proficientLocalesProperty))) { parsedProficientLocalesProperty = proficientLocalesProperty; proficientLocales = new ArrayList<>();
/** * Checks whether orderable of this order is same as other order * * @see org.openmrs.DrugOrder for overridden behaviour * @since 1.10 * @param otherOrder the other order to match on * @return true if the concept of the orders match * @should return false if the concept of the orders do not match * @should return false if other order is null * @should return true if the orders have the same concept */ public boolean hasSameOrderableAs(Order otherOrder) { if (otherOrder == null) { return false; } return OpenmrsUtil.nullSafeEquals(this.getConcept(), otherOrder.getConcept()); }
/** * Checks if this reaction has the same values as the given one * * @param reaction the reaction whose values to compare with * @return true if the values match, else false */ public boolean hasSameValues(AllergyReaction reaction) { if (!OpenmrsUtil.nullSafeEquals(getAllergyReactionId(), reaction.getAllergyReactionId())) { return false; } if (!OpenmrsUtil.nullSafeEquals(getReaction(), reaction.getReaction())) { //if object instances are different but with the same concept id, then not changed if (getReaction() != null && reaction.getReaction() != null) { if (!OpenmrsUtil.nullSafeEquals(getReaction().getConceptId(), reaction.getReaction().getConceptId())) { return false; } } else { return false; } } return OpenmrsUtil.nullSafeEquals(getReactionNonCoded(), reaction.getReactionNonCoded()); } }
/** * @see org.openmrs.hl7.HL7Service#getUuidFromIdentifiers(ca.uhn.hl7v2.model.v25.datatype.CX[]) */ @Override public String getUuidFromIdentifiers(CX[] identifiers) throws HL7Exception { Boolean found = false; String uuid = null; for (CX identifier : identifiers) { // check for UUID as the assigning authority if (OpenmrsUtil.nullSafeEquals(identifier.getAssigningAuthority().getNamespaceID().getValue(), "UUID")) { // check for duplicates if (found && !OpenmrsUtil.nullSafeEquals(identifier.getIDNumber().getValue(), uuid)) { throw new HL7Exception("multiple UUID values found"); } uuid = identifier.getIDNumber().getValue(); found = true; } } // returns null if not found return uuid; }
@Override public boolean matches(Object argument) { Visit visit = (Visit) argument; return OpenmrsUtil.nullSafeEquals(visit.getLocation(), expected.getLocation()) && OpenmrsUtil.nullSafeEquals(visit.getVisitType(), expected.getVisitType()) && OpenmrsUtil.nullSafeEquals(visit.getIndication(), expected.getIndication()) && OpenmrsUtil.nullSafeEquals(visit.getStartDatetime(), expected.getStartDatetime()) && OpenmrsUtil.nullSafeEquals(visit.getStopDatetime(), expected.getStopDatetime()) && (visit.getEncounters().size() == expected.getEncounters().size()); } };
/** * @see org.openmrs.hl7.HL7Service#loadHL7InArchiveData(HL7InArchive) */ @Override public void loadHL7InArchiveData(HL7InArchive archive) throws APIException { // quit early if there is no archive to work with if (archive == null) { return; } // quit early if the message is not migrated or already loaded if (!OpenmrsUtil.nullSafeEquals(archive.getMessageState(), HL7Constants.HL7_STATUS_MIGRATED) || archive.isLoaded()) { return; } try { archive.setHL7Data(OpenmrsUtil.getFileAsString(new File(new URI(archive.getHL7Data())))); archive.setLoaded(true); } catch (URISyntaxException e) { throw new APIException("Hl7Service.malformed.archive.location", new Object[] { archive.getHL7Data() }, e); } catch (IOException e) { throw new APIException("Hl7Service.unable.convert.archive", new Object[] { archive.getHL7Data() }, e); } }
private boolean areDrugOrdersOfSameOrderableAndOverlappingSchedule(Order firstOrder, Order secondOrder) { return firstOrder.hasSameOrderableAs(secondOrder) && !OpenmrsUtil.nullSafeEquals(firstOrder.getPreviousOrder(), secondOrder) && OrderUtil.checkScheduleOverlap(firstOrder, secondOrder) && firstOrder.getOrderType().equals( Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID)); }
/** * moves data to the filesystem from an HL7InArchive * * @param archive * @throws APIException */ private void migrateHL7InArchive(HL7InArchive archive) throws APIException { if (archive == null) { throw new APIException("Hl7Service.migrate.null.archive", (Object[]) null); } if (!OpenmrsUtil.nullSafeEquals(archive.getMessageState(), HL7Constants.HL7_STATUS_PROCESSED)) { throw new APIException("Hl7Service.migrate.archive.state", (Object[]) null); } try { URI uri = writeHL7InArchiveToFileSystem(archive); archive.setHL7Data(uri.toString()); archive.setMessageState(HL7Constants.HL7_STATUS_MIGRATED); saveHL7InArchive(archive); } catch (APIException e) { throw new APIException("Hl7Service.migrate.archive", null, e); } }
/** * Checks the form object for any inconsistencies/errors * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if name is null or empty or whitespace * @should fail validation if name is duplicate * @should pass validation if all required fields have proper values * @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) { super.validate(obj, errors); EncounterRole encounterRole = (EncounterRole) obj; if (!errors.hasErrors()) { EncounterRole duplicate = Context.getEncounterService().getEncounterRoleByName(encounterRole.getName().trim()); if (duplicate != null && duplicate.getUuid() != null && !OpenmrsUtil.nullSafeEquals(encounterRole.getUuid(), duplicate.getUuid())) { errors.rejectValue("name", "encounterRole.duplicate.name", "Specified Encounter Role name already exists, please specify another "); } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason"); } } }
if (duplicate != null && !OpenmrsUtil.nullSafeEquals(encounterType.getUuid(), duplicate.getUuid()) && !duplicate.getRetired()) { errors.rejectValue("name", "EncounterType.error.duplicateEncounterTypeNameSpecified",
Assert.assertTrue(StringUtils.hasText(encrypted)); String actual = Security.decrypt(encrypted); Assert.assertTrue(OpenmrsUtil.nullSafeEquals(expected, actual)); Assert.assertTrue(StringUtils.hasText(encrypted)); actual = Security.decrypt(encrypted); Assert.assertTrue(OpenmrsUtil.nullSafeEquals(expected, actual)); Assert.assertTrue(StringUtils.hasText(encrypted)); actual = Security.decrypt(encrypted); Assert.assertTrue(OpenmrsUtil.nullSafeEquals(expected, actual));
/** * Checks the form object for any inconsistencies/errors * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if user is null or empty or whitespace * @should fail validation if name is already exist in non retired concept class * @should pass validation if description is null or empty or whitespace * @should pass validation if all required fields have proper values * @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) { ConceptClass cc = (ConceptClass) obj; if (cc == null) { errors.rejectValue("conceptClass", "error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name"); if (!errors.hasErrors()) { ConceptClass exist = Context.getConceptService().getConceptClassByName(cc.getName()); if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(cc.getUuid(), exist.getUuid())) { errors.rejectValue("name", "conceptclass.duplicate.name"); } } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason"); } }
/** * Checks the form object for any inconsistencies/errors * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if name is null or empty or whitespace * @should pass validation if all required fields have proper values * @should fail validation if field type name already exist in none retired filed types * @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) { FieldType fieldType = (FieldType) obj; if (fieldType == null) { errors.rejectValue("fieldType", "error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name"); if (!errors.hasErrors()) { FieldType exist = Context.getFormService().getFieldTypeByName(fieldType.getName()); if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(fieldType.getUuid(), exist.getUuid())) { errors.rejectValue("name", "fieldtype.duplicate.name"); } } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name"); } }
private void validateForRequireDrug(Errors errors, DrugOrder order) { //Reject if global property is set to specify a formulation for drug order boolean requireDrug = Context.getAdministrationService().getGlobalPropertyValue( OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, false); OrderService orderService = Context.getOrderService(); if(requireDrug){ if(order.getConcept() != null && OpenmrsUtil.nullSafeEquals(orderService.getNonCodedDrugConcept(), order.getConcept())){ if(order.getDrug() == null && !order.isNonCodedDrug()){ errors.rejectValue("drugNonCoded", "DrugOrder.error.drugNonCodedIsRequired"); } else if(order.getDrug() != null){ errors.rejectValue("concept", "DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet"); } }else{ if(order.getDrug() == null && !order.isNonCodedDrug()){ errors.rejectValue("drug", "DrugOrder.error.drugIsRequired"); } else if(order.getDrug() != null && order.isNonCodedDrug()){ errors.rejectValue("concept", "DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet"); } } } }