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

Simplify the pseudonym and split the cached pseudonym and mainzelliste #98

Merged
merged 19 commits into from
Dec 11, 2020
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
63 changes: 63 additions & 0 deletions mvc/src/main/java/org/karnak/cache/CachedPatient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.karnak.cache;

import java.io.Serializable;
import java.time.LocalDate;

public class CachedPatient implements PseudonymPatient, Serializable {
private String pseudonym;
private String patientId;
private String patientName;
private String issuerOfPatientId;

public CachedPatient(String pseudonym, String patientId, String patientName, String issuerOfPatientId) {
this.pseudonym = pseudonym;
this.patientId = patientId;
this.patientName = patientName;
this.issuerOfPatientId = issuerOfPatientId;
}

@Override
public String getPseudonym() {
return pseudonym;
}

public void setPseudonym(String pseudonym) {
this.pseudonym = pseudonym;
}

@Override
public String getPatientId() {
return patientId;
}

public void setPatientId(String patientId) {
this.patientId = patientId;
}
@Override
public String getPatientName() {
return patientName;
}

public void setPatientName(String patientName) {
this.patientName = patientName;
}

@Override
public String getIssuerOfPatientId() {
return issuerOfPatientId;
}

public void setIssuerOfPatientId(String issuerOfPatientId) {
this.issuerOfPatientId = issuerOfPatientId;
}

@Override
public LocalDate getPatientBirthDate() {
return null;
}

@Override
public String getPatientSex() {
return null;
}
}
6 changes: 3 additions & 3 deletions mvc/src/main/java/org/karnak/cache/ExternalIDCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

@Component
public class ExternalIDCache extends PatientClient {
private static final String name = "externalid";
private static final int ttlSeconds = 60*60*24*7;
private static final String NAME = "externalid";
private static final int TTL_SECONDS = 60*60*24*7;

public ExternalIDCache() {
super(name, ttlSeconds);
super(NAME, TTL_SECONDS);
}
}
6 changes: 3 additions & 3 deletions mvc/src/main/java/org/karnak/cache/MainzellisteCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

