Skip to content

Commit

Permalink
RepositoryService $draft operation not clears out effectiveperiod (#758)
Browse files Browse the repository at this point in the history
* [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 <taha.attari@smilecdr.com>
  • Loading branch information
TahaAttari and taha.attari@smilecdr.com authored Jan 3, 2024
1 parent 5eb5f32 commit def35cc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ private List<MetadataResource> createDraftsOfArtifactAndRelated(MetadataResource

if (newResource == null) {
KnowledgeArtifactAdapter<MetadataResource> sourceResourceAdapter = new KnowledgeArtifactAdapter<>(resourceToDraft);
sourceResourceAdapter.setEffectivePeriod(null);
newResource = sourceResourceAdapter.copy();
newResource.setStatus(Enumerations.PublicationStatus.DRAFT);
newResource.setVersion(draftVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetadataResource> adapter = new KnowledgeArtifactAdapter<MetadataResource>(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");
Expand Down Expand Up @@ -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<MetadataResource> 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<MetadataResource> getMetadataResourcesFromBundle(Bundle bundle) {
return bundle.getEntry()
.stream()
.map(entry -> entry.getResponse().getLocation())
.map(location -> {
Expand All @@ -459,24 +508,8 @@ void releaseResource_propagate_effective_period() {
default:
return null;
}
})
.forEach(resource -> {
assertNotNull(resource);
if(!resource.getClass().getSimpleName().equals("ValueSet")){
KnowledgeArtifactAdapter<MetadataResource> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit def35cc

Please sign in to comment.