use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class WorkflowCollectionEditor method setAsText.
/**
* Takes a "program_id:list" where program_id is the id of the program that this collection is
* for (or not present, if it's a new program) and list is a space-separated list of concept
* ids. This class is a bit of a hack, because I don't know a better way to do this. -DJ The
* purpose is to retire and un-retire workflows where possible rather than deleting and creating
* them.
*
* @should update workflows in program
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (StringUtils.hasText(text)) {
ConceptService cs = Context.getConceptService();
ProgramWorkflowService pws = Context.getProgramWorkflowService();
try {
int ind = text.indexOf(":");
String progIdStr = text.substring(0, ind);
text = text.substring(ind + 1);
if (program == null) {
// if a program wasn't passed in, try to look it up now
program = pws.getProgram(Integer.valueOf(progIdStr));
}
} catch (Exception ex) {
}
String[] conceptIds = text.split(" ");
Set<ProgramWorkflow> oldSet = program == null ? new HashSet<>() : program.getAllWorkflows();
Set<Integer> newConceptIds = new HashSet<>();
for (String id : conceptIds) {
if (id.trim().length() == 0) {
continue;
}
log.debug("trying " + id);
newConceptIds.add(Integer.valueOf(id.trim()));
}
// go through oldSet and see what we need to keep and what we need to unvoid
Set<Integer> alreadyDone = new HashSet<>();
for (ProgramWorkflow pw : oldSet) {
if (!newConceptIds.contains(pw.getConcept().getConceptId())) {
pw.setRetired(true);
} else if (newConceptIds.contains(pw.getConcept().getConceptId()) && pw.getRetired()) {
pw.setRetired(false);
}
alreadyDone.add(pw.getConcept().getConceptId());
}
// now add any new ones
newConceptIds.removeAll(alreadyDone);
for (Integer conceptId : newConceptIds) {
ProgramWorkflow pw = new ProgramWorkflow();
pw.setProgram(program);
pw.setConcept(cs.getConcept(conceptId));
oldSet.add(pw);
}
setValue(oldSet);
} else {
setValue(null);
}
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class ORUR01HandlerTest method processMessage_shouldNotCreateProblemListObservationWithConceptProposals.
/**
* Tests that a ConceptProposal row can be written by the processor
*
* @see ORUR01Handler#processMessage(Message)
*/
@Test
public void processMessage_shouldNotCreateProblemListObservationWithConceptProposals() throws Exception {
ObsService obsService = Context.getObsService();
ConceptService conceptService = Context.getConceptService();
EncounterService encService = Context.getEncounterService();
String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080630094800||ORU^R01|kgWdFt0SVwwClOfJm3pe|P|2.5|1||||||||15^AMRS.ELD.FORMID\r" + "PID|||3^^^^~d3811480^^^^||John3^Doe^||\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20080208|||||||V\r" + "ORC|RE||||||||20080208000000|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBR|1|||1284^PROBLEM LIST^99DCT\r" + "OBX|1|CWE|6042^PROBLEM ADDED^99DCT||PROPOSED^SEVERO DOLOR DE CABEZA^99DCT|||||||||20080208";
Message hl7message = parser.parse(hl7String);
router.processMessage(hl7message);
Patient patient = new Patient(3);
// check for any obs
assertEquals("There should not be any obs created for #3", 0, obsService.getObservationsByPerson(patient).size());
// check for a new encounter
assertEquals("There should be 1 new encounter created for #3", 1, encService.getEncountersByPatient(patient).size());
// check for the proposed concept
List<ConceptProposal> proposedConcepts = conceptService.getConceptProposals("SEVERO DOLOR DE CABEZA");
assertEquals("There should be a proposed concept by this name", 1, proposedConcepts.size());
assertEquals(encService.getEncountersByPatient(patient).get(0), proposedConcepts.get(0).getEncounter());
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class OrderFrequencyValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see OrderFrequencyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
ConceptService cs = Context.getConceptService();
Concept concept = new Concept();
ConceptName cn = new ConceptName("new name", Context.getLocale());
concept.setDatatype(cs.getConceptDatatype(1));
concept.setConceptClass(cs.getConceptClass(19));
concept.addName(cn);
concept.addDescription(new ConceptDescription("some description", null));
cs.saveConcept(concept);
OrderFrequency orderFrequency = new OrderFrequency();
orderFrequency.setConcept(concept);
orderFrequency.setRetireReason("retireReason");
Errors errors = new BindException(orderFrequency, "orderFrequency");
new OrderFrequencyValidator().validate(orderFrequency, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailIfDurationUnitsHasNoMappingToSNOMEDCTSource.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfDurationUnitsHasNoMappingToSNOMEDCTSource() {
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
ConceptService cs = Context.getConceptService();
order.setConcept(cs.getConcept(5497));
order.setPatient(patient);
order.setCareSetting(careSetting);
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDateActivated(encounter.getEncounterDatetime());
order.setOrderType(orderType);
order.setDosingType(FreeTextDosingInstructions.class);
order.setInstructions("None");
order.setDosingInstructions("Test Instruction");
order.setDuration(20);
order.setDurationUnits(cs.getConcept(28));
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
assertEquals("DrugOrder.error.durationUnitsNotMappedToSnomedCtDurationCode", errors.getFieldError("durationUnits").getCode());
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class ConceptAttributeTypeValidator method validate.
@Override
public void validate(Object obj, Errors errors) {
super.validate(obj, errors);
ConceptAttributeType conceptAttributeType = (ConceptAttributeType) obj;
ConceptService conceptService = Context.getConceptService();
if (conceptAttributeType.getName() != null && !conceptAttributeType.getName().isEmpty()) {
ConceptAttributeType attributeType = conceptService.getConceptAttributeTypeByName(conceptAttributeType.getName());
if (attributeType != null && !attributeType.getUuid().equals(conceptAttributeType.getUuid())) {
errors.rejectValue("name", "ConceptAttributeType.error.nameAlreadyInUse");
}
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "ConceptAttributeType.error.nameEmpty");
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "datatypeClassname", "preferredHandlerClassname", "retireReason");
}
Aggregations