@Component
public class MainzellisteCache extends PatientClient {
private static final String name = "mainzelliste";
private static final int ttlSeconds = 15*60;
private static final String NAME = "mainzelliste";
private static final int TTL_SECONDS = 15*60;

public MainzellisteCache() {
super(name, ttlSeconds);
super(NAME, TTL_SECONDS);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package org.karnak.ui.extid;

import org.dcm4che6.util.DateTimeUtils;
package org.karnak.cache;

import java.io.Serializable;
import java.time.LocalDate;

public class Patient implements Serializable {

private String extid;
public class MainzellistePatient implements PseudonymPatient, Serializable {
private String pseudonym;
private String patientId;
private String patientFirstName;
private String patientLastName;
private LocalDate patientBirthDate;
private String patientSex;
private String issuerOfPatientId;

public String getExtid() {
return extid;
@Override
public String getPseudonym() {
return pseudonym;
}

public void setExtid(String extid) {
this.extid = extid;
public void setPseudonym(String pseudonym) {
this.pseudonym = pseudonym;
}

@Override
public String getPatientId() {
return patientId;
}
Expand All @@ -31,6 +30,12 @@ public void setPatientId(String patientId) {
this.patientId = patientId;
}

@Override
public String getPatientName() {
return patientFirstName == null || patientFirstName.equals("") ?
patientLastName : String.format("%s^%s", patientLastName == null ? "" : patientLastName, patientFirstName);
}

public String getPatientFirstName() {
return patientFirstName;
}
Expand All @@ -47,6 +52,7 @@ public void setPatientLastName(String patientLastName) {
this.patientLastName = patientLastName;
}

@Override
public LocalDate getPatientBirthDate() {
return patientBirthDate;
}
Expand All @@ -55,13 +61,7 @@ public void setPatientBirthDate(LocalDate patientBirthDate) {
this.patientBirthDate = patientBirthDate;
}

public String getFormatPatientBirthDate() {
if (patientBirthDate != null) {
return DateTimeUtils.formatDA(patientBirthDate);
}
return "";
}

@Override
public String getPatientSex() {
return patientSex;
}
Expand All @@ -70,6 +70,7 @@ public void setPatientSex(String patientSex) {
this.patientSex = patientSex;
}

@Override
public String getIssuerOfPatientId() {
return issuerOfPatientId;
}
Expand All @@ -78,13 +79,10 @@ public void setIssuerOfPatientId(String issuerOfPatientId) {
this.issuerOfPatientId = issuerOfPatientId;
}

public String getPatientNameDicomFormat(){
return patientFirstName == null ? patientLastName : String.format("%s^%s", patientLastName, patientFirstName);
}

public Patient(String extid, String patientId, String patientFirstName, String patientLastName, LocalDate patientBirthDate, String patientSex, String issuerOfPatientId)
public MainzellistePatient(String pseudonym, String patientId, String patientFirstName, String patientLastName,
LocalDate patientBirthDate, String patientSex, String issuerOfPatientId)
{
this.extid = extid;
this.pseudonym = pseudonym;
this.patientId = patientId;
this.patientFirstName = patientFirstName;
this.patientLastName = patientLastName;
Expand Down
25 changes: 12 additions & 13 deletions mvc/src/main/java/org/karnak/cache/PatientClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import org.karnak.ui.extid.Patient;

import java.util.Collection;

public abstract class PatientClient {
// https://docs.hazelcast.org/docs/latest/manual/html-single/#cp-subsystem
private final static int CPMember = 3;
private final static String cluserName = "PatientClient";
private static final String CLUSTER_NAME = "PatientClient";
private static final int CP_MEMBER = 3;
private final String name;
private final HazelcastInstance hazelcastInstance;

Expand All @@ -28,29 +27,29 @@ private Config createConfig(int ttlSeconds) {
// The method setMaxIdleSeconds defines how long the entry stays in the cache without being touched
// mapConfig.setMaxIdleSeconds(20);
config.addMapConfig(mapConfig);
config.setClusterName(cluserName);
config.getCPSubsystemConfig().setCPMemberCount(CPMember);
config.setClassLoader(Patient.class.getClassLoader());
config.setClusterName(CLUSTER_NAME);
config.getCPSubsystemConfig().setCPMemberCount(CP_MEMBER);
config.setClassLoader(PseudonymPatient.class.getClassLoader());
return config;
}

public Patient put(String key, Patient patient) {
IMap<String, Patient> map = hazelcastInstance.getMap(name);
public PseudonymPatient put(String key, PseudonymPatient patient) {
IMap<String, PseudonymPatient> map = hazelcastInstance.getMap(name);
return map.putIfAbsent(key, patient);
}

public Patient get(String key) {
IMap<String, Patient> map = hazelcastInstance.getMap(name);
public PseudonymPatient get(String key) {
IMap<String, PseudonymPatient> map = hazelcastInstance.getMap(name);
return map.get(key);
}

public void remove(String key) {
IMap<String, Patient> map = hazelcastInstance.getMap(name);
IMap<String, PseudonymPatient> map = hazelcastInstance.getMap(name);
map.remove(key);
}

public Collection<Patient> getAll() {
IMap<String, Patient> map = hazelcastInstance.getMap(name);
public Collection<PseudonymPatient> getAll() {
IMap<String, PseudonymPatient> map = hazelcastInstance.getMap(name);
return map.values();
}
}
30 changes: 15 additions & 15 deletions mvc/src/main/java/org/karnak/cache/PatientClientUtil.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package org.karnak.cache;

import org.karnak.profilepipe.utils.PatientMetadata;
import org.karnak.ui.extid.Patient;

public class PatientClientUtil {
public PatientClientUtil() {
private PatientClientUtil() {
throw new IllegalStateException("Utility class");
}

public static String getPseudonym(PatientMetadata patientMetadata, PatientClient cache) {
if (cache != null) {
final String key = generateKey(patientMetadata);
final Patient patient = cache.get(key);
final PseudonymPatient patient = cache.get(key);
if (patient != null && patientMetadata.compareCachedPatient(patient)) {
return patient.getExtid();
return patient.getPseudonym();
}
}
return null;
}

public static String generateKey(String PatientID, String PatientName, String IssuerOfPatientID) {
return PatientID.concat(PatientName).concat(IssuerOfPatientID);
public static String generateKey(String patientID, String patientName, String issuerOfPatientID) {
return patientID.concat(patientName).concat(issuerOfPatientID);
}

public static String generateKey(Patient patient) {
String PatientID = patient.getPatientId();
String PatientName = patient.getPatientNameDicomFormat();
String IssuerOfPatientID = patient.getIssuerOfPatientId();
return generateKey(PatientID, PatientName, IssuerOfPatientID);
public static String generateKey(PseudonymPatient patient) {
String patientID = patient.getPatientId();
String patientName = patient.getPatientName();
String issuerOfPatientID = patient.getIssuerOfPatientId();
return generateKey(patientID, patientName, issuerOfPatientID);
}

public static String generateKey(PatientMetadata patientMetadata) {
String PatientID = patientMetadata.getPatientID();
String PatientName = patientMetadata.getPatientName();
String IssuerOfPatientID = patientMetadata.getIssuerOfPatientID();
return generateKey(PatientID, PatientName, IssuerOfPatientID);
String patientID = patientMetadata.getPatientID();
String patientName = patientMetadata.getPatientName();
String issuerOfPatientID = patientMetadata.getIssuerOfPatientID();
return generateKey(patientID, patientName, issuerOfPatientID);
}
}
17 changes: 17 additions & 0 deletions mvc/src/main/java/org/karnak/cache/PseudonymPatient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.karnak.cache;

import java.time.LocalDate;

public interface PseudonymPatient {
String getPseudonym();

String getPatientId();

String getPatientName();

String getIssuerOfPatientId();

LocalDate getPatientBirthDate();

String getPatientSex();
}
1 change: 0 additions & 1 deletion mvc/src/main/java/org/karnak/data/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.karnak.profilepipe.profilebody.ProfilePipeBody;
import org.karnak.standard.ConfidentialityProfiles;
import org.karnak.standard.StandardDICOM;
import org.karnak.ui.extid.Patient;
import org.karnak.ui.profile.ProfilePipeService;
import org.karnak.ui.profile.ProfilePipeServiceImpl;
import org.slf4j.Logger;
Expand Down
12 changes: 6 additions & 6 deletions mvc/src/main/java/org/karnak/profilepipe/Pseudonym.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import org.dcm4che6.util.TagUtils;
import org.karnak.api.PseudonymApi;
import org.karnak.api.rqbody.Fields;
import org.karnak.cache.MainzellistePatient;
import org.karnak.cache.PatientClient;
import org.karnak.data.AppConfig;
import org.karnak.data.gateway.Destination;
import org.karnak.data.gateway.IdTypes;
import org.karnak.profilepipe.utils.PatientMetadata;
import org.karnak.ui.extid.Patient;
import org.karnak.cache.PatientClientUtil;
import org.karnak.util.SpecialCharacter;
import org.slf4j.Logger;
Expand All @@ -31,7 +31,7 @@ public Pseudonym() {
public String generatePseudonym(Destination destination, DicomObject dcm, String defaultIsserOfPatientID) {
String pseudonym;
if (destination.getSavePseudonym() != null && destination.getSavePseudonym() == false) {
pseudonym = getExtIDInDicom(dcm, destination);
pseudonym = getPseudonymInDicom(dcm, destination);
if (pseudonym == null) {
throw new IllegalStateException("Cannot get a pseudonym in a DICOM tag");
}
Expand All @@ -44,15 +44,15 @@ public String generatePseudonym(Destination destination, DicomObject dcm, String
}
PatientMetadata patientMetadata = new PatientMetadata(dcm, defaultIsserOfPatientID);
try {
return getMainzellistePseudonym(patientMetadata, getExtIDInDicom(dcm, destination),
return getMainzellistePseudonym(patientMetadata, getPseudonymInDicom(dcm, destination),
destination.getIdTypes());
} catch (Exception e) {
LOGGER.error("Cannot get a pseudonym with Mainzelliste API {}", e);
throw new IllegalStateException("Cannot get a pseudonym in cache or with Mainzelliste API");
}
}

private String getExtIDInDicom(DicomObject dcm, Destination destination) {
private String getPseudonymInDicom(DicomObject dcm, Destination destination) {
if (destination.getIdTypes().equals(IdTypes.ADD_EXTID)) {
String cleanTag = destination.getTag().replaceAll("[(),]", "").toUpperCase();
final String tagValue = dcm.getString(TagUtils.intFromHexString(cleanTag)).orElse(null);
Expand Down Expand Up @@ -87,14 +87,14 @@ public String getMainzellistePseudonym(PatientMetadata patientMetadata, String e
}

private void cachingMainzellistePseudonym(String pseudonym, PatientMetadata patientMetadata) {
final Patient patient = new Patient(pseudonym,
final MainzellistePatient mainzellistePatient = new MainzellistePatient(pseudonym,
patientMetadata.getPatientID(),
patientMetadata.getPatientFirstName(),
patientMetadata.getPatientLastName(),
patientMetadata.getLocalDatePatientBirthDate(),
patientMetadata.getPatientSex(),
patientMetadata.getIssuerOfPatientID());
String cacheKey = PatientClientUtil.generateKey(patientMetadata);
mainzellisteCache.put(cacheKey, patient);
mainzellisteCache.put(cacheKey, mainzellistePatient);
}
}
Loading