JsonParserHl7OrgDstu2Test.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:hapi-fhir 作者:
@Test
 public void testEncodeBundle() throws InterruptedException {
   Bundle b = new Bundle();

   InstantType pub = InstantType.now();
   b.getMeta().setLastUpdatedElement(pub);
   Thread.sleep(2);

   Patient p1 = new Patient();
   p1.addName().addFamily("Family1");
   p1.setId("1");
   BundleEntryComponent entry = b.addEntry();
   entry.setResource(p1);

   Patient p2 = new Patient();
   p2.setId("Patient/2");
   p2.addName().addFamily("Family2");
   entry = b.addEntry();
   entry.setResource(p2);

   BundleEntryComponent deletedEntry = b.addEntry();
   Patient dp = new Patient();
   deletedEntry.setResource(dp);

   dp.setId(("3"));
   InstantType nowDt = InstantType.withCurrentTime();
   dp.getMeta().setLastUpdatedElement(nowDt);

   String bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
   ourLog.info(bundleString);

   // List<String> strings = new ArrayList<String>();
   // strings.addAll(Arrays.asList("\"published\":\"" + pub.getValueAsString() + "\""));
   // strings.addAll(Arrays.asList("\"id\":\"1\""));
   // strings.addAll(Arrays.asList("\"id\":\"2\"", "\"rel\":\"alternate\"", "\"href\":\"http://foo/bar\""));
   // strings.addAll(Arrays.asList("\"deleted\":\"" + nowDt.getValueAsString() + "\"", "\"id\":\"Patient/3\""));

   //@formatter:off
    String[] strings = new String[] {
        "\"resourceType\": \"Bundle\",",
        "\"lastUpdated\": \"" + pub.getValueAsString() + "\"",
        "\"entry\": [",
        "\"resource\": {",
        "\"id\": \"1\"",
        "\"resource\": {",
        "\"id\": \"2\"",
        "\"resource\": {",
        "\"id\": \"3\"",
        "\"meta\": {",
        "\"lastUpdated\": \"" + nowDt.getValueAsString() + "\"" 
    };
    //@formatter:off
    assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));

    b.getEntry().remove(2);
    bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
    assertThat(bundleString, not(containsString("deleted")));

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号