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

4917 refactor nicknaming hapi with version bump #4955

Merged
merged 25 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hapi-deployable-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
4 changes: 2 additions & 2 deletions hapi-fhir-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-bom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<packaging>pom</packaging>
<name>HAPI FHIR BOM</name>

<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-checkstyle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/hapi-fhir-cli-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/hapi-fhir-cli-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-cli</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-client-okhttp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
type: fix
issue: 4917
title: "Matching algorithms have been refactored to allow
greater flexibility in setting and defining nicknames
as well as allowing bean injection into matcher classes.
"
2 changes: 1 addition & 1 deletion hapi-fhir-jacoco/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jaxrsserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.jpa.searchparam.nickname;
package ca.uhn.fhir.jpa.nickname;

import javax.annotation.Nonnull;
import java.io.BufferedReader;
Expand All @@ -33,19 +33,30 @@ class NicknameMap {
private final Map<String, List<String>> myFormalToNick = new HashMap<>();
private final Map<String, List<String>> myNicknameToFormal = new HashMap<>();

private final List<String> myBadRows = new ArrayList<>();

void load(Reader theReader) throws IOException {
try (BufferedReader reader = new BufferedReader(theReader)) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
String key = parts[0];
List<String> values = new ArrayList<>(Arrays.asList(parts).subList(1, parts.length));
add(key, values);
if (parts.length > 1) {
String key = parts[0];
List<String> values = new ArrayList<>(Arrays.asList(parts).subList(1, parts.length));
add(key, values);
} else {
myBadRows.add(line);
}
}
}
}

private void add(String theKey, List<String> theValues) {
void clear() {
myFormalToNick.clear();
myNicknameToFormal.clear();
}

void add(String theKey, List<String> theValues) {
myFormalToNick.put(theKey, theValues);
for (String value : theValues) {
myNicknameToFormal.putIfAbsent(value, new ArrayList<>());
Expand All @@ -57,14 +68,22 @@ int size() {
return myFormalToNick.size();
}

boolean isEmpty() {
return size() == 0;
}

List<String> getBadRows() {
return myBadRows;
}

@Nonnull
List<String> getNicknamesFromFormalName(String theName) {
public List<String> getNicknamesFromFormalName(String theName) {
List<String> result = myFormalToNick.get(theName);
return result == null ? new ArrayList<>() : result;
}

@Nonnull
List<String> getFormalNamesFromNickname(String theNickname) {
public List<String> getFormalNamesFromNickname(String theNickname) {
List<String> result = myNicknameToFormal.get(theNickname);
return result == null ? new ArrayList<>() : result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.jpa.searchparam.nickname;
package ca.uhn.fhir.jpa.nickname;

import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.i18n.Msg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

Expand All @@ -32,22 +36,40 @@
import java.util.List;
import java.util.Set;

/**
* Nickname service is used to load nicknames
* via a file that contains rows of comma separated names that are
* "similar" or nicknames of each other.
* -
* If no nickname resource is provided, nicknames/names.csv will be used instead.
* -
* If one is to be provided, it must be provided before nickname svc is invoked
*/
public class NicknameSvc {
private final NicknameMap myNicknameMap = new NicknameMap();
private static final Logger ourLog = LoggerFactory.getLogger(NicknameSvc.class);

public NicknameSvc() throws IOException {
Resource nicknameCsvResource = new ClassPathResource("/nickname/names.csv");
try (InputStream inputStream = nicknameCsvResource.getInputStream()) {
try (Reader reader = new InputStreamReader(inputStream)) {
myNicknameMap.load(reader);
}
}
private NicknameMap myNicknameMap;

private Resource myNicknameResource;

public NicknameSvc() {

}

public void setNicknameResource(Resource theNicknameResource) {
myNicknameResource = theNicknameResource;
}

public int size() {
ensureMapInitialized();
return myNicknameMap.size();
}

public List<String> getBadRows() {
ensureMapInitialized();
return myNicknameMap.getBadRows();
}

public Collection<String> getEquivalentNames(String theName) {
Set<String> retval = new HashSet<>(getNicknamesFromFormalName(theName));

Expand All @@ -64,11 +86,34 @@ public Collection<String> getEquivalentNames(String theName) {

@Nonnull
List<String> getNicknamesFromFormalName(String theName) {
ensureMapInitialized();
return myNicknameMap.getNicknamesFromFormalName(theName);
}

@Nonnull
List<String> getFormalNamesFromNickname(String theNickname) {
ensureMapInitialized();
return myNicknameMap.getFormalNamesFromNickname(theNickname);
}

private void ensureMapInitialized() {
if (myNicknameResource == null) {
myNicknameResource = new ClassPathResource("/nickname/names.csv");
}

if (myNicknameMap == null) {
myNicknameMap = new NicknameMap();
}
if (myNicknameMap.isEmpty()) {
try {
try (InputStream inputStream = myNicknameResource.getInputStream()) {
try (Reader reader = new InputStreamReader(inputStream)) {
myNicknameMap.load(reader);
}
}
} catch (IOException e) {
throw new ConfigurationException(Msg.code(2234) + "Unable to load nicknames", e);
}
}
}
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ca.uhn.fhir.jpa.searchparam.nickname;
package ca.uhn.fhir.jpa.nickname;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ca.uhn.fhir.jpa.searchparam.nickname;
package ca.uhn.fhir.jpa.nickname;

import org.junit.jupiter.api.Test;

Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpaserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>6.7.3-SNAPSHOT</version>
<version>6.7.6-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
import ca.uhn.fhir.jpa.partition.PartitionManagementProvider;
import ca.uhn.fhir.jpa.partition.RequestPartitionHelperSvc;
import ca.uhn.fhir.jpa.provider.DiffProvider;
import ca.uhn.fhir.jpa.provider.ProcessMessageProvider;
import ca.uhn.fhir.jpa.provider.InstanceReindexProvider;
import ca.uhn.fhir.jpa.provider.ProcessMessageProvider;
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider;
import ca.uhn.fhir.jpa.provider.ValueSetOperationProvider;
Expand Down Expand Up @@ -149,7 +149,6 @@
import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.searchparam.config.SearchParamConfig;
import ca.uhn.fhir.jpa.searchparam.extractor.IResourceLinkResolver;
import ca.uhn.fhir.jpa.searchparam.nickname.NicknameInterceptor;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamProvider;
import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc;
import ca.uhn.fhir.jpa.sp.SearchParamPresenceSvcImpl;
Expand Down Expand Up @@ -198,7 +197,6 @@
import org.springframework.transaction.PlatformTransactionManager;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Date;

@Configuration
Expand Down Expand Up @@ -772,12 +770,6 @@ public UnknownCodeSystemWarningValidationSupport unknownCodeSystemWarningValidat
return new UnknownCodeSystemWarningValidationSupport(theFhirContext);
}

@Lazy
@Bean
public NicknameInterceptor nicknameInterceptor() throws IOException {
return new NicknameInterceptor();
}

@Bean
public ISynchronousSearchSvc synchronousSearchSvc() {
return new SynchronousSearchSvcImpl();
Expand Down
Loading