Package org.openmrs

Examples of org.openmrs.Encounter


        return "singleObsFormWithUploader";
      }
     
      @Override
      public Encounter getEncounterToView() throws Exception {
        Encounter e = new Encounter();
        BufferedImage image = createImage();
        e.setPatient(getPatient());
        Date date = Context.getDateFormat().parse("11/08/2012");
        e.setDateCreated(new Date());
        e.setEncounterDatetime(date);
        e.setLocation(Context.getLocationService().getLocation(2));
        e.setProvider(Context.getPersonService().getPerson(502));
       
        Obs obs = new Obs();
        obs.setConcept(Context.getConceptService().getConcept(6100));
        obs.setComplexData(new ComplexData("complex_obs_image_test.gif", image));
        obs.setValueComplex("gif image |complex_obs_image_test.gif");
       
        e.addObs(obs);
        Context.getEncounterService().saveEncounter(e);
        return e;
      }
    }.run();
  }
View Full Code Here


    Map<String, String> labeledWidgets = getLabeledWidgets(html, widgetLabels());
    MockHttpServletRequest request = new MockHttpServletRequest();
        request.setSession(session.getHttpSession());
    setupRequest(request, labeledWidgets);
    Patient patientToView = null;
    Encounter encounterToView = null;
    if (request.getParameterMap().size() > 0) {
      SubmissionResults results = doSubmission(session, request);
      testResults(results);
      patientToView = results.getPatient();
      encounterToView = results.getEncounterCreated();
    }

    // view that patient and run tests on it
    Patient overridePatient = getPatientToView();
    boolean doViewPatient = overridePatient != null || doViewPatient();
    if (doViewPatient) {
      if (overridePatient != null)
        patientToView = overridePatient;
      session = setupFormViewSession(patientToView, null, getFormName());
      testFormViewSessionAttribute(session);
      html = session.getHtmlToDisplay();
      testViewingPatient(patientToView, html);
    }

    // view that encounter and run tests on that
    Encounter override = getEncounterToView();
    boolean doViewEncounter = override != null || doViewEncounter();
    if (doViewEncounter) {
      if (override != null)
        encounterToView = override;

      session = setupFormViewSession(patientToView, encounterToView, getFormName());
      testFormViewSessionAttribute(session);
      html = session.getHtmlToDisplay();
      testViewingEncounter(encounterToView, html);
    }

    // edit the encounter, and run tests on that
    override = getEncounterToEdit();
    boolean doEditEncounter = override != null || doEditEncounter();

    overridePatient = getPatientToEdit();
    boolean doEditPatient = overridePatient != null || doEditPatient();

    if (doEditEncounter || doEditPatient) {
      Encounter toEdit = encounterToView;
      if (override != null)
        toEdit = override;

      Patient patientToEdit = patientToView;
      if (overridePatient != null)
View Full Code Here

      if (voidReason == null)
        voidReason = "htmlformentry";
      boolean shouldVoidEncounter = true;
      Map<Obs, Obs> replacementObs = new HashMap<Obs, Obs>();//new, then source
      Map<Order, Order> replacementOrders = new HashMap<Order, Order>();//new, then source
      Encounter eTmp = returnEncounterCopy(e, replacementObs, replacementOrders);
      FormEntrySession session = new FormEntrySession(eTmp.getPatient(), eTmp, Mode.VIEW, htmlform, null); // session gets a null HttpSession
            session.getHtmlToDisplay();
      List<FormSubmissionControllerAction> actions = session.getSubmissionController().getActions();
      Set<Obs> matchedObs = new HashSet<Obs>();
      Set<Order> matchedOrders = new HashSet<Order>();
      for (FormSubmissionControllerAction lfca : actions) {
View Full Code Here

   * @throws Exception
   */
  private static Encounter returnEncounterCopy(Encounter source, Map<Obs, Obs> replacementObs,
                                               Map<Order, Order> replacementOrders) throws Exception {
    if (source != null) {
      Encounter encNew = (Encounter) returnCopy(source);
     
      //note: we can do this because we're not going to manipulate anything about these obs or orders, and this copy won't be persisted...
     
      Set<Obs> newObs = new HashSet<Obs>();
      for (Obs o : source.getAllObs(true)) {
        Obs oNew = returnObsCopy(o, replacementObs);
        newObs.add(oNew);
      }
      encNew.setObs(newObs);
     
      Set<Order> newOrders = new HashSet<Order>();
      for (Order o : source.getOrders()) {
        Order oNew = (Order) returnOrderCopy(o, replacementOrders);
        newOrders.add(oNew);
      }
      encNew.setOrders(newOrders);
      return encNew;
    }
    return null;
  }
View Full Code Here

            }
            session.getSubmissionActions().getCurrentEncounter().setEncounterDatetime(date);
        }
        if (timeWidget != null) {
            Date time = (Date) timeWidget.getValue(session.getContext(), submission);
            Encounter e = session.getSubmissionActions().getCurrentEncounter();
            Date dateAndTime = HtmlFormEntryUtil.combineDateAndTime(e.getEncounterDatetime(), time);
            e.setEncounterDatetime(dateAndTime);
        }
        if (providerWidget != null) {
            Object value = providerWidget.getValue(session.getContext(), submission);
            Person person = (Person) convertValueToProvider(value);
            session.getSubmissionActions().getCurrentEncounter().setProvider(person);
View Full Code Here

      throw new IllegalArgumentException("Cannot enroll in a blank program");
   
    Patient patient = highestOnStack(Patient.class);
    if (patient == null)
      throw new IllegalArgumentException("Cannot enroll in a program outside of a Patient");
    Encounter encounter = highestOnStack(Encounter.class);
   
    // if an enrollment date has not been specified, enrollment date is the encounter date
    enrollmentDate = (enrollmentDate != null) ? enrollmentDate : (encounter  != null) ? encounter.getEncounterDatetime() : null;
   
    if (enrollmentDate == null)
      throw new IllegalArgumentException("Cannot enroll in a program without specifying an Encounter Date or Enrollment Date");
   
    // only need to do some if the patient is not enrolled in the specified program on the specified date
View Full Code Here

      throw new IllegalArgumentException("Cannot end a blank program");
   
    Patient patient = highestOnStack(Patient.class);
    if (patient == null)
      throw new IllegalArgumentException("Cannot find program without a patient");
    Encounter encounter = highestOnStack(Encounter.class);
    if (encounter == null)
      throw new IllegalArgumentException("Cannot end enrollment in a program outside of an Encounter");
   
    List<PatientProgram> pp = Context.getProgramWorkflowService().getPatientPrograms(patient, program, null,
        encounter.getEncounterDatetime(), new Date(), null, false);
   
    patientProgramsToComplete.addAll(pp);
  }
