Skip to content

Commit

Permalink
IPS now supports MDM, now only returns golden records associated to a…
Browse files Browse the repository at this point in the history
… patient
  • Loading branch information
cerbeor committed Sep 16, 2024
1 parent c38f3a2 commit a118ae3
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.immregistries.iis.kernal.fhir.ips;

import ca.uhn.fhir.jpa.ips.api.IIpsGenerationStrategy;
import ca.uhn.fhir.jpa.ips.api.IpsContext;
import ca.uhn.fhir.jpa.ips.api.SectionRegistry;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;

import java.util.List;

public interface ICustomIpsGenerationStrategy extends IIpsGenerationStrategy {

// IBaseBundle everything(IIdType theOriginalSubjectId, SectionRegistry.Section theSection) ;
// List<IBaseResource> extractResourcesFromBundle(IpsContext.IpsSectionContext theIpsSectionContext, IBaseBundle iBaseBundle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class IpsConfig {

@Bean
@Conditional(OnR4Condition.class)
public IIpsGenerationStrategy ipsGenerationStrategyR4() {
public ICustomIpsGenerationStrategy ipsGenerationStrategyR4() {
return new IpsGenerationStrategyR4();
}

@Bean
@Conditional(OnR5Condition.class)
public IIpsGenerationStrategy ipsGenerationStrategyR5() {
public ICustomIpsGenerationStrategy ipsGenerationStrategyR5() {
return new IpsGenerationStrategyR5();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
package org.immregistries.iis.kernal.fhir.ips;

import ca.uhn.fhir.jpa.ips.api.IpsContext;
import ca.uhn.fhir.jpa.ips.api.IpsSectionEnum;
import ca.uhn.fhir.jpa.ips.api.SectionRegistry;
import ca.uhn.fhir.jpa.ips.strategy.DefaultIpsGenerationStrategy;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Address;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.*;
import org.immregistries.iis.kernal.InternalClient.RepositoryClientFactory;
import org.immregistries.iis.kernal.fhir.security.ServletHelper;
import org.immregistries.iis.kernal.mapping.forR4.OrganizationMapperR4;
import org.immregistries.iis.kernal.model.Tenant;
import org.springframework.beans.factory.annotation.Autowired;

public class IpsGenerationStrategyR4 extends DefaultIpsGenerationStrategy {
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static org.immregistries.iis.kernal.InternalClient.FhirRequester.GOLDEN_RECORD;
import static org.immregistries.iis.kernal.InternalClient.FhirRequester.GOLDEN_SYSTEM_TAG;

public class IpsGenerationStrategyR4 extends DefaultIpsGenerationStrategy implements ICustomIpsGenerationStrategy{

@Autowired
OrganizationMapperR4 organizationMapper;
@Autowired
RepositoryClientFactory repositoryClientFactory;

/**
* Constructor
Expand All @@ -32,4 +46,42 @@ public IBaseResource createAuthor() {
return organization;
}

public IBaseBundle everything(IIdType theOriginalSubjectId, SectionRegistry.Section theSection) {
Parameters inParams = new Parameters();
inParams.addParameter("_mdm", true);
inParams.addParameter("type", StringUtils.join(theSection.getResourceTypes(),","));
Bundle bundle = repositoryClientFactory.getFhirClient().operation().onServer().named(JpaConstants.OPERATION_EVERYTHING).withParameters(inParams)
.returnResourceType(Bundle.class).execute();
return bundle;
}

public List<IBaseResource> extractResourcesFromBundle(IpsContext.IpsSectionContext theIpsSectionContext, IBaseBundle iBaseBundle) {
Bundle bundle = (Bundle) iBaseBundle;
return bundle.getEntry().stream()
.filter((bundleEntryComponent -> bundleEntryComponent.hasResource() && theIpsSectionContext.getResourceType().equals(bundleEntryComponent.getResource().getResourceType().name())))
.map(Bundle.BundleEntryComponent::getResource).collect(Collectors.toList());
}

public String mdmLinksParameterIds(IIdType theOriginalSubjectId, SectionRegistry.Section theSection) {
Parameters inParams = new Parameters();
inParams.addParameter("resourceId", theOriginalSubjectId.getValue());
Bundle bundle = repositoryClientFactory.getFhirClient().operation().onServer().named("$mdm-query-links").withParameters(inParams)
.returnResourceType(Bundle.class).execute();
return bundle.getEntry().stream().map(bundleEntryComponent -> bundleEntryComponent.getResource().getId()).collect(Collectors.joining(","));
}

@Override
public boolean shouldInclude(IpsContext.IpsSectionContext theIpsSectionContext, IBaseResource theCandidate) {
if (Objects.requireNonNull(theIpsSectionContext.getSection()) == IpsSectionEnum.IMMUNIZATIONS) {
if (theIpsSectionContext.getResourceType().equals(ResourceType.Immunization.name())) {
Immunization immunization = (Immunization) theCandidate;
if (immunization.getMeta().getTag(GOLDEN_SYSTEM_TAG, GOLDEN_RECORD) == null) {
return false;
}
}
}
return super.shouldInclude(theIpsSectionContext,theCandidate);
}


}
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
package org.immregistries.iis.kernal.fhir.ips;

import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.ips.api.IpsContext;
import ca.uhn.fhir.jpa.ips.api.IpsSectionEnum;
import ca.uhn.fhir.jpa.ips.api.SectionRegistry;
import ca.uhn.fhir.jpa.ips.strategy.DefaultIpsGenerationStrategy;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.provider.BaseJpaResourceProviderPatient;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r5.model.*;
import org.immregistries.iis.kernal.InternalClient.FhirRequester;
import org.immregistries.iis.kernal.InternalClient.FhirRequesterR5;
import org.immregistries.iis.kernal.InternalClient.RepositoryClientFactory;
import org.immregistries.iis.kernal.fhir.security.ServletHelper;
import org.immregistries.iis.kernal.mapping.forR5.OrganizationMapperR5;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static org.immregistries.iis.kernal.InternalClient.FhirRequester.GOLDEN_RECORD;
import static org.immregistries.iis.kernal.InternalClient.FhirRequester.GOLDEN_SYSTEM_TAG;


/**
* prototype, unusable
*/
public class IpsGenerationStrategyR5 extends DefaultIpsGenerationStrategy {
public class IpsGenerationStrategyR5 extends DefaultIpsGenerationStrategy implements ICustomIpsGenerationStrategy {

@Autowired
OrganizationMapperR5 organizationMapper;
@Autowired
BaseJpaResourceProviderPatient<Patient> baseJpaResourceProviderPatient;
@Autowired
RepositoryClientFactory repositoryClientFactory;

/**
* Constructor
*/
Expand All @@ -41,20 +63,41 @@ public IBaseResource createAuthor() {
return organization;
}

public IBaseBundle everything(IIdType theOriginalSubjectId, SectionRegistry.Section theSection) {
Parameters inParams = new Parameters();
inParams.addParameter("_mdm", true);
inParams.addParameter("type", StringUtils.join(theSection.getResourceTypes(),","));
Bundle bundle = repositoryClientFactory.getFhirClient().operation().onServer().named(JpaConstants.OPERATION_EVERYTHING).withParameters(inParams)
.returnResourceType(Bundle.class).execute();
return bundle;
}


public List<IBaseResource> extractResourcesFromBundle(IpsContext.IpsSectionContext theIpsSectionContext, IBaseBundle iBaseBundle) {
Bundle bundle = (Bundle) iBaseBundle;
return bundle.getEntry().stream()
.filter((bundleEntryComponent -> bundleEntryComponent.hasResource() && theIpsSectionContext.getResourceType().equals(bundleEntryComponent.getResource().getResourceType().name())))
.map(Bundle.BundleEntryComponent::getResource).collect(Collectors.toList());
}

public String mdmLinksParameterIds(IIdType theOriginalSubjectId, SectionRegistry.Section theSection) {
Parameters inParams = new Parameters();
inParams.addParameter("resourceId", theOriginalSubjectId.getValue());
Bundle bundle = repositoryClientFactory.getFhirClient().operation().onServer().named("$mdm-query-links").withParameters(inParams)
.returnResourceType(Bundle.class).execute();
return bundle.getEntry().stream().map(bundleEntryComponent -> bundleEntryComponent.getResource().getId()).collect(Collectors.joining(","));
}

@SuppressWarnings("EnhancedSwitchMigration")
@Override
public boolean shouldInclude(IpsContext.IpsSectionContext theIpsSectionContext, IBaseResource theCandidate) {

switch (theIpsSectionContext.getSection()) {
case IMMUNIZATIONS:
if (theIpsSectionContext.getResourceType().equals(ResourceType.Immunization.name())) {
Immunization immunization = (Immunization) theCandidate;
return immunization.getStatus() != Immunization.ImmunizationStatusCodes.ENTEREDINERROR;
if (Objects.requireNonNull(theIpsSectionContext.getSection()) == IpsSectionEnum.IMMUNIZATIONS) {
if (theIpsSectionContext.getResourceType().equals(ResourceType.Immunization.name())) {
Immunization immunization = (Immunization) theCandidate;
if (immunization.getMeta().getTag(GOLDEN_SYSTEM_TAG, GOLDEN_RECORD) == null) {
return false;
}
break;
}
}

return true;
return super.shouldInclude(theIpsSectionContext,theCandidate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.util.BundleBuilder;
import ca.uhn.fhir.util.CompositionBuilder;
import ca.uhn.fhir.util.ResourceReferenceInfo;
import ca.uhn.fhir.util.ValidateUtil;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import org.hl7.fhir.Parameters;
import org.hl7.fhir.instance.model.api.*;
//import org.hl7.fhir.r4.model.*;

Expand All @@ -42,12 +44,12 @@ public class IpsGeneratorSvcIIS extends IpsGeneratorSvcImpl {


private final FhirContext myFhirContext;
private final IIpsGenerationStrategy myGenerationStrategy;
private final ICustomIpsGenerationStrategy myGenerationStrategy;
private final DaoRegistry myDaoRegistry;

public IpsGeneratorSvcIIS(FhirContext theFhirContext, IIpsGenerationStrategy theGenerationStrategy, DaoRegistry theDaoRegistry) {
super(theFhirContext, theGenerationStrategy, theDaoRegistry);
this.myGenerationStrategy = theGenerationStrategy;
this.myGenerationStrategy = (ICustomIpsGenerationStrategy) theGenerationStrategy;
this.myDaoRegistry = theDaoRegistry;
this.myFhirContext = theFhirContext;
}
Expand Down Expand Up @@ -157,7 +159,10 @@ private void determineInclusionsForSection(

SearchParameterMap searchParameterMap = new SearchParameterMap();
String subjectSp = determinePatientCompartmentSearchParameterName(nextResourceType);
searchParameterMap.add(subjectSp, new ReferenceParam(theOriginalSubjectId));
/**
* Mdm activated
*/
searchParameterMap.add(subjectSp, new ReferenceParam(theOriginalSubjectId).setMdmExpand(true));

IpsSectionEnum sectionEnum = theSection.getSectionEnum();
IpsContext.IpsSectionContext ipsSectionContext =
Expand Down

0 comments on commit a118ae3

Please sign in to comment.