Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start moving forced-id inline to ResourceTable #4260

Merged
merged 19 commits into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,5 @@
---
type: change
issue: 4260
title: "Client assigned resource ids are now stored in a new FORCED_ID column in HFR_RESOURCE.
michaelabuckley marked this conversation as resolved.
Show resolved Hide resolved
This is parallel storage to allow gradual upgrade away from the current HFJ_FORCED_ID join table."
michaelabuckley marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -320,6 +320,7 @@ private DaoMethodOutcome doCreateForPostOrPut(T theResource, String theIfNoneExi
String resourceIdBeforeStorage = theResource.getIdElement().getIdPart();
boolean resourceHadIdBeforeStorage = isNotBlank(resourceIdBeforeStorage);
boolean resourceIdWasServerAssigned = theResource.getUserData(JpaConstants.RESOURCE_ID_SERVER_ASSIGNED) == Boolean.TRUE;
entity.setForcedIdValue(resourceIdBeforeStorage);

HookParams hookParams;

Expand Down
Expand Up @@ -86,6 +86,20 @@ public HapiFhirJpaMigrationTasks(Set<String> theFlags) {
init600(); // 20211102 -
init610();
init620();
init630();
}

private void init630() {
Builder version = forVersion(VersionEnum.V6_3_0);

// start forced_id inline migration
version
.onTable("HFJ_RESOURCE")
.addColumn("20221108.1", "FORCED_ID")
.nullable()
// FHIR ids are ascii subset, limited to 64 chars.
.type(ColumnTypeEnum.STRING, 64);
michaelabuckley marked this conversation as resolved.
Show resolved Hide resolved

}

private void init620() {
Expand Down
Expand Up @@ -277,6 +277,9 @@ public class ResourceTable extends BaseHasResource implements Serializable, IBas
@Column(name = "RES_VER")
private long myVersion;

@Column(name= "FORCED_ID", length = 64)
private String myForcedIdValue;

@OneToMany(mappedBy = "myResourceTable", fetch = FetchType.LAZY)
private Collection<ResourceHistoryProvenanceEntity> myProvenance;
michaelabuckley marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -782,4 +785,12 @@ public Collection<SearchParamPresentEntity> getSearchParamPresents() {
}
return mySearchParamPresents;
}

public String getForcedIdValue() {
return myForcedIdValue;
}

public void setForcedIdValue(String theForcedIdValue) {
myForcedIdValue = theForcedIdValue;
}
}
Expand Up @@ -6,7 +6,9 @@
import ca.uhn.fhir.jpa.api.model.HistoryCountModeEnum;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.DaoTestUtils;
import ca.uhn.fhir.jpa.dao.data.IForcedIdDao;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.entity.TagTypeEnum;
import ca.uhn.fhir.jpa.searchparam.SearchParamConstants;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
Expand Down Expand Up @@ -544,6 +546,29 @@ public void testCreateDifferentTypesWithSameForcedId() {
obs = myObservationDao.read(obsId.toUnqualifiedVersionless(), mySrd);
}

/**
* fixme changelog
michaelabuckley marked this conversation as resolved.
Show resolved Hide resolved
* fixme migration
* We are starting a migration to inline forced_id into RESOURCE_TABLE.
* Verify we are populating the new field AND the old join table for a couple of releases to allow smooth upgrades.
*/
@Test
public void testCreateResourceWithForcedId_populatesResourceTableFieldAndJoinTable() {
michaelabuckley marked this conversation as resolved.
Show resolved Hide resolved
String idName = "forcedId";

Patient pat = new Patient();
pat.setId(idName);
IIdType patId = myPatientDao.update(pat, mySrd).getId();
assertEquals("Patient/" + idName, patId.toUnqualifiedVersionless().getValue());

ResourceTable readBackResource = myEntityManager
.createQuery("select rt from ResourceTable rt where rt.myForcedId.myForcedId = 'forcedId'", ResourceTable.class)
.getSingleResult();

assertEquals(idName, readBackResource.getForcedId().getForcedId(), "legacy join populated");
assertEquals(idName, readBackResource.getForcedIdValue(), "inline field poplulated");
}

@Test
public void testCreateDuplicateTagsDoesNotCauseDuplicates() {
Patient p = new Patient();
Expand Down