Now convert pure numeric ids to "npm-<id>".

This commit is contained in:
Kevin Hartmann 2021-05-03 12:55:17 -04:00
parent e8ac24b4df
commit 320e8379b3
4 changed files with 31 additions and 3 deletions

View File

@ -1,4 +1,5 @@
---
type: add
issue: 2590
title: "When resources are created using package load, the new resources will use the same IDs as were provided in with the resource definitions in the package, if they exist"
title: "When resources are created using package load, the new resources will use the same IDs as were provided in with the resource definitions in the package, if they exist.
If the ids are numeric, a prefix of 'npm-' will be added."

View File

@ -337,12 +337,15 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc {
createResource(dao, theResource);
ourLog.info("Created resource with new id");
} else {
if (id.isIdPartValidLong()) {
String newIdPart = "npm-" + id.getIdPart();
id.setParts(id.getBaseUrl(), id.getResourceType(), newIdPart, id.getVersionIdPart());
}
updateResource(dao, theResource);
ourLog.info("Created resource with existing id");
}
} else {
ourLog.info("Updating existing resource matching {}", map.toNormalizedQueryString(myFhirContext));
ourLog.info("Updating existing resource matching {}", map.toNormalizedQueryString(myFhirContext));
theResource.setId(searchResult.getResources(0, 1).get(0).getIdElement().toUnqualifiedVersionless());
DaoMethodOutcome outcome = updateResource(dao, theResource);
if (!outcome.isNop()) {

View File

@ -262,6 +262,30 @@ public class NpmR4Test extends BaseJpaR4Test {
IBaseResource resource = result.getResources(0, 1).get(0);
assertEquals("CodeSystem/shorthand-code-system/_history/1", resource.getIdElement().toString());
});
}
@Test
public void testNumericIdsInstalledWithNpmPrefix() throws Exception {
myDaoConfig.setAllowExternalReferences(true);
// Load a copy of hl7.fhir.uv.shorthand-0.12.0, but with id set to 1 instead of "shorthand-code-system"
byte[] bytes = loadClasspathBytes("/packages/hl7.fhir.uv.shorthand-0.13.0.tgz");
myFakeNpmServlet.myResponses.put("/hl7.fhir.uv.shorthand/0.13.0", bytes);
PackageInstallationSpec spec = new PackageInstallationSpec().setName("hl7.fhir.uv.shorthand").setVersion("0.13.0").setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL);
PackageInstallOutcomeJson outcome = myPackageInstallerSvc.install(spec);
// Be sure no further communication with the server
JettyUtil.closeServer(myServer);
// Search for the installed resource
runInTransaction(() -> {
SearchParameterMap map = SearchParameterMap.newSynchronous();
map.add(StructureDefinition.SP_URL, new UriParam("http://hl7.org/fhir/uv/shorthand/CodeSystem/shorthand-code-system"));
IBundleProvider result = myCodeSystemDao.search(map);
assertEquals(1, result.sizeOrThrowNpe());
IBaseResource resource = result.getResources(0, 1).get(0);
assertEquals("CodeSystem/npm-1/_history/1", resource.getIdElement().toString());
});
}