/** * Convenience method that returns a display name for the drug, defaults to drug.name * * @return the display name * @since 1.8.5, 1.9.4, 1.10 */ public String getDisplayName() { if (StringUtils.isNotBlank(getName())) { return getName(); } if (getConcept() != null) { return getConcept().getName().getName(); } return ""; }
/** * @throws Exception * @see DrugOrder#copy() */ @Test public void copy_shouldCopyAllDrugOrderFields() throws Exception { DrugOrder drugOrder = new DrugOrder(); Drug drug = new Drug(); drug.setConcept(new Concept()); drugOrder.setDrug(drug); OrderTest.assertThatAllFieldsAreCopied(drugOrder, null); }
/** * Gets whether or not this is a combination drug * * @return Boolean * * @deprecated as of 2.0, use {@link #getCombination()} */ @Deprecated @JsonIgnore public Boolean isCombination() { return getCombination(); }
/** * Turn the given drug into a string acceptable for hl7 and forms * * @param drug Drug to convert to a string * @return String representation of the given drug */ public static String drugToString(Drug drug) { return drug.getDrugId() + "^" + drug.getName() + "^" + HL7Constants.HL7_LOCAL_DRUG; } }
/** * @see Drug#addDrugReferenceMap(DrugReferenceMap) */ @Test public void addDrugReferenceMap_shouldSetDrugAsTheDrugToWhichAMappingIsBeingAdded() { Drug drug1 = new Drug(); drug1.setUuid(UUID_1); Drug drug2 = new Drug(); drug2.setUuid(UUID_2); DrugReferenceMap map = new DrugReferenceMap(); map.setDrug(drug2); drug1.addDrugReferenceMap(map); Assert.assertEquals(drug1, drug1.getDrugReferenceMaps().iterator().next().getDrug()); }
/** * Checks that a given <code>Drug</code> object is valid. * * @param obj the Object to validate * @param errors holds the validation errors * @throws IllegalArgumentException Runtime Exception if the supplied argument is * null or not of type <code>Drug</code> * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail if a concept is not specified */ @Override public void validate(Object obj, Errors errors) throws IllegalArgumentException { if (obj == null || !(obj instanceof Drug)) { throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + Drug.class); } log.debug("request to validate drug having concept: " + ((Drug) obj).getConcept()); ValidationUtils.rejectIfEmpty(errors, "concept", "ConceptDrug.error.conceptRequired"); }
@Override public List<Map<String, Object>> simplify(List<Drug> drugs) { List<Map<String, Object>> simplified = new ArrayList<Map<String, Object>>(); Locale locale = Context.getLocale(); for (Drug drug : drugs) { Map<String, Object> item = new LinkedHashMap<String, Object>(); item.put("id", drug.getId()); item.put("name", drug.getName()); if (drug.getDosageForm() != null) { item.put("dosageForm", drug.getDosageForm().getName(locale).getName()); } if (drug.getRoute() != null) { item.put("route", drug.getRoute().getName(locale).getName()); } item.put("doseStrength", drug.getDoseStrength()); item.put("units", drug.getUnits()); item.put("combination", drug.getCombination()); if (drug.getConcept() != null) { item.put("concept", drug.getConcept().getName(locale).getName()); } simplified.add(item); } return simplified; } }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("retired", getObject().isRetired()); assertPropEquals("doseStrength", getObject().getDoseStrength()); assertPropEquals("maximumDailyDose", getObject().getMaximumDailyDose()); assertPropEquals("minimumDailyDose", getObject().getMinimumDailyDose()); assertPropEquals("units", getObject().getUnits()); assertPropEquals("combination", getObject().getCombination()); assertPropPresent("concept"); assertPropPresent("route"); assertPropPresent("dosageForm"); }
@Override public List<Map<String, Object>> simplify(List<Drug> drugs) { List<Map<String, Object>> simplified = new ArrayList<Map<String, Object>>(); Locale locale = Context.getLocale(); for (Drug drug : drugs) { Map<String, Object> item = new LinkedHashMap<String, Object>(); item.put("id", drug.getId()); item.put("name", drug.getName()); if (drug.getDosageForm() != null) { item.put("dosageForm", drug.getDosageForm().getName(locale).getName()); } item.put("combination", drug.getCombination()); if (drug.getConcept() != null) { item.put("concept", drug.getConcept().getName(locale).getName()); } simplified.add(item); } return simplified; } }
/** * Ensures that unique drugs are returned in situations where more than one searched fields * match e.g drug name and linked concept name match the search phrase * * @see ConceptService#getDrugs(String, java.util.Locale, boolean, boolean) */ @Test public void getDrugs_shouldReturnUniqueDrugs() { //sanity check that drug.name and drug.concept.name will both match the search phrase Drug drug = conceptService.getDrug("ASPIRIN"); assertEquals(drug.getName().toLowerCase(), drug.getConcept().getName().getName().toLowerCase()); List<Drug> drugs = conceptService.getDrugs("Asp", null, false, false); assertEquals(1, drugs.size()); assertEquals(3, drugs.get(0).getDrugId().intValue()); }
/** * Gets the entries concept drug name in the form of CONCEPTNAME (Drug: DRUGNAME) * * @param locale * @return full drug name (with concept name appended) */ public String getFullName(Locale locale) { if (concept == null) { return getName(); } else { return getName() + " (" + concept.getName(locale).getName() + ")"; } }
/** * @see DrugsByNameComparator#compareDrugNamesIgnoringNumericals(Drug,Drug) */ @Test public void compareDrugNamesIgnoringNumericals_shouldReturnZeroIfNameForDrug1ComesBeforeThatOfDrug2() { Drug drug1 = new Drug(); drug1.setName("ABCD"); Drug drug2 = new Drug(); drug2.setName("abcd"); DrugsByNameComparator dComparator = new DrugsByNameComparator(); int actualValue = dComparator.compare(drug1, drug2); Assert.assertEquals(actualValue, 0); }
public void CRUDOperation(DBHandler db){ // Inserting Contacts Log.d("Insert: ", "Inserting .."); db.addDrug(new Drug("Chloroquine", "The bitter drug that is not slimy")); db.addDrug(new Drug("Artesunate", "The big drug..PS: I hate it so much")); // Reading all contacts Log.d("Reading: ", "Reading all contacts.."); drug = db.getAllDrugs(); for (Drug dg : drug) { String log = "Id: "+dg.getID()+" , Name: " + dg.getName() + " , Desc: " + dg.get_desc(); Log.d("Name: ", log); } }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService .getConceptMapType(1))); drug.setName("name"); drug.setStrength("strength"); drug.setRetireReason("retireReason"); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertFalse(errors.hasFieldErrors()); }
if (context.getExistingOrders().containsKey(drug.getConcept())) { existingOrder = drugOrder; if (drugWidget instanceof DropdownWidget){ drugWidget.setInitialValue(drugOrder.getDrug().getDrugId()); } else { if (((CheckboxWidget) drugWidget).getValue().equals(drugOrder.getDrug().getDrugId().toString())) ((CheckboxWidget) drugWidget).setInitialValue("CHECKED");
@Test public void shouldGetADrugByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); Drug drug = service.getDrugByUuid(getUuid()); Assert.assertNotNull(result); Assert.assertEquals(drug.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(drug.getName(), PropertyUtils.getProperty(result, "name")); }
@Override public void setInitialValue(Object initialValue) { if (initialValue instanceof Drug) { Drug asDrug = (Drug) initialValue; this.initialValue = new Option(asDrug.getName(), "Drug:" + asDrug.getId(), true); } else if (initialValue instanceof Concept) { Concept asConcept = (Concept) initialValue; this.initialValue = new Option((asConcept.getName().getName()), asConcept.getConceptId().toString(), true); } else { this.initialValue = (Option) initialValue; } }
ConceptAnswer answer = iterator.next(); String conceptUuid = answer.getConcept().getUuid(); String drugUuid = (answer.getAnswerDrug() != null) ? answer.getAnswerDrug().getUuid() : null; if (answerUuids.contains(conceptUuid)) { answerToAdd = new ConceptAnswer((Concept) obj); else answerToAdd = new ConceptAnswer(((Drug) obj).getConcept(), (Drug) obj);
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailIfConceptReferenceTermOnDrugReferenceMapIsNull() { Drug drug = new Drug(); drug.addDrugReferenceMap(new DrugReferenceMap()); Errors errors = new BindException(drug, "drug"); new DrugValidator().validate(drug, errors); Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptReferenceTerm")); }
/** * @see DrugValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldFailIfTheDrugObjectIsNull() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("The parameter obj should not be null and must be of type" + Drug.class); new DrugValidator().validate(null, new BindException(new Drug(), "drug")); }