Commit 743615a1 authored by R.W.Majeed's avatar R.W.Majeed

scripting moved to separate project

parent b64dbebb
package de.sekmi.histream.etl.scripting;
import java.util.Collection;
import java.util.Collections;
import jdk.nashorn.api.scripting.AbstractJSObject;
public class FactsArray extends AbstractJSObject{
private Facts facts;
public FactsArray(Facts facts){
this.facts = facts;
}
@Override
public Object getMember(String name) {
return facts.get(name);
}
@Override
public Object getSlot(int index) {
return facts.get(index);
}
@Override
public boolean hasMember(String name) {
return facts.firstIndexOf(name) != -1;
}
@Override
public boolean hasSlot(int slot) {
return slot >= 0 && slot < facts.facts().size();
}
@Override
public boolean isArray() {
return true;
}
@Override
public boolean isStrictFunction() {
return true;
}
@Override
public void removeMember(String name) {
facts.remove(name);
}
@Override
public Collection<Object> values() {
return Collections.unmodifiableList(facts.facts());
}
}
.settings/
.classpath
.project
target/
Support for native JS objects?
-> import jdk.nashorn.api.scripting.AbstractJSObject;
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>HIStream : Javascript support</name>
<groupId>de.sekmi.histream</groupId>
<artifactId>histream-js</artifactId>
<version>0.8-SNAPSHOT</version>
<parent>
<groupId>de.sekmi.histream</groupId>
<artifactId>histream</artifactId>
<version>0.8-SNAPSHOT</version>
</parent>
<build>
</build>
<dependencies>
<dependency>
<groupId>de.sekmi.histream</groupId>
<artifactId>histream-core</artifactId>
<version>0.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package de.sekmi.histream.etl.scripting;
package de.sekmi.histream.scripting;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.Observation;
......
package de.sekmi.histream.etl.scripting;
package de.sekmi.histream.scripting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationFactory;
/**
* Javascript compatible interface for manipulating a list of
* facts. Facts can be changed, removed, added.
* <p>
* Use {@link #setObservations(List)} to specify the list
* of observations. The provided list is edited in place.
* </>
* @author R.W.Majeed
*
*/
public class Facts {
private ArrayList<Fact> facts;
private List<Fact> facts;
private List<Observation> sourceList;
private ObservationFactory factory;
private String patientId;
private String encounterId;
private DateTimeAccuracy defaultStartTime;
public Facts(ObservationFactory factory, String patientId, String encounterId, DateTimeAccuracy defaultStartTime){
this.factory = factory;
this.patientId = patientId;
......@@ -23,7 +33,8 @@ public class Facts {
this.defaultStartTime = defaultStartTime;
this.facts = new ArrayList<>();
}
public void setObservations(Collection<Observation> observations){
public void setObservations(List<Observation> observations){
sourceList = observations;
facts.clear();
observations.stream().map(o -> new Fact(o)).forEach(facts::add);
}
......@@ -37,6 +48,7 @@ public class Facts {
Observation o = factory.createObservation(patientId, conceptId, defaultStartTime);
o.setEncounterId(encounterId);
Fact f = new Fact(o);
sourceList.add(o);
facts.add(f);
return f;
}
......@@ -53,7 +65,11 @@ public class Facts {
if( i == -1 ){
return null;
}else{
return facts.remove(i);
Fact f = facts.remove(i);
Observation o = sourceList.remove(i);
// verify that fact and observation are associated
assert f.getObservation() == o;
return f;
}
}
public Fact get(int index){
......
......@@ -4,4 +4,4 @@
* @author R.W.Majeed
*
*/
package de.sekmi.histream.etl.scripting;
\ No newline at end of file
package de.sekmi.histream.scripting;
\ No newline at end of file
package de.sekmi.histream.etl.scripting;
package de.sekmi.histream.scripting;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
......@@ -35,7 +39,10 @@ public class TestFacts {
factory.createObservation("P1", "C3", DateTimeAccuracy.parsePartialIso8601("2011-02-01"))
};
Facts f = new Facts(factory, "P1", "V1", defaultStart);
List<Observation> list = new ArrayList<>();
Collections.addAll(list, facts);
f.setObservations(list);
engine.put("facts", f);
engine.eval("facts.add('C4')");
......
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