use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorrect.
/**
* @see FormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorrect() {
Form form = new Form();
form.setName("test");
form.setVersion("1.0");
Errors errors = new BindException(form, "form");
new FormValidator().validate(form, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class ORUR01Handler method createEncounter.
/**
* This method does not call the database to create the encounter row. The encounter is only
* created after all obs have been attached to it Creates an encounter pojo to be attached
* later. This method does not create an encounterId
*
* @param msh
* @param patient
* @param pv1
* @param orc
* @return
* @throws HL7Exception
*/
private Encounter createEncounter(MSH msh, Patient patient, PV1 pv1, ORC orc) throws HL7Exception {
// the encounter we will return
Encounter encounter;
// look for the encounter id in PV1-19
CX visitNumber = pv1.getVisitNumber();
Integer encounterId = null;
try {
encounterId = Integer.valueOf(visitNumber.getIDNumber().getValue());
} catch (NumberFormatException e) {
// pass
}
// the database
if (encounterId != null) {
encounter = Context.getEncounterService().getEncounter(encounterId);
} else {
// if no encounter_id was passed in, this is a new
// encounter, create the object
encounter = new Encounter();
Date encounterDate = getEncounterDate(pv1);
Provider provider = getProvider(pv1);
Location location = getLocation(pv1);
Form form = getForm(msh);
EncounterType encounterType = getEncounterType(msh, form);
User enterer = getEnterer(orc);
// Date dateEntered = getDateEntered(orc); // ignore this since we have no place in the data model to store it
encounter.setEncounterDatetime(encounterDate);
if (unknownRole == null) {
unknownRole = Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
}
encounter.setProvider(unknownRole, provider);
encounter.setPatient(patient);
encounter.setLocation(location);
encounter.setForm(form);
encounter.setEncounterType(encounterType);
encounter.setCreator(enterer);
encounter.setDateCreated(new Date());
}
return encounter;
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class ORUR01Handler method getForm.
/**
* needs to find a Form based on information in MSH-21. example: 16^AMRS.ELD.FORMID
*
* @param msh
* @return
* @should pass if return value is null when uuid and id is null
* @should pass if return value is not null when uuid or id is not null
* @throws HL7Exception
*/
public Form getForm(MSH msh) throws HL7Exception {
String uuid = null;
String id = null;
for (EI identifier : msh.getMessageProfileIdentifier()) {
if (identifier != null && identifier.getNamespaceID() != null) {
String identifierType = identifier.getNamespaceID().getValue();
if (OpenmrsUtil.nullSafeEquals(identifierType, HL7Constants.HL7_FORM_UUID)) {
uuid = identifier.getEntityIdentifier().getValue();
} else if (OpenmrsUtil.nullSafeEquals(identifierType, HL7Constants.HL7_FORM_ID)) {
id = identifier.getEntityIdentifier().getValue();
} else {
log.warn("Form identifier type of " + identifierType + " unknown to ORU R01 processor.");
}
}
}
Form form = null;
if (uuid == null && id == null) {
return form;
}
// prefer uuid over id
if (uuid != null) {
form = Context.getFormService().getFormByUuid(uuid);
}
// if uuid did not work ...
if (id != null) {
try {
Integer formId = Integer.parseInt(id);
form = Context.getFormService().getForm(formId);
} catch (NumberFormatException e) {
throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.parseFormId"), e);
}
}
return form;
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class ORUR01HandlerTest method processMessage_shouldUnderstandFormUuidIfPresent.
/**
* @see ORUR01Handler#processMessage(Message)
*/
@Test
public void processMessage_shouldUnderstandFormUuidIfPresent() 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||||||||d9218f76-6c39-45f4-8efa-4c5c6c199f50^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("d9218f76-6c39-45f4-8efa-4c5c6c199f50", form.getUuid());
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class ORUR01HandlerTest method getForm_shouldPassIfReturnValueIsNullWhenUuidAndIdIsNull.
/**
* @see ORUR01Handler#getForm(MSH)
*/
@Test
public void getForm_shouldPassIfReturnValueIsNullWhenUuidAndIdIsNull() throws Exception {
String hl7String = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20090728170332||ORU^R01|gu99yBh4loLX2mh9cHaV|P|2.5|1||||||||\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.assertNull(form);
}
Aggregations