예제 #1
0
  /**
   * @see Encounter#getProvider()
   * @verifies should exclude voided providers
   */
  @Test
  public void getProvider_shouldExcludeVoidedProviders() throws Exception {
    // given
    Encounter encounter = new Encounter();
    EncounterRole role = new EncounterRole();

    Provider provider = new Provider();
    Provider anotherProvider = new Provider();

    Person person = new Person();
    Person anotherPerson = new Person();

    provider.setPerson(person);
    anotherProvider.setPerson(anotherPerson);

    // add the first provider
    encounter.setProvider(role, provider);

    // replace with the second provider
    encounter.setProvider(role, anotherProvider);

    // when
    Person result = encounter.getProvider();

    // then
    Assert.assertEquals(anotherPerson, result);
  }
  public void saveAndTransferFileComplexObs() {

    try {
      List<Encounter> encounters =
          Context.getEncounterService().getEncounters(null, null, null, null, null, null, true);
      Encounter lastEncounter = encounters.get(encounters.size() - 1);

      Person patient = lastEncounter.getPatient();
      ConceptComplex conceptComplex = Context.getConceptService().getConceptComplex(17);
      Location location = Context.getLocationService().getDefaultLocation();
      Obs obs = new Obs(patient, conceptComplex, new Date(), location);

      String mergedUrl = tempFile.getCanonicalPath();
      InputStream out1 = new FileInputStream(new File(mergedUrl));

      ComplexData complexData = new ComplexData(tempFile.getName(), out1);
      obs.setComplexData(complexData);
      obs.setEncounter(lastEncounter);

      Context.getObsService().saveObs(obs, null);
      tempFile.delete();

    } catch (Exception e) {
      log.error(e);
    }
  }
예제 #3
0
  /**
   * @see Encounter#getProvidersByRoles()
   * @verifies return all roles and providers
   */
  @Test
  public void getProvidersByRoles_shouldReturnAllRolesAndProviders() throws Exception {
    // given
    Encounter encounter = new Encounter();
    EncounterRole role = new EncounterRole();

    Provider provider = new Provider();
    encounter.addProvider(role, provider);

    Provider provider2 = new Provider();
    encounter.addProvider(role, provider2);

    EncounterRole role2 = new EncounterRole();
    Provider provider3 = new Provider();
    encounter.addProvider(role2, provider3);

    // when
    Map<EncounterRole, Set<Provider>> providersByRoles = encounter.getProvidersByRoles();

    // then
    Assert.assertEquals("Roles", 2, providersByRoles.size());
    Assert.assertTrue("Roles", providersByRoles.keySet().containsAll(Arrays.asList(role, role2)));

    Assert.assertEquals("Providers for role", 2, providersByRoles.get(role).size());
    Assert.assertTrue(
        "Providers for role",
        providersByRoles.get(role).containsAll(Arrays.asList(provider, provider2)));

    Assert.assertEquals("Provider for role2", 1, providersByRoles.get(role2).size());
    Assert.assertTrue("Providers for role2", providersByRoles.get(role2).contains(provider3));
  }
예제 #4
0
 /** @see Encounter#addObs(Obs) */
 @Test
 @Verifies(value = "should add obs with null values", method = "addObs(Obs)")
 public void addObs_shouldAddObsWithNullValues() throws Exception {
   Encounter encounter = new Encounter();
   encounter.addObs(new Obs());
   assertEquals(1, encounter.getAllObs(true).size());
 }
예제 #5
0
 /** @see Encounter#addOrder(Order) */
 @Test
 @Verifies(value = "should add order with null values", method = "addOrder(Order)")
 public void addOrder_shouldAddOrderWithNullValues() throws Exception {
   Encounter encounter = new Encounter();
   encounter.addOrder(new Order());
   assertEquals(1, encounter.getOrders().size());
 }
