Search in sources :

Example 26 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldPreferFormUuidOverIdIfBothArePresent.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldPreferFormUuidOverIdIfBothArePresent() throws Exception {
    // save original encounter count
    List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(new Patient(3));
    Integer originalEncounters = encounters.size();
    // process message
    String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||4^AMRS.ELD.FORMID~c156e1a8-6731-4ebd-89ff-d0d1c45eb004^AMRS.ELD.FORMUUID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714";
    Message hl7message = parser.parse(hl7String);
    router.processMessage(hl7message);
    // make sure an encounter was added
    encounters = Context.getEncounterService().getEncountersByPatient(new Patient(3));
    Assert.assertEquals(originalEncounters + 1, encounters.size());
    // get last encounter
    Encounter enc = encounters.get(encounters.size() - 1);
    // check the form uuid
    Form form = enc.getForm();
    Assert.assertEquals("c156e1a8-6731-4ebd-89ff-d0d1c45eb004", form.getUuid());
}
Also used : Message(ca.uhn.hl7v2.model.Message) Form(org.openmrs.Form) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class ORUR01HandlerTest method getForm_shouldPassIfReturnValueIsNotNullWhenUuidOrIdIsNotNull.

/**
 * @see ORUR01Handler#getForm(MSH)
 */
@Test
public void getForm_shouldPassIfReturnValueIsNotNullWhenUuidOrIdIsNotNull() throws Exception {
    String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||Beren^John^Bondo||\r" + "NK1|1|Jones^Jane^Lee^^RN|3A^Parent^99REL||||||||||||F|19751016|||||||||||||||||2^^^L^PI\r" + "PV1||O|1^Unknown||||1^Super User (admin)|||||||||||||||||||||||||||||||||||||20090714|||||||V\r" + "ORC|RE||||||||20090728165937|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|5497^CD4 COUNT^99DCT||123|||||||||20090714\r" + "OBR|3|||23^FOOD CONSTRUCT^99DCT\r" + "OBX|1|CWE|21^FOOD ASSISTANCE FOR ENTIRE FAMILY^99DCT||22^UNKNOWN^99DCT^2471^UNKNOWN^99NAM|||||||||20090714";
    ORUR01Handler oruHandler = new ORUR01Handler();
    Message hl7message = parser.parse(hl7String);
    ORU_R01 oru = (ORU_R01) hl7message;
    ca.uhn.hl7v2.model.v25.segment.MSH msh = oru.getMSH();
    Form form = oruHandler.getForm(msh);
    Assert.assertNotNull(form);
}
Also used : Message(ca.uhn.hl7v2.model.Message) ORU_R01(ca.uhn.hl7v2.model.v25.message.ORU_R01) Form(org.openmrs.Form) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 28 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method getFormField_shouldIgnoreFormFieldsPassedToIgnoreFormFields.

/**
 * @see FormService#getFormField(Form,Concept,Collection<QFormField;>,null)
 */
@Test
public void getFormField_shouldIgnoreFormFieldsPassedToIgnoreFormFields() {
    executeDataSet(INITIAL_FIELDS_XML);
    executeDataSet("org/openmrs/api/include/FormServiceTest-formFields.xml");
    FormField ff = Context.getFormService().getFormField(new Form(1), new Concept(1), null, false);
    // sanity check
    assertNotNull(ff);
    // test that the first formfield is ignored when a second fetch
    // is done on the same form and same concept
    List<FormField> ignoreFormFields = new ArrayList<>();
    ignoreFormFields.add(ff);
    FormField ff2 = Context.getFormService().getFormField(new Form(1), new Concept(1), ignoreFormFields, false);
    assertNotNull(ff2);
    assertNotSame(ff, ff2);
}
Also used : Concept(org.openmrs.Concept) Form(org.openmrs.Form) ArrayList(java.util.ArrayList) FormField(org.openmrs.FormField) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 29 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method purgeFormResource_shouldDeleteAFormResource.

/**
 * @throws ParseException
 * @see FormService#purgeFormResource(Form,String,String)
 */
@Test
public void purgeFormResource_shouldDeleteAFormResource() throws ParseException {
    // save an original resource
    Form form = Context.getFormService().getForm(1);
    String name = "Start Date";
    FormResource resource = new FormResource();
    resource.setForm(form);
    resource.setName(name);
    resource.setDatatypeClassname("org.openmrs.customdatatype.datatype.DateDatatype");
    Date previous = new SimpleDateFormat("yyyy-MM-dd").parse("2011-10-16");
    resource.setValue(previous);
    resource = Context.getFormService().saveFormResource(resource);
    Integer resourceId = resource.getFormResourceId();
    // clear the session
    Context.clearSession();
    // find and delete the resource
    resource = Context.getFormService().getFormResource(resourceId);
    Context.getFormService().purgeFormResource(resource);
    // clear the session
    Context.flushSession();
    // try to find the resource
    resource = Context.getFormService().getFormResource(resourceId);
    Assert.assertNull(resource);
}
Also used : Form(org.openmrs.Form) FormResource(org.openmrs.FormResource) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 30 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method purgeForm_shouldDeleteGivenFormSuccessfully.

/**
 * @see FormService#purgeForm(Form)
 */
@Test
public void purgeForm_shouldDeleteGivenFormSuccessfully() {
    FormService fs = Context.getFormService();
    createFormsLockedGPAndSetValue("false");
    Form form = fs.getForm(1);
    fs.purgeForm(form);
    assertNull(fs.getForm(1));
}
Also used : Form(org.openmrs.Form) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Form (org.openmrs.Form)45 Test (org.junit.Test)37 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)37 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Date (java.util.Date)7 Encounter (org.openmrs.Encounter)7 FormField (org.openmrs.FormField)6 FormResource (org.openmrs.FormResource)6 Message (ca.uhn.hl7v2.model.Message)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ArrayList (java.util.ArrayList)5 Patient (org.openmrs.Patient)3 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)2 HashSet (java.util.HashSet)2 Concept (org.openmrs.Concept)2 Field (org.openmrs.Field)2 Location (org.openmrs.Location)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1