Commit 8f653f87 authored by R.W.Majeed's avatar R.W.Majeed

Parsing of flat observation files (incomplete)

parent 45bebff7
......@@ -4,7 +4,12 @@ import java.util.Enumeration;
import de.sekmi.histream.ext.ExternalSourceType;
/**
* Observation of a single event or a single fact assigned to a single patient.
* TODO include java.util.stream API
* @author Raphael
*
*/
public interface Observation extends ConceptValuePair, ExternalSourceType{
String getPatientId();
String getEncounterId();
......
package de.sekmi.histream.impl;
import java.util.function.Consumer;
import java.util.regex.Pattern;
/**
* Converts a stream of lines to flat observation events
* @author Raphael
*
*/
public class FlatObservationLineReader implements Consumer<String>{
private FlatObservationWriter writer;
private Pattern fieldSeparator;
private static final int maxFields = 8;
public FlatObservationLineReader(FlatObservationWriter writer){
this.writer = writer;
this.fieldSeparator = Pattern.compile("\\t");
}
@Override
public void accept(String line) {
if( line.length() == 0 ){
// empty line
return;
}
char first = line.charAt(0);
if( first == '#' ){
// comment
}else if( first == '@' ){
// command
// TODO @meta, @concept, @group
}else{
String[] fields = fieldSeparator.split(line, maxFields);
writer.writeObservation(fields);
}
}
}
package de.sekmi.histream.impl;
import java.util.Hashtable;
import java.util.Map;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Visit;
/**
* Reads a flat file with content type text/tab-separated-values.
* @author Raphael
*
*/
public class FlatObservationProvider extends AbstractObservationProvider implements FlatObservationWriter {
static private Class<?>[] supportedExtensions = new Class<?>[]{Patient.class,Visit.class};
private Map<String, String> meta;
private Map<String, String> conceptMap;
public FlatObservationProvider() {
meta = new Hashtable<>();
}
@Override
public Class<?>[] getSupportedExtensions() {
return supportedExtensions;
}
@Override
public void writeMeta(String key, String value) {
meta.put(key, value);
}
@Override
public void writeConceptMap(String concept, String map) {
conceptMap.put(concept, map);
}
@Override
public void beginGroup() {
// TODO build group of following observations
}
@Override
public void endGroup() {
// TODO group finished, provide observation
}
@Override
public void writeObservation(String[] fields) {
// TODO Auto-generated method stub
}
}
package de.sekmi.histream.impl;
public interface FlatObservationWriter {
void writeMeta(String meta, String value);
void writeConceptMap(String concept, String map);
void beginGroup();
void endGroup();
void writeObservation(String[] fields);
}
package de.sekmi.histream;
import java.io.BufferedReader;
import java.io.FileReader;
import org.junit.Test;
public class TestLoadFlatText {
@Test
public void loadFlatText() throws Exception{
BufferedReader buf = new BufferedReader(new FileReader("src/test/resources/fwh-flat.txt"));
//buf.lines().forEach(action);
buf.lines();
buf.close();
}
}
......@@ -9,21 +9,37 @@
@concept(patient.birthdate)=geb
@concept(patient.deathdate)=gest
@concept(patient.sex)=sex
@concept(visit.start)=vstart
@concept(visit.end)=vend
@concept(patient.surname)=psurname
@concept(patient.names)=pnames
@concept(visit)=visit
# visit start, end, location, provider
# eav eintrge folgen
# patid fallid konzept wert typ start ende einheit
1 2 geb 1950
1 2 gest 2012
1 2 sex F
# patid fallid konzept typ wert start ende einheit provider location
XX12345 XXE12345 geb 2001-01-01
XX12345 XXE12345 gest 2020
XX12345 XXE12345 sex F
XX12345 XXE12345 psurname Dampf
XX12345 XXE12345 pnames A B
XX12345 XXE12345 visit @ @ 2014-01-01T10:30:00 2014-01-05T10:30:00 @ xxxa Zuhause
# wie gruppierte werte?
# z.B. so: erste zeile enthlt konzeptcode, weitere Zeilen modifier codes
# dabei muss patid,fallid,zeitstempel gleich sein.
@modifier(start)
1 2 gruppe1 123 N 2012
1 2 modif1 halo T 2012
1 2 modif2 888 N 2012
@modifier(end)
# normale werte
XX12345 XXE12345 T:date:secs @ @ 2014-09-07T10:40:03
XX12345 XXE12345 T:date:mins @ @ 2014-09-07T10:40
XX12345 XXE12345 T:date:hours @ @ 2014-09-07T10
XX12345 XXE12345 T:date:day @ @ 2014-09-07
XX12345 XXE12345 T:date:month @ @ 2014-09
XX12345 XXE12345 T:date:year @ @ 2014
XX12345 XXE12345 T:type:str str abc123
XX12345 XXE12345 T:type:int int 123
# value attributes can be used in elements eav-item and value -->
XX12345 XXE12345 T:type:dec dec 123.456 mm
# test group items
@group(start)
XX12345 XXE12345 T:group:1 nil
XX12345 XXE12345 T:mod:1 nil
XX12345 XXE12345 T:mod:2 str def456
XX12345 XXE12345 T:mod:3 dec 78.9 mm A
@group(end)
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