Search in sources :

Example 16 with ConceptService

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);
    }
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) ConceptService(org.openmrs.api.ConceptService) HashSet(java.util.HashSet)

Example 17 with ConceptService

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());
}
Also used : Message(ca.uhn.hl7v2.model.Message) ConceptProposal(org.openmrs.ConceptProposal) Patient(org.openmrs.Patient) ObsService(org.openmrs.api.ObsService) ConceptService(org.openmrs.api.ConceptService) EncounterService(org.openmrs.api.EncounterService) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 18 with ConceptService

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());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) ConceptName(org.openmrs.ConceptName) BindException(org.springframework.validation.BindException) ConceptDescription(org.openmrs.ConceptDescription) ConceptService(org.openmrs.api.ConceptService) OrderFrequency(org.openmrs.OrderFrequency) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 19 with ConceptService

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());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) ConceptService(org.openmrs.api.ConceptService) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 20 with ConceptService

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");
}
Also used : ConceptAttributeType(org.openmrs.ConceptAttributeType) ConceptService(org.openmrs.api.ConceptService)

Aggregations

ConceptService (org.openmrs.api.ConceptService)21 Test (org.junit.Test)11 Concept (org.openmrs.Concept)11 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)11 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)4 ConceptName (org.openmrs.ConceptName)4 Encounter (org.openmrs.Encounter)4 Patient (org.openmrs.Patient)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 CareSetting (org.openmrs.CareSetting)3 ConceptDescription (org.openmrs.ConceptDescription)3 OrderFrequency (org.openmrs.OrderFrequency)3 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 Date (java.util.Date)2 StringTokenizer (java.util.StringTokenizer)2