예제 #6
0
  /** @see Encounter#getObsAtTopLevel(null) */
  @Test
  @Verifies(
      value = "should get both child and parent obs after removing child from parent grouping",
      method = "getObsAtTopLevel(null)")
  public void getObsAtTopLevel_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping()
      throws Exception {
    Encounter enc = new Encounter();

    // create and add an Obs
    Obs parentObs = new Obs();
    enc.addObs(parentObs);

    // add a child to the obs and make sure that now that the Obs is an ObsGroup with one child:
    Obs childObs = new Obs();
    parentObs.addGroupMember(childObs);

    // add the child obs directly to the encounter as well
    childObs.setEncounter(enc);
    enc.addObs(childObs);

    // remove the obsGrouping, so that both obs are now just children of the Encounter
    parentObs.removeGroupMember(childObs);

    assertEquals(2, enc.getObsAtTopLevel(false).size());
  }
  @Test
  public void shouldNotBeEqualWhenDifferentClassesAndSameId() throws Exception {
    Encounter encounter = new Encounter(2);
    Order order = new Order(2);

    Assert.assertFalse(encounter.equals(order));
  }
예제 #8
0
 /** @see Encounter#addObs(Obs) */
 @Test
 @Verifies(value = "should not fail with null obs", method = "addObs(Obs)")
 public void addObs_shouldNotFailWithNullObs() throws Exception {
   Encounter encounter = new Encounter();
   encounter.addObs(null);
   assertEquals(0, encounter.getAllObs(true).size());
 }
예제 #9
0
 /** @see Encounter#toString() */
 @Test
 @Verifies(value = "should not fail with empty object", method = "toString()")
 public void toString_shouldNotFailWithEmptyObject() throws Exception {
   Encounter encounter = new Encounter();
   @SuppressWarnings("unused")
   String toStringOutput = encounter.toString();
 }
예제 #10
0
  /** @see Encounter#getAllObs(null) */
  @Test
  @Verifies(
      value = "should get both parent and child with child directly on encounter",
      method = "getAllObs(null)")
  public void getAllObs_shouldGetBothParentAndChildWithChildDirectlyOnEncounter() throws Exception {
    Encounter enc = new Encounter();

    // create and add an Obs
    Obs parentObs = new Obs();
    enc.addObs(parentObs);

    // add a child to the obs and make sure that now that the Obs is an ObsGroup with one child:
    Obs childObs = new Obs();
    parentObs.addGroupMember(childObs);

    // add the child obs directly to the encounter as well
    childObs.setEncounter(enc);
    enc.addObs(childObs);

    // do the check
    assertEquals(2, enc.getAllObs(true).size());

    // this should return one of each -- the obsGroup and the child (because encounter_id is
    // populated in the child Obs):
    int numberOfChildObs = 0;
    int numberofParentObs = 0;
    for (Obs oTmp : enc.getAllObs(false)) {
      if (oTmp.isObsGrouping()) numberofParentObs++;
      else numberOfChildObs++;
    }
    assertEquals(1, numberOfChildObs);
    assertEquals(1, numberofParentObs);
  }
예제 #11
0
 /** @see Encounter#addOrder(Order) */
 @Test
 @Verifies(value = "should not fail with null obs passed to add order", method = "addOrder(Order)")
 public void addOrder_shouldNotFailWithNullObsPassedToAddOrder() throws Exception {
   Encounter encounter = new Encounter();
   encounter.addOrder(null);
   assertEquals(0, encounter.getOrders().size());
 }
예제 #12
0
  /** @see Encounter#getObs() */
  @Test
  @Verifies(value = "should not return null with null obs set", method = "getObs()")
  public void getObs_shouldNotReturnNullWithNullObsSet() throws Exception {
    Encounter encounter = new Encounter();

    assertNotNull(encounter.getObs());
    assertEquals(encounter.getObs().size(), 0);
  }
예제 #13
0
 /** @see Encounter#removeOrder(Order) */
 @Test
 @Verifies(
     value = "should not fail when removing non existent order",
     method = "removeOrder(Order)")
 public void removeOrder_shouldNotFailWhenRemovingNonExistentOrder() throws Exception {
   Encounter encounter = new Encounter();
   encounter.removeOrder(new Order(123));
 }
