use of org.openmrs.Form in project openmrs-module-mirebalais by PIH.
the class PatientPageController method controller.
public void controller(@RequestParam("patientId") Patient patient, UiUtils ui, EmrContext emrContext, PageModel model, @SpringBean("formService") FormService formService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
patientDomainWrapper.setPatient(patient);
SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.message("mirebalais.outpatientVitals.title"), "link", ui.pageLink("coreapps", "findpatient/findPatient", Collections.singletonMap("app", (Object) "mirebalais.outpatientVitals")));
SimpleObject patientPageBreadcrumb = SimpleObject.create("label", patient.getFamilyName() + ", " + patient.getGivenName(), "link", ui.thisUrlWithContextPath());
Form outpatientVitalsForm = formService.getFormByUuid("68728aa6-4985-11e2-8815-657001b58a90");
List<Encounter> existingEncounters = new ArrayList<Encounter>();
if (emrContext.getActiveVisit() != null) {
for (Encounter encounter : emrContext.getActiveVisit().getVisit().getEncounters()) {
if (!encounter.isVoided() && outpatientVitalsForm.equals(encounter.getForm())) {
existingEncounters.add(encounter);
}
}
}
model.addAttribute("visit", emrContext.getActiveVisit() != null ? emrContext.getActiveVisit().getVisit() : null);
model.addAttribute("existingEncounters", existingEncounters);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
model.addAttribute("appName", CustomAppLoaderConstants.Apps.UHM_VITALS);
}
use of org.openmrs.Form in project openmrs-module-coreapps by openmrs.
the class PatientPageController method controller.
public void controller(@RequestParam("patientId") Patient patient, UiUtils ui, UiSessionContext emrContext, PageModel model, @SpringBean("formService") FormService formService, @SpringBean("patientService") PatientService patientService, @SpringBean("adtService") AdtService adtService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
patientDomainWrapper.setPatient(patient);
SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.message("referenceapplication.app.capturevitals.title"), "link", ui.pageLink("coreapps", "findpatient/findPatient?app=referenceapplication.vitals"));
SimpleObject patientPageBreadcrumb = SimpleObject.create("label", patient.getFamilyName() + ", " + patient.getGivenName(), "link", ui.thisUrlWithContextPath());
Form vitalsForm = formService.getFormByUuid("a000cb34-9ec1-4344-a1c8-f692232f6edd");
Location visitLocation = adtService.getLocationThatSupportsVisits(emrContext.getSessionLocation());
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, visitLocation);
List<Encounter> existingEncounters = new ArrayList<Encounter>();
if (activeVisit != null) {
for (Encounter encounter : activeVisit.getVisit().getEncounters()) {
if (!encounter.isVoided() && vitalsForm.equals(encounter.getForm())) {
existingEncounters.add(encounter);
}
}
}
model.addAttribute("visit", activeVisit != null ? activeVisit.getVisit() : null);
model.addAttribute("existingEncounters", existingEncounters);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormServiceImpl method duplicateForm.
/**
* Duplicate this form and form_fields associated with this form
*
* @param form
* @return New duplicated form
* @throws APIException
* @see org.openmrs.api.FormService#duplicateForm(org.openmrs.Form)
*/
@Override
public Form duplicateForm(Form form) throws APIException {
checkIfFormsAreLocked();
// get original form id for reference later
Integer originalFormId = form.getFormId();
for (FormField formField : form.getFormFields()) {
formField.setUuid(null);
formField.setFormFieldId(null);
}
// this is required because Hibernate would recognize the original collection
form.setFormFields(new HashSet<>(form.getFormFields()));
form.setUuid(null);
form.setFormId(null);
form.setCreator(null);
form.setDateCreated(null);
form.setChangedBy(null);
form.setDateChanged(null);
Context.clearSession();
RequiredDataAdvice.recursivelyHandle(SaveHandler.class, form, null);
Form newForm = dao.duplicateForm(form);
// duplicate form resources from the old form to the new one
duplicateFormResources(Context.getFormService().getForm(originalFormId), newForm);
return newForm;
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounters_shouldGetEncountersByForm.
/**
* @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
* java.util.Collection, java.util.Collection, boolean)
*/
@Test
public void getEncounters_shouldGetEncountersByForm() {
List<Form> forms = new ArrayList<>();
forms.add(new Form(1));
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setEnteredViaForms(forms).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
assertEquals(8, encounters.size());
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class ORUR01HandlerTest method processMessage_shouldPreferFormIdIfUuidIsNotFound.
/**
* @see ORUR01Handler#processMessage(Message)
*/
@Test
public void processMessage_shouldPreferFormIdIfUuidIsNotFound() 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||||||||1^AMRS.ELD.FORMID~oicu812^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 id
Form form = enc.getForm();
Assert.assertEquals(1, form.getId().intValue());
}
Aggregations