org.openmrs.Obs.removeGroupMember()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中org.openmrs.Obs.removeGroupMember()方法的一些代码示例,展示了Obs.removeGroupMember()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Obs.removeGroupMember()方法的具体详情如下:
包路径:org.openmrs.Obs
类名称:Obs
方法名:removeGroupMember

Obs.removeGroupMember介绍

[英]Convenience method to remove an Obs from this grouping This also removes the link in the given obsobject to this obs grouper
[中]从该分组中删除Obs的便捷方法这也会删除给定obs对象中指向该Obs分组的链接

代码示例

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see Obs#removeGroupMember(Obs)
 */
@Test
public void removeGroupMember_shouldReturnFalseWhenANonExistentObsIsRemoved() throws Exception {
  Obs obs = new Obs();
  obs.removeGroupMember(new Obs());
  assertFalse(obs.isDirty());
}

代码示例来源:origin: openmrs/openmrs-core

@Test
public void saveEncounter_shouldSaveEncounterWhenTopLevelObsIsUpdatedByRemovingChildObs() {
  executeDataSet(ENC_OBS_HIERARCHY_DATA_XML);
  EncounterService es = Context.getEncounterService();
  ObsService os = Context.getObsService();
  Encounter enc = es.getEncounter(100);
  Obs oParent = os.getObs(100);
  Obs oChild = os.getObs(101);
  oParent.removeGroupMember(oChild);
  es.saveEncounter(enc);
  Context.flushSession();
  Context.clearSession();
  enc = es.getEncounter(100);
  Set<Obs> obsAtTopLevel = enc.getObsAtTopLevel(true);
  assertEquals(2,obsAtTopLevel.size()); //oChild's new version is still associated to encounter but not part of the oParent anymore
  assertTrue(obsAtTopLevel.contains(os.getObs(100)));
  Obs newObs = obsAtTopLevel.stream().filter(obs -> obs.getObsId() != 100 ).findFirst().get(); //Find the other top level obs which is not 100. i.e. the new obs which is a clone of 101
  assertNotNull(newObs.getPreviousVersion());
  assertEquals(oChild.getObsId(), newObs.getPreviousVersion().getObsId());
  assertTrue(os.getObs(100).getGroupMembers(true).contains(os.getObs(102)));
  //The oChild will still be associated to the parent because when we save oChild, we create a new instance
  //and void the oChild using ObsServiceImpl.voidExistingObs(). We use Context.evictFromSession(obs); to get a fresh copy
  //there by losing the change we made to oChild.
  assertTrue(os.getObs(100).getGroupMembers(true).contains(os.getObs(101)));
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see Encounter#getAllObs(null)
 */
@Test
public void getAllObs_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping() {
  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.getAllObs(true).size());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see Encounter#getObsAtTopLevel(null)
 */
@Test
public void getObsAtTopLevel_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping() {
  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());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see Encounter#getObs()
 */
@Test
public void getObs_shouldGetBothChildAndParentObsAfterRemovingChildFromParentGrouping() {
  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);
  
  // do the check
  assertEquals(2, enc.getObs().size());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see Obs#removeGroupMember(Obs)
 */
@Test
public void removeGroupMember_shouldReturnDirtyFalseWhenAnObsIsRemoved() throws Exception {
  Obs obs = new Obs(2);
  Obs member = new Obs();
  obs.addGroupMember(member);
  assertFalse(obs.isDirty());
  resetObs(obs);
  obs.removeGroupMember(member);
  assertFalse(obs.isDirty());
}

代码示例来源:origin: openmrs/openmrs-core

/**
 * @see Obs#removeGroupMember(Obs)
 */
@Test
public void removeGroupMember_shouldReturnFalseForDirtyFlagWhenAnObsIsRemovedFromGroup() throws Exception {
  Obs obs = new Obs();
  Obs member = new Obs();
  obs.addGroupMember(member);
  assertFalse(obs.isDirty());
  resetObs(obs);
  obs.removeGroupMember(member);
  assertFalse(obs.isDirty());
}

代码示例来源:origin: openmrs/openmrs-core

obsGroup.removeGroupMember(obs2);
assertTrue(obsGroup.hasGroupMembers(false));
assertEquals("Removing a non existent obs should not decrease the number of grouped obs", 1, obsGroup
new Obs().removeGroupMember(obs2);
obsGroup.removeGroupMember(obs);

代码示例来源:origin: openmrs/openmrs-core

oGrandparent.removeGroupMember(o2);

代码示例来源:origin: openmrs/openmrs-module-htmlformentry

/**
 * Removes any Obs that are empty or which have only empty children
 */
public static void removeEmptyObs(Collection<Obs> obsList) {
  if (obsList != null) {
    Set<Obs> obsToRemove = new HashSet<Obs>();
    for (Obs o : obsList) {
      removeEmptyObs(o.getGroupMembers());
      boolean valueEmpty = StringUtils.isEmpty(o.getValueAsString(Context.getLocale()));
      boolean membersEmpty = o.getGroupMembers() == null || o.getGroupMembers().isEmpty();
      if (valueEmpty && membersEmpty) {
        obsToRemove.add(o);
      }
    }
    for (Obs o : obsToRemove) {
      if (o.getObsGroup() != null) {
        o.getObsGroup().removeGroupMember(o);
        o.setObsGroup(null);
      }
      if (o.getEncounter() != null) {
        o.getEncounter().removeObs(o);
        o.setEncounter(null);
      }
      obsList.remove(o);
    }
  }
}

相关文章