예제 #14
0
 /** @see Encounter#addOrder(Order) */
 @Test
 @Verifies(value = "should set encounter attribute", method = "addOrder(Order)")
 public void addOrder_shouldSetEncounterAttribute() throws Exception {
   Encounter encounter = new Encounter();
   Order order = new Order();
   encounter.addOrder(order);
   assertTrue(order.getEncounter().equals(encounter));
 }
예제 #15
0
 /** @see Encounter#removeObs(Obs) */
 @Test
 @Verifies(
     value = "should not throw error when removing null obs from empty set",
     method = "removeObs(Obs)")
 public void removeObs_shouldNotThrowErrorWhenRemovingNullObsFromEmptySet() throws Exception {
   Encounter encounterWithoutObsSet = new Encounter();
   encounterWithoutObsSet.removeObs(null);
 }
예제 #16
0
 /** @see Encounter#addObs(Obs) */
 @Test
 @Verifies(value = "should set encounter attribute on obs", method = "addObs(Obs)")
 public void addObs_shouldSetEncounterAttributeOnObs() throws Exception {
   Encounter encounter = new Encounter();
   Obs obs = new Obs();
   encounter.addObs(obs);
   assertTrue(obs.getEncounter().equals(encounter));
 }
예제 #17
0
  /**
   * @see Encounter#getProvider()
   * @verifies return null if there is no providers
   */
  @Test
  public void getProvider_shouldReturnNullIfThereIsNoProviders() throws Exception {
    // given
    Encounter encounter = new Encounter();

    // when
    Person result = encounter.getProvider();

    // then
    Assert.assertNull(result);
  }
예제 #18
0
  /** @see Encounter#removeOrder(Order) */
  @Test
  @Verifies(value = "should remove order from encounter", method = "removeOrder(Order)")
  public void removeOrder_shouldRemoveOrderFromEncounter() throws Exception {
    Encounter encounter = new Encounter();
    Order order = new Order(1);
    encounter.addOrder(order);
    assertEquals(1, encounter.getOrders().size());

    encounter.removeOrder(order);
    assertEquals(0, encounter.getOrders().size());
  }
예제 #19
0
  /**
   * @see Encounter#getProvidersByRoles()
   * @verifies return empty map if no providers
   */
  @Test
  public void getProvidersByRoles_shouldReturnEmptyMapIfNoProviders() throws Exception {
    // given
    Encounter encounter = new Encounter();

    // when
    Map<EncounterRole, Set<Provider>> providersByRoles = encounter.getProvidersByRoles();

    // then
    Assert.assertEquals(0, providersByRoles.size());
  }
예제 #20
0
  /** @see Encounter#getOrders() */
  @Test
  @Verifies(
      value = "should add order to encounter when adding order to set returned from getOrders",
      method = "getOrders()")
  public void addOrders_shouldAddOrderToEncounterWhenAddingOrderToSetReturnedFromGetOrders()
      throws Exception {
    Encounter encounter = new Encounter();
    Order order = new Order();
    encounter.getOrders().add(order);

    assertEquals(1, encounter.getOrders().size());
  }
예제 #21
0
  /** @see Encounter#addOrder(Order) */
  @Test
  @Verifies(value = "should add order to non null initial order set", method = "addOrder(Order)")
  public void addOrder_shouldAddOrderToNonNullInitialOrderSet() throws Exception {
    Encounter encounter = new Encounter();
    Set<Order> orderSet = new HashSet<Order>();
    orderSet.add(new Order(1));

    encounter.setOrders(orderSet);

    encounter.addOrder(new Order(2));
    assertEquals(2, encounter.getOrders().size());
  }
예제 #22
0
  /** @see Encounter#getObs() */
  @Test
  @Verifies(value = "should get obs", method = "getObs()")
  public void getObs_shouldGetObs() throws Exception {
    Encounter encounter = new Encounter();

    // create and add an Obs
    Obs o = new Obs();
    encounter.addObs(o);

    assertNotNull(encounter.getObs());
    assertEquals(1, encounter.getObs().size());
  }
예제 #23
0
  /** @see Encounter#getObs() */
  @Test
  @Verifies(value = "should not get voided obs", method = "getObs()")
  public void getObs_shouldNotGetVoidedObs() throws Exception {
    Encounter enc = new Encounter();

    // create and add an Obs
    Obs o = new Obs();
    o.setVoided(true);
    enc.addObs(o);

    assertEquals(0, enc.getObs().size());
  }
예제 #24
0
  /** @see Encounter#addObs(Obs) */
  @Test
  @Verifies(value = "should add obs to non null initial obs set", method = "addObs(Obs)")
  public void addObs_shouldAddObsToNonNullInitialObsSet() throws Exception {
    Encounter encounter = new Encounter();
    Set<Obs> obsSet = new HashSet<Obs>();
    obsSet.add(new Obs(1));

    encounter.setObs(obsSet);

    encounter.addObs(new Obs(2));
    assertEquals(2, encounter.getAllObs(true).size());
  }
예제 #25
0
  /**
   * @see Encounter#addProvider(EncounterRole,Provider)
   * @verifies add provider for new role
   */
  @Test
  public void addProvider_shouldAddProviderForNewRole() throws Exception {
    // given
    Encounter encounter = new Encounter();
    EncounterRole encounterRole = new EncounterRole();
    Provider provider = new Provider();

    // when
    encounter.addProvider(encounterRole, provider);

    // then
    Assert.assertTrue(encounter.getProvidersByRole(encounterRole).contains(provider));
  }
예제 #26
0
  /**
   * @see Encounter#getProvidersByRole(EncounterRole)
   * @verifies return empty set for null role
   */
  @Test
  public void getProvidersByRole_shouldReturnEmptySetForNullRole() throws Exception {
    // given
    Encounter encounter = new Encounter();
    EncounterRole role = new EncounterRole();
    Provider provider = new Provider();
    encounter.addProvider(role, provider);

    // when
    Set<Provider> providers = encounter.getProvidersByRole(null);

    // then
    Assert.assertEquals(0, providers.size());
  }
예제 #27
0
  /**
   * @see Encounter#setProvider(EncounterRole,Provider)
   * @verifies set provider for new role
   */
  @Test
  public void setProvider_shouldSetProviderForNewRole() throws Exception {
    // given
    Encounter encounter = new Encounter();
    EncounterRole role = new EncounterRole();
    Provider provider = new Provider();

    // when
    encounter.setProvider(role, provider);

    // then
    Assert.assertEquals(1, encounter.getProvidersByRole(role).size());
    Assert.assertTrue(encounter.getProvidersByRole(role).contains(provider));
  }
예제 #28
0
  /**
   * @see Encounter#getProvider()
   * @verifies return null if there is no provider for person
   */
  @Test
  public void getProvider_shouldReturnNullIfThereIsNoProviderForPerson() throws Exception {
    // given
    Encounter encounter = new Encounter();
    EncounterRole role = new EncounterRole();
    Provider provider = new Provider();
    encounter.addProvider(role, provider);

    // when
    Person result = encounter.getProvider();

    // then
    Assert.assertNull(result);
  }
예제 #29
0
  /** @see Encounter#removeObs(Obs) */
  @Test
  @Verifies(
      value = "should not throw error when removing null obs from non empty set",
      method = "removeObs(Obs)")
  public void removeObs_shouldNotThrowErrorWhenRemovingNullObsFromNonEmptySet() throws Exception {
    Encounter encounterWithObsSet = new Encounter();
    Set<Obs> obsSet = new HashSet<Obs>();
    obsSet.add(new Obs());

    encounterWithObsSet.setObs(obsSet);
    // make sure the encounter got the obs
    Assert.assertEquals(1, encounterWithObsSet.getAllObs(true).size());
    encounterWithObsSet.removeObs(null);
  }
예제 #30
0
  /**
   * @see Encounter#getProvider()
   * @verifies return provider for person
   */
  @Test
  public void getProvider_shouldReturnProviderForPerson() throws Exception {
    // given
    Encounter encounter = new Encounter();
    EncounterRole role = new EncounterRole();
    Provider provider = new Provider();
    Person person = new Person();
    provider.setPerson(person);
    encounter.addProvider(role, provider);

    // when
    Person result = encounter.getProvider();

    // then
    Assert.assertEquals(person, result);
  }