Package org.openmrs

Examples of org.openmrs.Encounter


        return "standardRegimenTestForm";
      }
     
      @Override
      public Encounter getEncounterToView(){
        Encounter e = new Encounter();
        Patient p = Context.getPatientService().getPatient(2);
        e.setPatient(p);
        e.setEncounterDatetime(date);
        e.setProvider(Context.getPersonService().getPerson(502));
        e.setEncounterType(Context.getEncounterService().getEncounterType(1));
        e.setLocation(Context.getLocationService().getLocation(2));

        //add standard regimen to encounter:
        List<RegimenSuggestion> rs = DrugOrderSupport.getInstance().getStandardRegimens();
        RegimenSuggestion rsug = RegimenUtil.getStandardRegimenByCode(rs, "all3");
        Set<Order> dors = RegimenUtil.standardRegimenToDrugOrders(rsug, date, p);
        for (Order o : dors){
          o.setDiscontinuedDate(new Date(date.getTime() + 10));
          o.setDiscontinuedBy(Context.getAuthenticatedUser());
          o.setDiscontinuedReason(Context.getConceptService().getConcept(102));
          o.setDiscontinued(true);
          o.setDiscontinuedReasonNonCoded("non-coded reason");
          e.addOrder(o);
       
        //save so interceptor sets missing mandatory values
        return Context.getEncounterService().saveEncounter(e);
      }
     
View Full Code Here


        return "standardRegimenTestForm";
      }
     
      @Override
      public Encounter getEncounterToView(){
        Encounter e = new Encounter();
        Patient p = Context.getPatientService().getPatient(2);
        e.setPatient(p);
        e.setEncounterDatetime(date);
        e.setProvider(Context.getPersonService().getPerson(502));
        e.setEncounterType(Context.getEncounterService().getEncounterType(1));
        e.setLocation(Context.getLocationService().getLocation(2));

        //add standard regimen to encounter:
        List<RegimenSuggestion> rs = Context.getOrderService().getStandardRegimens();
        RegimenSuggestion rsug = RegimenUtil.getStandardRegimenByCode(rs, "drug2and3");
        Set<Order> dors = RegimenUtil.standardRegimenToDrugOrders(rsug, date, p);
        for (Order o : dors){
          e.addOrder(o);
       
        //save so interceptor sets missing mandatory values
        return Context.getEncounterService().saveEncounter(e);
      }
     
View Full Code Here

 
  @Test
  @Verifies(value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldReturnEncounterVoided() throws Exception {
    executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
   
    //add a bunch of obs...
    TestUtil.addObs(e, 2474, Context.getConceptService().getConcept(656), date); //matches
   
    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH
            + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);
   
    //this is going to test out the voided state of the obs in the encounter after processing:
    Assert.assertTrue(e.isVoided());
   
  }
View Full Code Here

 
  @Test
  @Verifies(value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldReturnEncounterCorrectly() throws Exception {
    executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
   
    //add a bunch of obs...
    TestUtil.addObs(e, 2474, Context.getConceptService().getConcept(656), date); //matches
    TestUtil.addObs(e, 3017, Context.getConceptService().getConcept(767), date); //matches
    TestUtil.addObs(e, 3032, new Date(), date); //matches
    TestUtil.addObs(e, 1, 5000, date); //   matches
    TestUtil.addObs(e, 2, 5000, date); //not in form schema
    TestUtil.addObs(e, 3, 5000, date); //not in form schema
    TestUtil.addObs(e, 6, "blah blah", date); //   matches
    //1004 is ANOTHER ALLERGY CONSTRUCT, 1005 is HYPER-ALLERGY CODED, 1001 is PENICILLIN
    TestUtil.addObsGroup(e, 1004, new Date(), 1005, Context.getConceptService().getConcept(1001), new Date()); //matches
    //7 IS ALLERGY CONSTRUCT, 1000 IS ALLERGY CODED, 1003 IS OPENMRS
    TestUtil.addObsGroup(e, 7, new Date(), 1000, Context.getConceptService().getConcept(1003), new Date()); //matches
    TestUtil.addObsGroup(e, 1000, new Date(), 7, Context.getConceptService().getConcept(1003), new Date()); //does not match     
    Context.getEncounterService().saveEncounter(e);
   
    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH
            + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);
   
    //this is going to test out the voided state of the obs in the encounter after processing:
    Assert.assertTrue(!e.isVoided());
    for (Obs o : e.getAllObs(true)) {
      if (o.getConcept().getConceptId().equals(2474))
        Assert.assertTrue(o.isVoided());
      if (o.getConcept().getConceptId().equals(3017))
        Assert.assertTrue(o.isVoided());
      if (o.getConcept().getConceptId().equals(3032))
View Full Code Here

 
  @Test
  @Verifies(value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldHandleDrugOrderCorrectly() throws Exception {
    executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 1, 5000, date); //a matching obs
   
    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setStartDate(new Date());
    e.addOrder(dor);
   
    Context.getEncounterService().saveEncounter(e);
   
    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH
            + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
   
    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, "test void reason");
   
    //this is going to test out the voided state of the obs in the encounter after processing:
    //order was matched, so order was voided, and because that's the only thing in the encounter, encounter was voided too.
    Assert.assertTrue(e.isVoided());
    Assert.assertTrue(e.getVoidReason().equals("test void reason"));
    for (Order o : e.getOrders()) {
      Assert.assertTrue(o.isVoided());
      Assert.assertTrue(o.getVoidReason().equals("test void reason"));
    }
    for (Obs o : e.getAllObs(true)) {
      Assert.assertTrue(o.getVoidReason().equals("test void reason"));
    }
  }
View Full Code Here

 
  @Test
  @Verifies(value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldHandleDrugOrderAndObsCorrectly() throws Exception {
    executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 3, 5000, date);//adding an un-matched Obs
   
    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setStartDate(new Date());
    e.addOrder(dor);
   
    Context.getEncounterService().saveEncounter(e);
   
    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH
            + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
   
    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);
   
    //order was matched, obs was not, so order should be voided, obs not, encounter not.
    Assert.assertTrue(!e.isVoided());
    for (Order o : e.getOrders()) {
      Assert.assertTrue(o.isVoided());
    }
    for (Obs o : e.getObs()) {
      Assert.assertTrue(!o.isVoided());
    }
  }
View Full Code Here

 
  @Test
  @Verifies(value = "should delete encounter correctly", method = "voidEncounterByHtmlFormSchema")
  public void testVoidEncounterByHtmlFormSchema_shouldDeleteEncounter() throws Exception {
    executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    Encounter e = new Encounter();
    e.setPatient(Context.getPatientService().getPatient(2));
    Date date = Context.getDateFormat().parse("01/02/2003");
    e.setDateCreated(new Date());
    e.setEncounterDatetime(date);
    e.setLocation(Context.getLocationService().getLocation(2));
    e.setProvider(Context.getPersonService().getPerson(502));
    TestUtil.addObs(e, 3, 5000, date);//adding an un-matched, voided Obs
    for (Obs o : e.getAllObs(true)) {
      o.setVoided(true);
      o.setVoidedBy(Context.getUserService().getUser(1));
      o.setVoidReason("blah");
      o.setDateVoided(new Date());
    }
   
    //and adding a voided drug order
    DrugOrder dor = new DrugOrder();
    dor.setVoided(false);
    dor.setConcept(Context.getConceptService().getConcept(792));
    dor.setCreator(Context.getUserService().getUser(1));
    dor.setDateCreated(new Date());
    dor.setDiscontinued(false);
    dor.setDrug(Context.getConceptService().getDrug(2));
    dor.setOrderType(Context.getOrderService().getOrderType(1));
    dor.setPatient(Context.getPatientService().getPatient(2));
    dor.setVoided(true);
    dor.setVoidedBy(Context.getUserService().getUser(1));
    dor.setVoidReason("blah");
    dor.setDateVoided(new Date());
    dor.setStartDate(new Date());
    e.addOrder(dor);
   
    Context.getEncounterService().saveEncounter(e);
   
    Form form = new Form();
    HtmlForm htmlform = new HtmlForm();
    htmlform.setForm(form);
    form.setEncounterType(new EncounterType());
    htmlform.setDateChanged(new Date());
    htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH
            + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
   
    HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);
   
    //encounter had no non-voided objects, should be voided
    Assert.assertTrue(e.isVoided());
  }
