Add EmpiTargetType to link

This commit is contained in:
Tadgh 2020-07-07 07:51:41 -07:00
parent b7e5705f57
commit 5b402de581
4 changed files with 30 additions and 7 deletions

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.log.Logs;
@ -53,6 +54,8 @@ public class EmpiLinkDaoSvc {
private IEmpiLinkDao myEmpiLinkDao;
@Autowired
private IdHelperService myIdHelperService;
@Autowired
private FhirContext myFhirContext;
@Transactional
public EmpiLink createOrUpdateLinkEntity(IBaseResource thePerson, IBaseResource theTarget, EmpiMatchResultEnum theMatchResult, EmpiLinkSourceEnum theLinkSource, @Nullable EmpiTransactionContext theEmpiTransactionContext) {
@ -62,6 +65,7 @@ public class EmpiLinkDaoSvc {
EmpiLink empiLink = getOrCreateEmpiLinkByPersonPidAndTargetPid(personPid, resourcePid);
empiLink.setLinkSource(theLinkSource);
empiLink.setMatchResult(theMatchResult);
empiLink.setEmpiTargetType(determineTargetType(theTarget));
String message = String.format("Creating EmpiLink from %s to %s -> %s", thePerson.getIdElement().toUnqualifiedVersionless(), theTarget.getIdElement().toUnqualifiedVersionless(), theMatchResult);
theEmpiTransactionContext.addTransactionLogMessage(message);
@ -70,6 +74,11 @@ public class EmpiLinkDaoSvc {
return empiLink;
}
private EmpiTargetType determineTargetType(IBaseResource theTarget) {
String resourceType = myFhirContext.getResourceType(theTarget);
return EmpiTargetType.valueOfCaseInsensitive(resourceType);
}
@Nonnull
public EmpiLink getOrCreateEmpiLinkByPersonPidAndTargetPid(Long thePersonPid, Long theResourcePid) {
@ -191,8 +200,8 @@ public class EmpiLinkDaoSvc {
}
private List<Long> deleteEmpiLinksAndReturnPersonPids(List<EmpiLink> theLinks) {
List<Long> collect = theLinks.stream().map(link -> link.getPersonPid()).collect(Collectors.toList());
myEmpiLinkDao.deleteAll();
List<Long> collect = theLinks.stream().map(EmpiLink::getPersonPid).collect(Collectors.toList());
theLinks.forEach(empiLink -> myEmpiLinkDao.delete(empiLink));
return collect;
}
@ -202,7 +211,6 @@ public class EmpiLinkDaoSvc {
Example<EmpiLink> exampleLink = Example.of(link);
List<EmpiLink> allOfType = myEmpiLinkDao.findAll(exampleLink);
return deleteEmpiLinksAndReturnPersonPids(allOfType);
}
public EmpiLink save(EmpiLink theEmpiLink) {

View File

@ -1,6 +1,12 @@
package ca.uhn.fhir.jpa.entity;
public enum EmpiTargetType {
PATIENT,
PRACTITIONER
PATIENT("patient"),
PRACTITIONER("practitioner");
EmpiTargetType(String thePractitioner) {}
public static EmpiTargetType valueOfCaseInsensitive(String theValue) {
return valueOf(EmpiTargetType.class, theValue.toUpperCase());
}
}

View File

@ -46,11 +46,13 @@ public class EmpiExpungeSvcImpl implements IEmpiExpungeSvc {
@Autowired
private IResourceExpungeService myResourceExpungeService;
@Override
public void expungeEmpiLinks(String theResourceType) {
EmpiTargetType targetType = getTargetTypeOrThrowException(theResourceType);
List<Long> longs = myEmpiLinkDaoSvc.deleteAllEmpiLinksOfTypeAndReturnPersonPids(targetType);
myResourceExpungeService.expungeHistoricalVersionsOfIds(null, longs, new AtomicInteger(longs.size()));
//TODO this expunge does not work!
myResourceExpungeService.expungeCurrentVersionOfResources(null, longs, new AtomicInteger(longs.size()));
}
private EmpiTargetType getTargetTypeOrThrowException(String theResourceType) {
@ -66,7 +68,7 @@ public class EmpiExpungeSvcImpl implements IEmpiExpungeSvc {
@Override
public void expungeEmpiLinks() {
List<Long> longs = myEmpiLinkDaoSvc.deleteAllEmpiLinksAndReturnPersonPids();
myResourceExpungeService.expungeHistoricalVersionsOfIds(null, longs, new AtomicInteger(longs.size()));;
myResourceExpungeService.expungeHistoricalVersionsOfIds(null, longs, new AtomicInteger(longs.size()));
}
}

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.jpa.empi.provider;
import ca.uhn.fhir.jpa.entity.EmpiLink;
import ca.uhn.fhir.model.primitive.IdDt;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.StringType;
@ -11,7 +12,10 @@ import javax.annotation.Nonnull;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
@ -49,8 +53,11 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
@Test
public void testClearPatientLinks() {
assertLinkCount(2);
myEmpiProviderR4.clearEmpiLinks(new StringType("patient"));
assertNoPatientLinksExist();
Person read = myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless());
assertThat(read, is(equalTo(nullValue())));
}
@Test