Commit 64f0841a authored by R.W.Majeed's avatar R.W.Majeed

javadoc, cached patient extension

parent dc7f8635
......@@ -62,6 +62,17 @@ public interface Observation extends ConceptValuePair{
void setStartTime(DateTimeAccuracy date);
ObservationFactory getFactory();
/**
* Access the extension for the given type.
* This will also allocate and assign the extension to
* the observation if this is the first time it is accessed
* for this observation.
*
* @param <T> Extension type
* @param extensionType extension class.
* @return extension object
* @throws IllegalArgumentException
*/
<T> T getExtension(Class<T> extensionType) throws IllegalArgumentException;
<T> void setExtension(Class<T> extensionType, T extension) throws IllegalArgumentException;
......
package de.sekmi.histream.impl;
import java.util.Hashtable;
import java.util.Map;
/**
* Patient extension which caches patients in a {@link Hashtable}.
*
* @author R.W.Majeed
*
*/
public class CachedPatientExtension extends SimplePatientExtension {
private Map<String, PatientImpl> cache;
public CachedPatientExtension() {
cache = new Hashtable<>();
}
@Override
public PatientImpl createInstance(Object... args) {
if( args.length < 1 || !(args[0] instanceof String) ){
throw new IllegalArgumentException("First argument should be String patient id");
}
String pid = (String)args[0];
PatientImpl cached = cache.get(pid);
if( cached == null ){
// not found in cache
// create
cached = super.createInstance(args);
// put in cache
cache.put(pid, cached);
}
return cached;
}
}
......@@ -26,6 +26,13 @@ import de.sekmi.histream.Observation;
import de.sekmi.histream.ext.ExternalSourceType;
import de.sekmi.histream.ext.Patient;
/**
* Basic implementation of patient extension which
* always creates new instances of {@link PatientImpl}.
*
* @author R.W.Majeed
*
*/
public class SimplePatientExtension implements Extension<PatientImpl>{
private final static Class<?>[] TYPES = new Class<?>[]{Patient.class, PatientImpl.class};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment