Search in sources :

Example 1 with TermValueMap

use of com.ibm.streamsx.health.vines.model.TermValueMap in project streamsx.health by IBMStreams.

the class VinesToObservationParser method mapWaveformMessage.

private void mapWaveformMessage(Vines v, VinesParserResult parserResult) {
    // generate Patient ID
    String patientId = "";
    Patient patient = v.getData().getPatient();
    if (patient != null) {
        patientId = patient.get_id();
    }
    // generate device type (same for all observations)
    Device device = new Device();
    device.setId(getDeviceId(v));
    long startTime = 0;
    long period = 0;
    try {
        startTime = toEpoch(v.getData().getBody().getStartTime());
    } catch (ParseException e) {
        String msg = "Error parsing timestamp: error=" + e.getLocalizedMessage() + ", timestamp=" + v.getData().getBody().getStartTime();
        logger.error(msg);
        e.printStackTrace();
        parserResult.addErrorMesage(msg);
    }
    Terms terms = v.getData().getBody().getTerms();
    Channel channel = terms.getChannel(terms.getChannelNames().get(0));
    ReadingSource readingSource = new ReadingSource();
    readingSource.setSourceType(SOURCE_TYPE);
    readingSource.setId(terms.getChannelNames().get(0));
    readingSource.setDeviceId(getDeviceId(v));
    // get the sample rate
    ITerm iterm = channel.getTerm("MDC_ATTR_SAMP_RATE");
    if (iterm instanceof Term) {
        Term term = (Term) iterm;
        // set the multiplier based on the UOM
        // in order to convert the sample rate
        // milliseconds
        double dividend = 1;
        if (term.getUOM().equals("MDC_DIM_SEC")) {
            dividend = 1000;
        }
        ITermValue itv = term.getValue();
        if (itv instanceof TermValueString) {
            String value = ((TermValueString) itv).getValue();
            if (NumberUtils.isNumber(value)) {
                period = Math.round((dividend / Double.valueOf(value)));
            }
        }
    }
    // get the UOM
    iterm = channel.getTerm("MDC_ATTR_SCALE_RANGE");
    String uom = "";
    if (iterm instanceof Term) {
        Term term = (Term) iterm;
        uom = term.getUOM();
    }
    // map waveform samples to observations
    iterm = channel.getTerm("MDC_ATTR_WAV");
    if (iterm instanceof TermArray) {
        TermArray term = (TermArray) iterm;
        for (ITermValue itv : term) {
            if (itv instanceof TermValueMap) {
                TermValueMap tvm = (TermValueMap) itv;
                for (String waveName : tvm.keySet()) {
                    ITerm waveITerm = tvm.get(waveName);
                    if (waveITerm instanceof Term) {
                        Term waveTerm = (Term) waveITerm;
                        ITermValue waveTermValue = waveTerm.getValue();
                        if (waveTermValue instanceof TermValueString) {
                            String waveStr = ((TermValueString) waveTermValue).getValue();
                            List<Double> waveform = WaveformHelper.parseWaveform(waveStr);
                            for (int i = 0; i < waveform.size(); ++i) {
                                Reading reading = new Reading();
                                reading.setReadingType(getReadingType(waveName));
                                reading.setValue(waveform.get(i));
                                reading.setTimestamp(startTime + period * i);
                                reading.setUom(uom);
                                parserResult.addObservation(new Observation(device, patientId, readingSource, reading));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Device(com.ibm.streamsx.health.ingest.types.model.Device) Channel(com.ibm.streamsx.health.vines.model.Channel) Terms(com.ibm.streamsx.health.vines.model.Terms) Patient(com.ibm.streamsx.health.vines.model.Patient) TermValueString(com.ibm.streamsx.health.vines.model.TermValueString) Term(com.ibm.streamsx.health.vines.model.Term) ITerm(com.ibm.streamsx.health.vines.model.ITerm) TermValueString(com.ibm.streamsx.health.vines.model.TermValueString) ITermValue(com.ibm.streamsx.health.vines.model.ITermValue) Reading(com.ibm.streamsx.health.ingest.types.model.Reading) TermArray(com.ibm.streamsx.health.vines.model.TermArray) ReadingSource(com.ibm.streamsx.health.ingest.types.model.ReadingSource) Observation(com.ibm.streamsx.health.ingest.types.model.Observation) ITerm(com.ibm.streamsx.health.vines.model.ITerm) ParseException(java.text.ParseException) DateTimeParseException(java.time.format.DateTimeParseException) TermValueMap(com.ibm.streamsx.health.vines.model.TermValueMap)

Example 2 with TermValueMap

use of com.ibm.streamsx.health.vines.model.TermValueMap in project streamsx.health by IBMStreams.

the class Tests method testWaveformTerm.

@Test
public void testWaveformTerm() {
    Vines vines = VinesMessageParser.fromJson(waveformMessage);
    Terms terms = vines.getData().getBody().getTerms();
    Assert.assertTrue(terms.containsKey("CH01"));
    /* Test waveform */
    Channel chan = terms.getChannel("CH01");
    Assert.assertTrue(chan.containsKey("MDC_ATTR_WAV"));
    ITerm t = chan.getTerm("MDC_ATTR_WAV");
    Assert.assertTrue(t instanceof TermArray);
    TermArray ta = (TermArray) t;
    Assert.assertTrue(ta.size() > 0);
    ITermValue itv = ta.get(0);
    Assert.assertTrue(itv instanceof TermValueMap);
    TermValueMap tvm = (TermValueMap) itv;
    Assert.assertTrue(tvm.containsKey("MDC_PRESS_BLD_ART_ABP"));
    t = tvm.get("MDC_PRESS_BLD_ART_ABP");
    Assert.assertTrue(t instanceof Term);
    Term term = (Term) t;
    itv = term.getValue();
    Assert.assertTrue(itv instanceof TermValueString);
    TermValueString tvs = (TermValueString) itv;
    String waveformString = "115.3125^116.5^117.4375^118.1875^118.8125^119.25^119.625^119.9375^120.125^120.25^120.125^119.875^119.375^118.75^117.9375^117^115.875^114.5^113^11 1.3125^109.8125^108.4375^107.3125^106.375^105.5625^104.875^104.25^103.6875^103.1875^102.8125^102.875^103.5625";
    Assert.assertEquals(waveformString, tvs.getValue());
    /* Test vitals */
    t = chan.getTerm("MDC_ATTR_SCALE_RANGE");
    Assert.assertTrue(t instanceof Term);
    term = (Term) t;
    Assert.assertEquals("", term.getCode());
    Assert.assertEquals("-40", term.getLowerValue());
    Assert.assertEquals("520", term.getUpperValue());
    Assert.assertEquals("MDC_DIM_MMHG", term.getUOM());
    Assert.assertEquals("266016", term.getUOMCode());
}
Also used : ITermValue(com.ibm.streamsx.health.vines.model.ITermValue) Vines(com.ibm.streamsx.health.vines.model.Vines) TermArray(com.ibm.streamsx.health.vines.model.TermArray) Channel(com.ibm.streamsx.health.vines.model.Channel) Terms(com.ibm.streamsx.health.vines.model.Terms) ITerm(com.ibm.streamsx.health.vines.model.ITerm) ITerm(com.ibm.streamsx.health.vines.model.ITerm) Term(com.ibm.streamsx.health.vines.model.Term) TermValueString(com.ibm.streamsx.health.vines.model.TermValueString) TermValueString(com.ibm.streamsx.health.vines.model.TermValueString) TermValueMap(com.ibm.streamsx.health.vines.model.TermValueMap) Test(org.junit.Test)

Example 3 with TermValueMap

use of com.ibm.streamsx.health.vines.model.TermValueMap in project streamsx.health by IBMStreams.

the class Tests method termsTest.

@Test
public void termsTest() {
    Vines vines = VinesMessageParser.fromJson(simpleMessage);
    Terms terms = vines.getData().getBody().getTerms();
    Assert.assertTrue(terms.containsKey("CH1"));
    Assert.assertTrue(terms.containsKey("CH2"));
    Channel chan = terms.getChannel("CH1");
    Assert.assertTrue(chan.containsKey("MDCX_ATTR_EVT_COND"));
    Assert.assertTrue(chan.containsKey("MDC_DEV_PUMP_INFUS_CHAN_DELIVERY"));
    Assert.assertTrue(chan.containsKey("MDC_PUMP_STAT"));
    Assert.assertTrue(chan.containsKey("MDC_PUMP_MODE"));
    Assert.assertTrue(chan.containsKey("MDC_FLOW_FLUID_PUMP"));
    chan = terms.getChannel("CH2");
    Assert.assertTrue(chan.containsKey("MDC_DEV_PUMP_INFUS_CHAN_SOURCE"));
    Assert.assertTrue(chan.containsKey("MDC_DRUG_NAME_TYPE"));
    Assert.assertTrue(chan.containsKey("MDC_CONC_DRUG"));
    Assert.assertTrue(chan.containsKey("MDC_RATE_DOSE"));
    Assert.assertTrue(chan.containsKey("MDC_FLOW_FLUID_PUMP"));
    Assert.assertTrue(chan.containsKey("MDC_VOL_FLUID_TBI"));
    Assert.assertTrue(chan.containsKey("MDC_VOL_FLUID_TBI_REMAIN"));
    Assert.assertTrue(chan.containsKey("MDC_VOL_FLUID_DELIV"));
    Assert.assertTrue(chan.containsKey("MDC_VOL_FLUID_DELIV_TOTAL_SET"));
    /* Test Term containing a Map for the value */
    ITerm t = terms.getChannel("CH1").getTerm("MDCX_ATTR_EVT_COND");
    Assert.assertTrue(t instanceof Term);
    Term term = (Term) t;
    Assert.assertEquals("0", term.getCode());
    ITermValue itv = term.getValue();
    Assert.assertTrue(itv instanceof TermValueMap);
    TermValueMap termValue = (TermValueMap) itv;
    Assert.assertTrue(termValue.containsKey("MDCX_PUMP_DELIV_STOP"));
    t = termValue.get("MDCX_PUMP_DELIV_STOP");
    Assert.assertTrue(t instanceof Term);
    term = (Term) t;
    Assert.assertEquals("0", term.getCode());
    /* Test Term containing a String for the value */
    t = terms.getChannel("CH2").getTerm("MDC_VOL_FLUID_TBI");
    Assert.assertTrue(t instanceof Term);
    term = (Term) t;
    Assert.assertEquals("999999", term.getCode());
    Assert.assertEquals("MDC_DIM_MILLI_L", term.getUOM());
    Assert.assertEquals("263762", term.getUOMCode());
    Assert.assertEquals("2010-07-06T19:36:29-05:00", term.getDate());
    itv = term.getValue();
    Assert.assertTrue(itv instanceof TermValueString);
    TermValueString tvs = (TermValueString) itv;
    Assert.assertEquals("250", tvs.getValue());
}
Also used : ITermValue(com.ibm.streamsx.health.vines.model.ITermValue) Vines(com.ibm.streamsx.health.vines.model.Vines) Channel(com.ibm.streamsx.health.vines.model.Channel) Terms(com.ibm.streamsx.health.vines.model.Terms) ITerm(com.ibm.streamsx.health.vines.model.ITerm) ITerm(com.ibm.streamsx.health.vines.model.ITerm) Term(com.ibm.streamsx.health.vines.model.Term) TermValueString(com.ibm.streamsx.health.vines.model.TermValueString) TermValueMap(com.ibm.streamsx.health.vines.model.TermValueMap) Test(org.junit.Test)

Aggregations

Channel (com.ibm.streamsx.health.vines.model.Channel)3 ITerm (com.ibm.streamsx.health.vines.model.ITerm)3 ITermValue (com.ibm.streamsx.health.vines.model.ITermValue)3 Term (com.ibm.streamsx.health.vines.model.Term)3 TermValueMap (com.ibm.streamsx.health.vines.model.TermValueMap)3 TermValueString (com.ibm.streamsx.health.vines.model.TermValueString)3 Terms (com.ibm.streamsx.health.vines.model.Terms)3 TermArray (com.ibm.streamsx.health.vines.model.TermArray)2 Vines (com.ibm.streamsx.health.vines.model.Vines)2 Test (org.junit.Test)2 Device (com.ibm.streamsx.health.ingest.types.model.Device)1 Observation (com.ibm.streamsx.health.ingest.types.model.Observation)1 Reading (com.ibm.streamsx.health.ingest.types.model.Reading)1 ReadingSource (com.ibm.streamsx.health.ingest.types.model.ReadingSource)1 Patient (com.ibm.streamsx.health.vines.model.Patient)1 ParseException (java.text.ParseException)1 DateTimeParseException (java.time.format.DateTimeParseException)1