View Full Code Here

      throw new IllegalArgumentException("Cannot change to a blank state");
   
    Patient patient = highestOnStack(Patient.class);
    if (patient == null)
      throw new IllegalArgumentException("Cannot change state without a patient");
    Encounter encounter = highestOnStack(Encounter.class);
    if (encounter == null)
      throw new IllegalArgumentException("Cannot change state without an Encounter");

        // fetch any existing patient program with a state from this workflow
    PatientProgram patientProgram = HtmlFormEntryUtil.getPatientProgramByWorkflow(patient, state.getProgramWorkflow());

        // if no existing patient program, see if a patient program for this program is already set to be created at part of this submission (HTML-416)
        if (patientProgram == null) {
           patientProgram = HtmlFormEntryUtil.getPatientProgramByProgram(patientProgramsToCreate, state.getProgramWorkflow().getProgram());
        }

        if (patientProgram == null) {
            patientProgram = HtmlFormEntryUtil.getPatientProgramByProgram(patientProgramsToUpdate, state.getProgramWorkflow().getProgram());
        }

        // if patient program is still null, we need to create a new program
    if (patientProgram == null) {
      patientProgram = new PatientProgram();
      patientProgram.setPatient(patient);
      patientProgram.setProgram(state.getProgramWorkflow().getProgram());
      patientProgram.setDateEnrolled(encounter.getEncounterDatetime());
      // HACK: we need to set the date created, creator, and uuid here as a hack around a hibernate flushing issue
      // (should be able to remove this once we move to Hibernate Interceptors instead of Spring AOP to set these parameters)
      patientProgram.setDateCreated(new Date());
      patientProgram.setCreator(Context.getAuthenticatedUser());
      patientProgram.setUuid(UUID.randomUUID().toString());
     
    }
   
    for (PatientState patientState : patientProgram.statesInWorkflow(state.getProgramWorkflow(), false)) {
      if (patientState.getActive(encounter.getEncounterDatetime())) {
        if (patientState.getState().equals(state)) {
          return;
        }
      }
    }
   
    PatientState previousState = null;
    PatientState nextState = null;
    PatientState newState = new PatientState();
    newState.setPatientProgram(patientProgram);
    newState.setState(state);
    newState.setStartDate(encounter.getEncounterDatetime());
    // HACK: we need to set the date created, creator, and uuid here as a hack around a hibernate flushing issue
    // (should be able to remove this once we move to Hibernate Interceptors instead of Spring AOP to set these parameters)
    newState.setDateCreated(new Date());
    newState.setCreator(Context.getAuthenticatedUser());
    newState.setUuid(UUID.randomUUID().toString());
View Full Code Here

     
      @Override
      public void testResults(SubmissionResults results) {
        results.assertNoErrors();
        results.assertEncounterCreated();
        Encounter e = results.getEncounterCreated();
        Assert.assertTrue(e != null);
        Assert.assertTrue(e.getOrders() != null);
       
        // build the list of drugs that should be in the order in the order
        Set<Integer> drugsInOrder = new HashSet<Integer>();
        drugsInOrder.add(2);
        drugsInOrder.add(3);
        drugsInOrder.add(11);
       
        Assert.assertTrue(e.getOrders().size() == 3);
        for (Order o : e.getOrders()){
          if (o instanceof DrugOrder == false) {
            Assert.assertTrue(false);
          }
          if (!drugsInOrder.remove(((DrugOrder) o).getDrug().getId())) {
            Assert.assertTrue(false);
View Full Code Here

     
      @Override
      public void testResults(SubmissionResults results) {
        results.assertNoErrors();
        results.assertEncounterCreated();
        Encounter e = results.getEncounterCreated();
        Assert.assertTrue(e != null);
        Assert.assertTrue(e.getOrders() != null);
        Assert.assertTrue(e.getOrders().size() == 3);
        for (Order o : e.getOrders()){
          if (o instanceof DrugOrder == false)
            Assert.assertTrue(false);
          Assert.assertTrue(dateAsString(o.getStartDate()).equals(dateAsString(date)));
          Assert.assertTrue(o.isDiscontinued(new Date(date.getTime() + 5000)));
          Assert.assertTrue(o.getDiscontinuedReason().getConceptId().equals(102));
View Full Code Here

TOP

Related Classes of org.openmrs.Encounter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.