From def35ccbc5b1f566930735bb3e68f5ee3536b3f1 Mon Sep 17 00:00:00 2001 From: Taha Date: Wed, 3 Jan 2024 14:22:50 -0800 Subject: [PATCH] RepositoryService $draft operation not clears out effectiveperiod (#758) * [APHL-784] update test * [APHL-784] remove effective period as part of draft operation * [APHL-784] update test to account for all owned resources * update version --------- Co-authored-by: taha.attari@smilecdr.com --- .../ruler/cr/KnowledgeArtifactProcessor.java | 1 + .../ruler/cr/r4/RepositoryServiceTest.java | 69 ++++++++++++++----- ...rsd-active-transaction-bundle-example.json | 4 ++ 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/KnowledgeArtifactProcessor.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/KnowledgeArtifactProcessor.java index 27a1d9262..ec7de7df2 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/KnowledgeArtifactProcessor.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/KnowledgeArtifactProcessor.java @@ -413,6 +413,7 @@ private List createDraftsOfArtifactAndRelated(MetadataResource if (newResource == null) { KnowledgeArtifactAdapter sourceResourceAdapter = new KnowledgeArtifactAdapter<>(resourceToDraft); + sourceResourceAdapter.setEffectivePeriod(null); newResource = sourceResourceAdapter.copy(); newResource.setStatus(Enumerations.PublicationStatus.DRAFT); newResource.setVersion(draftVersion); diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/RepositoryServiceTest.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/RepositoryServiceTest.java index fc124f182..19d0b6027 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/RepositoryServiceTest.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/RepositoryServiceTest.java @@ -129,6 +129,36 @@ void draftOperation_test() { assertTrue(Canonicals.getVersion(relatedArtifacts.get(1).getResource()).equals(draftedVersion)); } @Test + void draftOperation_no_effectivePeriod_test() { + loadTransaction("ersd-active-transaction-bundle-example.json"); + Library baseLib = getClient() + .read() + .resource(Library.class) + .withId(specificationLibReference.split("/")[1]) + .execute(); + assertTrue(baseLib.hasEffectivePeriod()); + PlanDefinition planDef = getClient() + .read() + .resource(PlanDefinition.class) + .withId("plandefinition-ersd-instance-example") + .execute(); + assertTrue(planDef.hasEffectivePeriod()); + String version = "1.01.21.273"; + Parameters params = parameters(part("version", version) ); + Bundle returnedBundle = getClient().operation() + .onInstance(specificationLibReference) + .named("$draft") + .withParameters(params) + .returnResourceType(Bundle.class) + .execute(); + getMetadataResourcesFromBundle(returnedBundle) + .stream() + .forEach(resource -> { + KnowledgeArtifactAdapter adapter = new KnowledgeArtifactAdapter(resource); + assertFalse(adapter.getEffectivePeriod().hasStart() || adapter.getEffectivePeriod().hasEnd()); + }); + } + @Test void draftOperation_version_conflict_test() { loadTransaction("ersd-active-transaction-bundle-example.json"); loadResource("minimal-draft-to-test-version-conflict.json"); @@ -441,7 +471,26 @@ void releaseResource_propagate_effective_period() { .execute(); assertNotNull(returnResource); - returnResource.getEntry() + getMetadataResourcesFromBundle(returnResource) + .stream() + .forEach(resource -> { + assertNotNull(resource); + if(!resource.getClass().getSimpleName().equals("ValueSet")){ + KnowledgeArtifactAdapter adapter = new KnowledgeArtifactAdapter<>(resource); + assertTrue(adapter.getEffectivePeriod().hasStart()); + Date start = adapter.getEffectivePeriod().getStart(); + Calendar calendar = new GregorianCalendar(); + calendar.setTime(start); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH) + 1; + int day = calendar.get(Calendar.DAY_OF_MONTH); + String startString = year + "-" + month + "-" + day; + assertTrue(startString.equals(effectivePeriodToPropagate)); + } + }); + } + List getMetadataResourcesFromBundle(Bundle bundle) { + return bundle.getEntry() .stream() .map(entry -> entry.getResponse().getLocation()) .map(location -> { @@ -459,24 +508,8 @@ void releaseResource_propagate_effective_period() { default: return null; } - }) - .forEach(resource -> { - assertNotNull(resource); - if(!resource.getClass().getSimpleName().equals("ValueSet")){ - KnowledgeArtifactAdapter adapter = new KnowledgeArtifactAdapter<>(resource); - assertTrue(adapter.getEffectivePeriod().hasStart()); - Date start = adapter.getEffectivePeriod().getStart(); - Calendar calendar = new GregorianCalendar(); - calendar.setTime(start); - int year = calendar.get(Calendar.YEAR); - int month = calendar.get(Calendar.MONTH) + 1; - int day = calendar.get(Calendar.DAY_OF_MONTH); - String startString = year + "-" + month + "-" + day; - assertTrue(startString.equals(effectivePeriodToPropagate)); - } - }); + }).collect(Collectors.toList()); } - @Test void releaseResource_latestFromTx_NotSupported_test() { loadTransaction("ersd-small-approved-draft-bundle.json"); diff --git a/plugin/cr/src/test/resources/ersd-active-transaction-bundle-example.json b/plugin/cr/src/test/resources/ersd-active-transaction-bundle-example.json index 15362d8e5..4ee47f164 100644 --- a/plugin/cr/src/test/resources/ersd-active-transaction-bundle-example.json +++ b/plugin/cr/src/test/resources/ersd-active-transaction-bundle-example.json @@ -27,6 +27,10 @@ "url": "http://hl7.org/fhir/us/ecr/Library/SpecificationLibrary", "version": "1.0.0.23", "approvalDate": "1990-01-01", + "effectivePeriod": { + "start": "2023-01-01", + "end": "2023-12-01" + }, "extension": [ { "url": "http://hl7.org/fhir/StructureDefinition/artifact-releaseLabel",