/** * * Get the concept by id, the id can either be 1)an integer id like 5090 or 2)mapping type id * like "XYZ:HT" or 3)uuid like "a3e12268-74bf-11df-9768-17cfc9833272" * * @param Id * @return the concept if exist, else null * @should find a concept by its conceptId * @should find a concept by its mapping * @should find a concept by its uuid * @should return null otherwise */ public static Concept getConcept(String id) { Concept cpt = null; if (id != null) { try { // handle integer: id int conceptId = Integer.parseInt(id); cpt = Context.getConceptService().getConcept(conceptId); return cpt; } catch (Exception ex) { // do nothing } // handle mapping id: xyz:ht int index = id.indexOf(":"); if (index != -1) { String mappingCode = id.substring(0, index).trim(); String conceptCode = id.substring(index + 1, id.length()).trim(); cpt = Context.getConceptService().getConceptByMapping(conceptCode, mappingCode); return cpt; } // handle uuid id: "a3e1302b-74bf-11df-9768-17cfc9833272", if the id matches a uuid pattern if (Pattern.compile("\\w+-\\w+-\\w+-\\w+-\\w+").matcher(id).matches()) { cpt = Context.getConceptService().getConceptByUuid(id); return cpt; } } return cpt; }
/** @see {@link DrugOrderValidator#validate(Object,Errors)} */ @Test @Verifies( value = "should pass validation if all fields are correct", method = "validate(Object,Errors)") public void validate_shouldPassValidationIfAllFieldsAreCorrect() throws Exception { DrugOrder order = new DrugOrder(); Encounter encounter = new Encounter(); Patient patient = Context.getPatientService().getPatient(2); order.setConcept(Context.getConceptService().getConcept(88)); order.setOrderer(Context.getProviderService().getProvider(1)); order.setDosingType(DrugOrder.DosingType.FREE_TEXT); order.setInstructions("Instructions"); order.setDosingInstructions("Test Instruction"); order.setPatient(patient); encounter.setPatient(patient); order.setEncounter(encounter); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setStartDate(cal.getTime()); order.setAutoExpireDate(new Date()); order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order")); order.setDrug(Context.getConceptService().getDrug(3)); order.setCareSetting(Context.getOrderService().getCareSetting(1)); order.setQuantity(2.00); order.setQuantityUnits(Context.getConceptService().getConcept(51)); order.setNumRefills(10); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see RegimenManager#findDefinitions(String, org.openmrs.module.kenyaemr.regimen.RegimenOrder, * boolean) */ @Test public void findDefinitions_shouldFindDefinitionsForRegimen() { // Create regimen that matches the regimen2 definition exactly DrugOrder lamivudine = new DrugOrder(); lamivudine.setConcept(Context.getConceptService().getConcept(78643)); lamivudine.setDose(150d); lamivudine.setUnits("mg"); lamivudine.setFrequency("BD"); DrugOrder stavudine = new DrugOrder(); stavudine.setConcept(Context.getConceptService().getConcept(84309)); stavudine.setDose(30d); stavudine.setUnits("mg"); stavudine.setFrequency("OD"); RegimenOrder regimen = new RegimenOrder(new HashSet<DrugOrder>(Arrays.asList(lamivudine, stavudine))); // Test exact match List<RegimenDefinition> defsExact = regimenManager.findDefinitions("category1", regimen, true); Assert.assertEquals(1, defsExact.size()); Assert.assertEquals("regimen2", defsExact.get(0).getName()); // Test non-exact match List<RegimenDefinition> defsNonExact = regimenManager.findDefinitions("category1", regimen, false); Assert.assertEquals(2, defsNonExact.size()); Assert.assertEquals("regimen2", defsNonExact.get(0).getName()); Assert.assertEquals("regimen3", defsNonExact.get(1).getName()); }
/** * Gets a concept by an identifier (mapping or UUID) * * @param identifier the identifier * @return the concept * @throws org.openmrs.module.metadatadeploy.MissingMetadataException if the concept could not be * found */ public static Concept getConcept(String identifier) { Concept concept; if (identifier.contains(":")) { String[] tokens = identifier.split(":"); concept = Context.getConceptService().getConceptByMapping(tokens[1].trim(), tokens[0].trim()); } else { // Assume it's a UUID concept = Context.getConceptService().getConceptByUuid(identifier); } if (concept == null) { throw new MissingMetadataException(Concept.class, identifier); } // getConcept doesn't always return ConceptNumeric for numeric concepts if (concept.getDatatype().isNumeric() && !(concept instanceof ConceptNumeric)) { concept = Context.getConceptService().getConceptNumeric(concept.getId()); if (concept == null) { throw new MissingMetadataException(ConceptNumeric.class, identifier); } } return concept; }
/** * Sets the value of this obs to the specified valueBoolean if this obs has a boolean concept. * * @param valueBoolean the boolean value matching the boolean coded concept to set to */ public void setValueBoolean(Boolean valueBoolean) { if (valueBoolean != null && getConcept() != null && getConcept().getDatatype().isBoolean()) setValueCoded( valueBoolean.booleanValue() ? Context.getConceptService().getTrueConcept() : Context.getConceptService().getFalseConcept()); else if (valueBoolean == null) setValueCoded(null); }
@Test @Verifies( value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema") public void testVoidEncounterByHtmlFormSchema_shouldHandleDrugOrderCorrectly() throws Exception { executeDataSet( XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); Encounter e = new Encounter(); e.setPatient(Context.getPatientService().getPatient(2)); Date date = Context.getDateFormat().parse("01/02/2003"); e.setDateCreated(new Date()); e.setEncounterDatetime(date); e.setLocation(Context.getLocationService().getLocation(2)); e.setProvider(Context.getPersonService().getPerson(502)); TestUtil.addObs(e, 1, 5000, date); // a matching obs DrugOrder dor = new DrugOrder(); dor.setVoided(false); dor.setConcept(Context.getConceptService().getConcept(792)); dor.setCreator(Context.getUserService().getUser(1)); dor.setDateCreated(new Date()); dor.setDiscontinued(false); dor.setDrug(Context.getConceptService().getDrug(2)); dor.setOrderType(Context.getOrderService().getOrderType(1)); dor.setPatient(Context.getPatientService().getPatient(2)); dor.setStartDate(new Date()); e.addOrder(dor); Context.getEncounterService().saveEncounter(e); Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData( new TestUtil() .loadXmlFromFile( XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml")); HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, "test void reason"); // this is going to test out the voided state of the obs in the encounter after processing: // order was matched, so order was voided, and because that's the only thing in the encounter, // encounter was voided too. Assert.assertTrue(e.isVoided()); Assert.assertTrue(e.getVoidReason().equals("test void reason")); for (Order o : e.getOrders()) { Assert.assertTrue(o.isVoided()); Assert.assertTrue(o.getVoidReason().equals("test void reason")); } for (Obs o : e.getAllObs(true)) { Assert.assertTrue(o.getVoidReason().equals("test void reason")); } }
@Test @Verifies(value = "should delete encounter correctly", method = "voidEncounterByHtmlFormSchema") public void testVoidEncounterByHtmlFormSchema_shouldDeleteEncounter() throws Exception { executeDataSet( XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); Encounter e = new Encounter(); e.setPatient(Context.getPatientService().getPatient(2)); Date date = Context.getDateFormat().parse("01/02/2003"); e.setDateCreated(new Date()); e.setEncounterDatetime(date); e.setLocation(Context.getLocationService().getLocation(2)); e.setProvider(Context.getPersonService().getPerson(502)); TestUtil.addObs(e, 3, 5000, date); // adding an un-matched, voided Obs for (Obs o : e.getAllObs(true)) { o.setVoided(true); o.setVoidedBy(Context.getUserService().getUser(1)); o.setVoidReason("blah"); o.setDateVoided(new Date()); } // and adding a voided drug order DrugOrder dor = new DrugOrder(); dor.setVoided(false); dor.setConcept(Context.getConceptService().getConcept(792)); dor.setCreator(Context.getUserService().getUser(1)); dor.setDateCreated(new Date()); dor.setDiscontinued(false); dor.setDrug(Context.getConceptService().getDrug(2)); dor.setOrderType(Context.getOrderService().getOrderType(1)); dor.setPatient(Context.getPatientService().getPatient(2)); dor.setVoided(true); dor.setVoidedBy(Context.getUserService().getUser(1)); dor.setVoidReason("blah"); dor.setDateVoided(new Date()); dor.setStartDate(new Date()); e.addOrder(dor); Context.getEncounterService().saveEncounter(e); Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData( new TestUtil() .loadXmlFromFile( XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml")); HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null); // encounter had no non-voided objects, should be voided Assert.assertTrue(e.isVoided()); }
@Test @Verifies( value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema") public void testVoidEncounterByHtmlFormSchema_shouldHandleDrugOrderAndObsCorrectly() throws Exception { executeDataSet( XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); Encounter e = new Encounter(); e.setPatient(Context.getPatientService().getPatient(2)); Date date = Context.getDateFormat().parse("01/02/2003"); e.setDateCreated(new Date()); e.setEncounterDatetime(date); e.setLocation(Context.getLocationService().getLocation(2)); e.setProvider(Context.getPersonService().getPerson(502)); TestUtil.addObs(e, 3, 5000, date); // adding an un-matched Obs DrugOrder dor = new DrugOrder(); dor.setVoided(false); dor.setConcept(Context.getConceptService().getConcept(792)); dor.setCreator(Context.getUserService().getUser(1)); dor.setDateCreated(new Date()); dor.setDiscontinued(false); dor.setDrug(Context.getConceptService().getDrug(2)); dor.setOrderType(Context.getOrderService().getOrderType(1)); dor.setPatient(Context.getPatientService().getPatient(2)); dor.setStartDate(new Date()); e.addOrder(dor); Context.getEncounterService().saveEncounter(e); Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData( new TestUtil() .loadXmlFromFile( XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml")); HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null); // order was matched, obs was not, so order should be voided, obs not, encounter not. Assert.assertTrue(!e.isVoided()); for (Order o : e.getOrders()) { Assert.assertTrue(o.isVoided()); } for (Obs o : e.getObs()) { Assert.assertTrue(!o.isVoided()); } }
/** * Processes requests to unretire a concept map type * * @param request the {@link WebRequest} object * @param conceptMapType the concept map type object to unretire * @return the url to redirect to */ @RequestMapping(method = RequestMethod.POST, value = "/admin/concepts/unretireConceptMapType") public String unretireConceptMapType( WebRequest request, @ModelAttribute(value = "conceptMapType") ConceptMapType conceptMapType) { try { Context.getConceptService().unretireConceptMapType(conceptMapType); if (log.isDebugEnabled()) { log.debug("Unretired concept map type with id: " + conceptMapType.getId()); } request.setAttribute( WebConstants.OPENMRS_MSG_ATTR, Context.getMessageSourceService().getMessage("ConceptMapType.unretired"), WebRequest.SCOPE_SESSION); return "redirect:" + CONCEPT_MAP_TYPE_LIST_URL + ".list"; } catch (APIException e) { log.error("Error occurred while attempting to unretire concept map type", e); request.setAttribute( WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("ConceptMapType.unretire.error"), WebRequest.SCOPE_SESSION); } // an error occurred return CONCEPT_MAP_TYPE_FORM; }
/** @see Moh731CohortLibrary#revisitsArt() */ @Test public void revisitsArt() throws Exception { EncounterType hivConsult = MetadataUtils.getEncounterType(HivMetadata._EncounterType.HIV_CONSULTATION); Concept stavudine = Context.getConceptService().getConcept(84309); // Start patient #6 this month and give them a visit in the reporting period + 2 months TestUtils.saveDrugOrder(TestUtils.getPatient(6), stavudine, TestUtils.date(2012, 6, 10), null); TestUtils.saveEncounter(TestUtils.getPatient(6), hivConsult, TestUtils.date(2012, 6, 20)); // Start patient #7 in previous month and give them a visit in the reporting period + 2 months TestUtils.saveDrugOrder(TestUtils.getPatient(7), stavudine, TestUtils.date(2012, 5, 10), null); TestUtils.saveEncounter(TestUtils.getPatient(7), hivConsult, TestUtils.date(2012, 6, 20)); // Start patient #8 and give them visit outside of reporting period + 2 month window TestUtils.saveDrugOrder(TestUtils.getPatient(8), stavudine, TestUtils.date(2012, 1, 10), null); TestUtils.saveEncounter(TestUtils.getPatient(8), hivConsult, TestUtils.date(2012, 1, 20)); CohortDefinition cd = moh731Cohorts.revisitsArt(); context.addParameterValue("fromDate", PERIOD_START); context.addParameterValue("toDate", PERIOD_END); EvaluatedCohort evaluated = Context.getService(CohortDefinitionService.class).evaluate(cd, context); ReportingTestUtils.assertCohortEquals(Arrays.asList(7), evaluated); }
/** * Processes requests to unretire concept reference terms * * @param request the {@link WebRequest} object * @param conceptReferenceTermModel the concept reference term model object for the term to * unretire * @param retireReason the reason why the concept reference term is being unretired * @return the url to redirect to */ @RequestMapping( method = RequestMethod.POST, value = "/admin/concepts/unretireConceptReferenceTerm") public String unretireConceptReferenceTerm( WebRequest request, @ModelAttribute(value = "conceptReferenceTermModel") ConceptReferenceTermModel conceptReferenceTermModel) { try { ConceptReferenceTerm conceptReferenceTerm = conceptReferenceTermModel.getConceptReferenceTerm(); Context.getConceptService().unretireConceptReferenceTerm(conceptReferenceTerm); if (log.isDebugEnabled()) { log.debug("Unretired concept reference term with id: " + conceptReferenceTerm.getId()); } request.setAttribute( WebConstants.OPENMRS_MSG_ATTR, Context.getMessageSourceService().getMessage("ConceptReferenceTerm.unretired"), WebRequest.SCOPE_SESSION); return "redirect:" + CONCEPT_REFERENCE_TERM_FORM_URL + ".form?conceptReferenceTermId=" + conceptReferenceTerm.getConceptReferenceTermId(); } catch (APIException e) { log.error("Error occurred while unretiring concept reference term", e); request.setAttribute( WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("ConceptReferenceTerm.unretire.error"), WebRequest.SCOPE_SESSION); } // an error occurred, show the form return CONCEPT_REFERENCE_TERM_FORM; }
/** * Processes requests to purge a concept reference term * * @param request the {@link WebRequest} object * @param conceptReferenceTermModel * @return the url to forward to */ @RequestMapping(method = RequestMethod.POST, value = "/admin/concepts/purgeConceptReferenceTerm") public String purgeTerm( WebRequest request, @ModelAttribute(value = "conceptReferenceTermModel") ConceptReferenceTermModel conceptReferenceTermModel) { Integer id = conceptReferenceTermModel.getConceptReferenceTerm().getId(); try { Context.getConceptService() .purgeConceptReferenceTerm(conceptReferenceTermModel.getConceptReferenceTerm()); if (log.isDebugEnabled()) { log.debug("Purged concept reference term with id: " + id); } request.setAttribute( WebConstants.OPENMRS_MSG_ATTR, Context.getMessageSourceService().getMessage("ConceptReferenceTerm.purged"), WebRequest.SCOPE_SESSION); return "redirect:" + FIND_CONCEPT_REFERENCE_TERM_URL; } catch (APIException e) { log.warn("Error occurred while attempting to purge concept reference term", e); request.setAttribute( WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("ConceptReferenceTerm.purge.error"), WebRequest.SCOPE_SESSION); } // send the user back to form return "redirect:" + CONCEPT_REFERENCE_TERM_FORM_URL + ".form?conceptReferenceTermId=" + id; }
/** * Processes requests to save/update a concept map type * * @param request the {@link WebRequest} object * @param conceptMapType the concept map type object to save/update * @param result the {@link BindingResult} object * @return the url to redirect to */ @RequestMapping(method = RequestMethod.POST, value = CONCEPT_MAP_TYPE_FORM_URL) public String saveConceptMapType( WebRequest request, @ModelAttribute("conceptMapType") ConceptMapType conceptMapType, BindingResult result) { new ConceptMapTypeValidator().validate(conceptMapType, result); if (!result.hasErrors()) { try { Context.getConceptService().saveConceptMapType(conceptMapType); if (log.isDebugEnabled()) { log.debug("Saved concept map type: " + conceptMapType.toString()); } request.setAttribute( WebConstants.OPENMRS_MSG_ATTR, "ConceptMapType.saved", WebRequest.SCOPE_SESSION); return "redirect:" + CONCEPT_MAP_TYPE_LIST_URL + ".list"; } catch (APIException e) { log.error("Error while saving concept map type(s)", e); request.setAttribute( WebConstants.OPENMRS_ERROR_ATTR, "ConceptMapType.save.error", WebRequest.SCOPE_SESSION); } } // there was an error return CONCEPT_MAP_TYPE_FORM; }
/** * Checks that a given concept map type object is valid. * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail if the concept map type object is null * @should fail if the name is null * @should fail if the name is an empty string * @should fail if the name is a white space character * @should fail if the concept map type name is a duplicate * @should pass if the name is unique amongst all concept map type names * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ public void validate(Object obj, Errors errors) { if (obj == null || !(obj instanceof ConceptMapType)) { throw new IllegalArgumentException( "The parameter obj should not be null and must be of type" + ConceptMapType.class); } ConceptMapType conceptMapType = (ConceptMapType) obj; String name = conceptMapType.getName(); if (!StringUtils.hasText(name)) { errors.rejectValue( "name", "ConceptMapType.error.nameRequired", "The name property is required for a concept map type"); return; } name = name.trim(); ConceptMapType duplicate = Context.getConceptService().getConceptMapTypeByName(name); if (duplicate != null && !OpenmrsUtil.nullSafeEquals(duplicate.getUuid(), conceptMapType.getUuid())) { errors.rejectValue( "name", "ConceptMapType.duplicate.name", "Duplicate concept map type name: " + name); } ValidateUtil.validateFieldLengths( errors, obj.getClass(), "name", "description", "retireReason"); }
/** * Coerces a value to a Boolean representation * * @return Boolean representation of the obs value * @should return true for value_numeric concepts if value is 1 * @should return false for value_numeric concepts if value is 0 * @should return null for value_numeric concepts if value is neither 1 nor 0 */ public Boolean getValueAsBoolean() { if (getValueCoded() != null) { if (getValueCoded().equals(Context.getConceptService().getTrueConcept())) { return Boolean.TRUE; } else if (getValueCoded().equals(Context.getConceptService().getFalseConcept())) { return Boolean.FALSE; } } else if (getValueNumeric() != null) { if (getValueNumeric() == 1) return Boolean.TRUE; else if (getValueNumeric() == 0) return Boolean.FALSE; } // returning null is preferred to defaulting to false to support validation of user input is // from a form return null; }
/** @see {@link OrderValidator#validate(Object,Errors)} */ @Test @Verifies( value = "should pass validation if field lengths are correct", method = "validate(Object,Errors)") public void validate_shouldPassValidationIfFieldLengthsAreCorrect() throws Exception { Order order = new Order(); Encounter encounter = new Encounter(); order.setConcept(Context.getConceptService().getConcept(88)); order.setOrderer(Context.getProviderService().getProvider(1)); Patient patient = Context.getPatientService().getPatient(2); encounter.setPatient(patient); order.setPatient(patient); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setDateActivated(cal.getTime()); order.setAutoExpireDate(new Date()); order.setCareSetting(new CareSetting()); order.setEncounter(encounter); order.setUrgency(Order.Urgency.ROUTINE); order.setAction(Order.Action.NEW); order.setOrderReasonNonCoded("orderReasonNonCoded"); order.setAccessionNumber("accessionNumber"); order.setCommentToFulfiller("commentToFulfiller"); order.setVoidReason("voidReason"); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertFalse(errors.hasErrors()); }
/** * Processes requests to retire a concept map type * * @param request the {@link WebRequest} object * @param conceptMapType the concept map type object to retire * @param retireReason the reason why the concept map type is getting retired * @return the url to redirect to */ @RequestMapping(method = RequestMethod.POST, value = "/admin/concepts/retireConceptMapType") public String retireConceptMapType( WebRequest request, @ModelAttribute(value = "conceptMapType") ConceptMapType conceptMapType, @RequestParam(required = false, value = "retireReason") String retireReason) { if (!StringUtils.hasText(retireReason)) { retireReason = Context.getMessageSourceService().getMessage("general.default.retireReason"); } try { Context.getConceptService().retireConceptMapType(conceptMapType, retireReason); if (log.isDebugEnabled()) { log.debug("Retired concept map type with id: " + conceptMapType.getId()); } request.setAttribute( WebConstants.OPENMRS_MSG_ATTR, Context.getMessageSourceService().getMessage("ConceptMapType.retired"), WebRequest.SCOPE_SESSION); return "redirect:" + CONCEPT_MAP_TYPE_LIST_URL + ".list"; } catch (APIException e) { log.error("Error occurred while attempting to retire concept map type", e); request.setAttribute( WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("ConceptMapType.retire.error"), WebRequest.SCOPE_SESSION); } // an error occurred return CONCEPT_MAP_TYPE_FORM; }
public void saveAndTransferFileComplexObs() { try { List<Encounter> encounters = Context.getEncounterService().getEncounters(null, null, null, null, null, null, true); Encounter lastEncounter = encounters.get(encounters.size() - 1); Person patient = lastEncounter.getPatient(); ConceptComplex conceptComplex = Context.getConceptService().getConceptComplex(17); Location location = Context.getLocationService().getDefaultLocation(); Obs obs = new Obs(patient, conceptComplex, new Date(), location); String mergedUrl = tempFile.getCanonicalPath(); InputStream out1 = new FileInputStream(new File(mergedUrl)); ComplexData complexData = new ComplexData(tempFile.getName(), out1); obs.setComplexData(complexData); obs.setEncounter(lastEncounter); Context.getObsService().saveObs(obs, null); tempFile.delete(); } catch (Exception e) { log.error(e); } }
/** @see {@link OrderValidator#validate(Object,Errors)} */ @Test @Verifies( value = "should pass validation if all fields are correct", method = "validate(Object,Errors)") public void validate_shouldPassValidationIfAllFieldsAreCorrect() throws Exception { Order order = new DrugOrder(); Encounter encounter = new Encounter(); order.setConcept(Context.getConceptService().getConcept(88)); order.setOrderer(Context.getProviderService().getProvider(1)); Patient patient = Context.getPatientService().getPatient(2); encounter.setPatient(patient); order.setPatient(patient); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1); order.setDateActivated(cal.getTime()); order.setAutoExpireDate(new Date()); order.setCareSetting(new CareSetting()); order.setEncounter(encounter); order.setUrgency(Order.Urgency.ROUTINE); order.setAction(Order.Action.NEW); order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order")); Errors errors = new BindException(order, "order"); new OrderValidator().validate(order, errors); Assert.assertFalse(errors.hasErrors()); }
@Test @Verifies( value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema") public void testVoidEncounterByHtmlFormSchema_shouldReturnEncounterVoided() throws Exception { executeDataSet( XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET)); Encounter e = new Encounter(); e.setPatient(Context.getPatientService().getPatient(2)); Date date = Context.getDateFormat().parse("01/02/2003"); e.setDateCreated(new Date()); e.setEncounterDatetime(date); e.setLocation(Context.getLocationService().getLocation(2)); e.setProvider(Context.getPersonService().getPerson(502)); // add a bunch of obs... TestUtil.addObs(e, 2474, Context.getConceptService().getConcept(656), date); // matches Form form = new Form(); HtmlForm htmlform = new HtmlForm(); htmlform.setForm(form); form.setEncounterType(new EncounterType()); htmlform.setDateChanged(new Date()); htmlform.setXmlData( new TestUtil() .loadXmlFromFile( XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml")); HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null); // this is going to test out the voided state of the obs in the encounter after processing: Assert.assertTrue(e.isVoided()); }
/** * Processes requests to retire concept reference terms * * @param request the {@link WebRequest} object * @param conceptReferenceTermModel the concept reference term model for the term to retire * @param retireReason the reason why the concept reference term is being retired * @return the url to redirect to */ @RequestMapping(method = RequestMethod.POST, value = "/admin/concepts/retireConceptReferenceTerm") public String retireConceptReferenceTerm( WebRequest request, @ModelAttribute(value = "conceptReferenceTermModel") ConceptReferenceTermModel conceptReferenceTermModel, @RequestParam(required = false, value = "retireReason") String retireReason) { if (!StringUtils.hasText(retireReason)) { retireReason = Context.getMessageSourceService().getMessage("general.default.retireReason"); } try { ConceptReferenceTerm conceptReferenceTerm = conceptReferenceTermModel.getConceptReferenceTerm(); Context.getConceptService().retireConceptReferenceTerm(conceptReferenceTerm, retireReason); if (log.isDebugEnabled()) { log.debug("Retired concept reference term with id: " + conceptReferenceTerm.getId()); } request.setAttribute( WebConstants.OPENMRS_MSG_ATTR, Context.getMessageSourceService().getMessage("ConceptReferenceTerm.retired"), WebRequest.SCOPE_SESSION); return "redirect:" + FIND_CONCEPT_REFERENCE_TERM_URL; } catch (APIException e) { log.error("Error occurred while retiring concept reference term", e); request.setAttribute( WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("ConceptReferenceTerm.retire.error"), WebRequest.SCOPE_SESSION); } // an error occurred return CONCEPT_REFERENCE_TERM_FORM; }
/** * Gets the specified concept (by mapping or UUID) * * @param identifier the mapping or UUID * @return the concept * @throws IllegalArgumentException if no such concept could be found */ public static Concept getConcept(String identifier) { Concept concept = null; if (identifier.contains(":")) { String[] tokens = identifier.split(":"); concept = Context.getConceptService().getConceptByMapping(tokens[1].trim(), tokens[0].trim()); } else { // Assume its a UUID concept = Context.getConceptService().getConceptByUuid(identifier); } if (concept == null) { throw new IllegalArgumentException("No concept with identifier '" + identifier + "'"); } return concept; }
@PropertyGetter("concept") public Object getConcept(PersonAttributeType delegate) { if (OpenmrsUtil.nullSafeEquals(delegate.getFormat(), Concept.class.getCanonicalName())) { Concept concept = Context.getConceptService().getConcept(delegate.getForeignKey()); return ConversionUtil.convertToRepresentation(concept, Representation.FULL); } return null; }
private void assertMappedCorrectly() { Concept concept = Context.getConceptService().getConceptByUuid("23423a2982236623"); if (concept.isNumeric()) { Assert.fail(); } Assert.assertEquals("N/A", concept.getDatatype().getName()); }
/** * Processes requests to display a list of the current concept map types in the database * * @param model the {@link ModelMap} object * @param request the {@link WebRequest} object */ @RequestMapping(method = RequestMethod.GET, value = CONCEPT_MAP_TYPE_LIST_URL) public void showConceptMapTypeList(ModelMap model, WebRequest request) { ConceptService conceptService = Context.getConceptService(); List<ConceptMapType> conceptMapTypeList = null; conceptMapTypeList = conceptService.getConceptMapTypes(true, true); model.addAttribute("conceptMapTypeList", conceptMapTypeList); }
/** * Auto generated method comment * * @param conceptId * @return */ public static String getConceptName(Integer conceptId) { try { if (null == conceptId) return "-"; Concept concept = Context.getConceptService().getConcept(conceptId); return (concept != null) ? concept.getDisplayString() : "-"; } catch (Exception e) { log.info(e.getMessage()); return "-"; } }
@SuppressWarnings("unchecked") @ModelAttribute("referenceTermMappingsToThisTerm") public List<ConceptReferenceTermMap> getConceptMappingsToThisTerm( @ModelAttribute ConceptReferenceTerm conceptReferenceTerm) { if (conceptReferenceTerm.getConceptReferenceTermId() != null) { return Context.getConceptService().getReferenceTermMappingsTo(conceptReferenceTerm); } return ListUtils.EMPTY_LIST; }
/** @see {@link DrugOrderValidator#validate(Object,Errors)} */ @Test @Verifies( value = "should fail validation if drug concept is different from order concept", method = "validate(Object,Errors)") public void validate_shouldFailValidationIfDrugConceptIsDifferentFromOrderConcept() throws Exception { DrugOrder order = new DrugOrder(); Drug drug = Context.getConceptService().getDrug(3); Concept concept = Context.getConceptService().getConcept(792); order.setDrug(drug); order.setConcept(concept); // the actual concept which matches with drug is "88" Assert.assertNotEquals(drug.getConcept(), concept); Errors errors = new BindException(order, "order"); new DrugOrderValidator().validate(order, errors); Assert.assertTrue(errors.hasFieldErrors("concept")); Assert.assertTrue(errors.hasFieldErrors("drug")); }
/** * Auto generated method comment * * @param conceptId * @return */ public static String checkIfConceptExistByIdAsString(String conceptId) { String res = ""; try { if (conceptId.trim().compareTo("") == 0) return res; Concept concept = Context.getConceptService().getConcept(Integer.parseInt(conceptId)); res = (concept != null) ? "" + concept.getConceptId() : ""; } catch (Exception e) { log.info(e.getMessage()); } return res; }
/** * Auto generated method comment * * @param conceptId * @return */ public static String getConceptNameByIdAsString(String conceptId) { String res = "-"; try { if (conceptId.trim().compareTo("") == 0) return "-"; Concept concept = Context.getConceptService().getConcept(Integer.parseInt(conceptId)); res = (concept != null) ? concept.getDisplayString() : "-"; } catch (Exception e) { log.info(e.getMessage()); } return res; }