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

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

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

Obs.getPreviousVersion介绍

[英]When ObsService updates an obs, it voids the old version, creates a new Obs with the updates, and adds a reference to the previousVersion in the new Obs. getPreviousVersion returns the last version of this Obs.
[中]当ObsService更新obs时,它会使旧版本无效,使用更新创建新obs,并在新obs中添加对先前版本的引用。getPreviousVersion返回此Obs的最后一个版本。

代码示例

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

public Boolean hasPreviousVersion() {
  return getPreviousVersion() != null;
}

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

private Obs getNewVersionOfEditedObs(Obs parentObs, Obs originalObs){
  for(Obs childObs: parentObs.getGroupMembers()){
    if(originalObs.equals(childObs.getPreviousVersion())){
      return childObs;
    }
  }
  return null;
}

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

private void voidExistingObs(Obs obs, String changeMessage, Obs newObs) {
  // void out the original observation to keep it around for
  // historical purposes
  try {
    Context.addProxyPrivilege(PrivilegeConstants.DELETE_OBS);
    // fetch a clean copy of this obs from the database so that
    // we don't write the changes to the database when we save
    // the fact that the obs is now voided
    evictObsAndChildren(obs);
    obs = Context.getObsService().getObs(obs.getObsId());
    //delete the previous file from the appdata/complex_obs folder
    if (newObs.hasPreviousVersion() && newObs.getPreviousVersion().isComplex()) {
      File previousFile = AbstractHandler.getComplexDataFile(obs);
      previousFile.delete();
    }
    // calling this via the service so that AOP hooks are called
    Context.getObsService().voidObs(obs, changeMessage);
  }
  finally {
    Context.removeProxyPrivilege(PrivilegeConstants.DELETE_OBS);
  }
}

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

if (enc.getEncounterDatetime().equals(o.getObsDatetime())) {
    obsWithSameDateAfter.add(o);
    assertTrue(obsWithSameDateBefore.contains(o.getPreviousVersion()));
  } else if (obsWithDifferentDateAfter == null) {
    obsWithDifferentDateAfter = o;
assertNull(obsWithDifferentDateAfter.getPreviousVersion());
assertSame(obsWithDifferentDateBefore, obsWithDifferentDateAfter);

代码示例来源: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 ObsService#saveObs(Obs,String)
 */
@Test
public void saveObs_shouldLinkOriginalAndUpdatedObs() {
  // build
  int obsId = 7;
  ObsService obsService = Context.getObsService();
  Obs obs = obsService.getObs(obsId);
  
  // operate
  // change something on the obs and save it again
  obs.setComment("A new comment");
  Obs obsSaved = obsService.saveObs(obs, "Testing linkage");
  obs = obsService.getObs(obsId);
  
  // check
  assertNotNull(obsSaved);
  assertNotNull(obs);
  assertEquals(obs, obsSaved.getPreviousVersion());
}

相关文章