View Full Code Here

                    for (Obs oInner : oList)
                        log.debug("Obs in existingObsInGroups " + existingObsInGroups.getKey().getConcept() + " " + oInner.getConcept());
                }
            }
        }
        Encounter ret = new Encounter();
        ret.setCreator(e.getCreator());
        ret.setEncounterDatetime(e.getEncounterDatetime());
        ret.setProvider(e.getProvider());
        ret.setLocation(e.getLocation());
        ret.setDateCreated(e.getDateCreated());
        ret.setPatient(e.getPatient());
        //renders new encounter unsave-able:
        ret.setEncounterId(e.getEncounterId());
       
        for (Obs oTest : e.getAllObs()){
            boolean found = false;
            if (session.getContext().getExistingObs() != null && !oTest.isObsGrouping()){
                List<Obs> obsList = session.getContext().getExistingObs().get(oTest.getConcept());
                if (obsList != null && obsList.size() > 0){
                    for (Obs o : obsList){
                        if (o.getObsId().equals(oTest.getObsId())){
                            found = true;
                            continue;
                        }
                    }  
                }
            }
            if (!found && session.getContext().getExistingObsInGroups() != null){
                for (Map.Entry<Obs, Set<Obs>> mapEntry : session.getContext().getExistingObsInGroups().entrySet()){
                    if (mapEntry.getKey().equals(oTest)){
                        found = true;
                        continue;
                    } else {
                        Set<Obs> oSet = mapEntry.getValue();
                        //note: oSet.contains fails for some reason
                        for (Obs o:oSet){
                              if (o.getObsId().equals(oTest.getObsId())){
                                  found = true;
                                  continue;
                              }   
                        } 
                    }
                }
            }
            if (!found)
                ret.addObs(oTest);
        }
        session = null;
        return ret;
   
View Full Code Here

        } else {
            if (context.getMode() == Mode.EDIT) {
                if (encounter == null)
                    throw new RuntimeException("Programming exception: encounter shouldn't be null in EDIT mode");
            } else {
                encounter = new Encounter();
            }
            try {
                submissionActions.beginPerson(patient);
                submissionActions.beginEncounter(encounter);
            } catch (InvalidActionException e) {
View Full Code Here

    //if we give inList, start with that list and remove encounters
    if (inListEncounters != null) {
      encs = inListEncounters;
      Iterator<Encounter> iter = encs.iterator();
      while (iter.hasNext()) {
        Encounter currEnc = iter.next();
        if ((startDate != null && currEnc.getEncounterDatetime().before(startDate))
                || (endDate != null && currEnc.getEncounterDatetime().after(endDate))
                || (encType != null && !currEnc.getEncounterType().equals(encType))
                || (patient != null && !currEnc.getPatient().equals(patient))) {
          iter.remove();
        } else if (provid != null) {
          Iterator<Set<Provider>> providerIter = currEnc.getProvidersByRoles().values().iterator();
          boolean hasProvider = false;
          while (providerIter.hasNext() && !hasProvider) {
            Set<Provider> providerEncounters = providerIter.next();
            if (providerEncounters.contains(provid)) {
              hasProvider = true;
            }
          }
          if (!hasProvider) {
            iter.remove();
          }
        }
      }
    }
    //otherwise, make an entirely new list
    else {
      if (uuid != null) {
        encs = Context.getEncounterService().getEncounters(patient, location, startDate, endDate, null, encTypes,
            provids, null, null, Boolean.FALSE);
      } else {
        encs = Context.getEncounterService().getEncounters(patient, location, startDate, endDate, null, encTypes,
            null, null, null, Boolean.FALSE);
      }
    }
    //refactor this to hash map so double loop is not required
    if (notInListPatients != null) {
      Iterator<Encounter> iter = encs.iterator();
      Iterator<Encounter> iter2;
      //if patient is in notInListPatients, remove the encounter
      while (iter.hasNext()) {
        Encounter currEnc = iter.next();
        //if patient already has encounter, check the dates to see if he should be removed
        if (notInListPatients.contains(currEnc.getPatient())) {
          iter2 = notInListEncounters.iterator();
          boolean removed = false;
          while (iter2.hasNext() && !removed) {
            Encounter currEnc2 = iter2.next();
            if (currEnc2.getPatient().equals(currEnc.getPatient())
                    && currEnc2.getEncounterDatetime().after(currEnc.getEncounterDatetime())) {
              iter.remove();
              removed = true;
            }
          }
        }
      }
    }
    if (containsOrderType.equals("drugOrder")) {
      boolean shouldRemove;
      Iterator<Encounter> iter = encs.iterator();
      while (iter.hasNext()) {
        shouldRemove = true;
        Encounter currEnc = iter.next();
        Iterator<Order> orderIter = currEnc.getOrders().iterator();
        while (orderIter.hasNext()) {
          Order o = orderIter.next();
          if (o.isDrugOrder()) {
            shouldRemove = false;
            break;
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.