Search in sources :

Example 1 with Observation

use of com.ibm.streamsx.health.ingest.types.model.Observation 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 Observation

use of com.ibm.streamsx.health.ingest.types.model.Observation in project streamsx.health by IBMStreams.

the class VinesToObservationParser method mapVitalMessage.

private void mapVitalMessage(Vines v, VinesParserResult parserResult) {
    // generate Patient ID
    String patientId = "";
    Patient patient = v.getData().getPatient();
    if (patient != null) {
        patientId = patient.getMRN();
    }
    // generate device type (same for all observations)
    Device device = new Device();
    device.setId(getDeviceId(v));
    Terms terms = v.getData().getBody().getTerms();
    for (String channelName : terms.getChannelNames()) {
        Channel channel = terms.getChannel(channelName);
        // generate ReadingSource
        ReadingSource readingSource = new ReadingSource();
        readingSource.setId(channelName);
        readingSource.setSourceType(SOURCE_TYPE);
        readingSource.setDeviceId(getDeviceId(v));
        // iterate over all terms and generate Readings & Observations
        for (String termName : channel.getTermNames()) {
            ITerm term = channel.getTerm(termName);
            if (term instanceof Term) {
                Reading reading = new Reading();
                Term t = (Term) term;
                ITermValue itv = t.getValue();
                if (itv instanceof TermValueString) {
                    String value = ((TermValueString) itv).getValue();
                    if (!NumberUtils.isNumber(value)) {
                        // skip term as there is no numeric value
                        continue;
                    }
                    String date = t.getDate();
                    long epochTime = 0l;
                    try {
                        epochTime = toEpoch(date);
                    } catch (ParseException e) {
                        String msg = "Error parsing timestamp: error=" + e.getLocalizedMessage() + ", timestamp=" + date;
                        logger.error(msg, e);
                        e.printStackTrace();
                        parserResult.addErrorMesage(msg);
                    }
                    reading.setValue(Double.valueOf(value));
                    reading.setUom(t.getUOM());
                    reading.setTimestamp(epochTime);
                    reading.setReadingType(getReadingType(termName));
                    parserResult.addObservation(new Observation(device, patientId, readingSource, reading));
                }
            } else {
                // Array terms not expected in normal vines messages
                String msg = "Error parsing Vines message: Array terms not expected in normal vines messages.";
                logger.error(msg);
                parserResult.addErrorMesage(msg);
            }
        }
    }
}
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) 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)

Example 3 with Observation

use of com.ibm.streamsx.health.ingest.types.model.Observation in project streamsx.health by IBMStreams.

the class ResolverTests method setup.

@Before
public void setup() {
    readingType = new ReadingType();
    reading = new Reading();
    reading.setReadingType(readingType);
    obs = new Observation();
    obs.setReading(reading);
}
Also used : Reading(com.ibm.streamsx.health.ingest.types.model.Reading) ReadingType(com.ibm.streamsx.health.ingest.types.model.ReadingType) Observation(com.ibm.streamsx.health.ingest.types.model.Observation) Before(org.junit.Before)

Example 4 with Observation

use of com.ibm.streamsx.health.ingest.types.model.Observation in project streamsx.health by IBMStreams.

the class UOMConverterService method build.

public void build() {
    /*
		 * You *MUST* register all available converters here. Otherwise,
		 * you will end up NoConverterFoundExceptions. 
		 */
    ConverterFactory factory = new ConverterFactory();
    factory.registerConverterClass(VoltageConverter.class);
    factory.registerConverterClass(CelciusToFahrenheitConverter.class);
    factory.registerConverterClass(FahrenheitToCelciusConverter.class);
    factory.registerConverterClass(BPSToBPMConverter.class);
    factory.registerConverterClass(BPMToBPSConverter.class);
    /*
		 * Build topology
		 */
    TStream<Observation> obsStream = SubscribeConnector.subscribe(topo, this.subscribeTopic);
    TStream<Observation> updateObsStream = obsStream.modify(new UnitConverter(factory, uomMapFile));
    PublishConnector.publishObservation(updateObsStream, getPublishedTopic());
}
Also used : Observation(com.ibm.streamsx.health.ingest.types.model.Observation) ConverterFactory(com.ibm.streamsx.health.prepare.uomconverter.ConverterFactory)

Example 5 with Observation

use of com.ibm.streamsx.health.ingest.types.model.Observation in project streamsx.health by IBMStreams.

the class HealthDataBeaconService method build.

public void build() {
    TStream<Observation> ecgIStream = topo.periodicSource(new HealthcareDataGenerator(DEFAULT_PATIENT_ID, "src/main/resources/ecgI.csv", ReadingTypeCode.ECG_LEAD_I.getCode()), ECG_PERIOD, ECG_PERIOD_TIMEUNIT);
    TStream<Observation> respStream = topo.periodicSource(new HealthcareDataGenerator(DEFAULT_PATIENT_ID, "src/main/resources/resp.csv", ReadingTypeCode.RESP_RATE.getCode()), RESP_PERIOD, RESP_PERIOD_TIMEUNIT);
    TStream<Observation> abpDiasStream = topo.periodicSource(new ABPDiastolicDataGenerator(DEFAULT_PATIENT_ID), VITALS_PERIOD, VITALS_PERIOD_TIMEUNIT);
    TStream<Observation> abpSysStream = topo.periodicSource(new ABPSystolicDataGenerator(DEFAULT_PATIENT_ID), VITALS_PERIOD, VITALS_PERIOD_TIMEUNIT);
    TStream<Observation> hrStream = topo.periodicSource(new HeartRateDataGenerator(DEFAULT_PATIENT_ID), VITALS_PERIOD, VITALS_PERIOD_TIMEUNIT);
    TStream<Observation> spo2Stream = topo.periodicSource(new SpO2DataGenerator(DEFAULT_PATIENT_ID), VITALS_PERIOD, VITALS_PERIOD_TIMEUNIT);
    TStream<Observation> temperatureStream = topo.periodicSource(new TemperatureDataGenerator(DEFAULT_PATIENT_ID), VITALS_PERIOD, VITALS_PERIOD_TIMEUNIT);
    Set<TStream<Observation>> observations = new HashSet<TStream<Observation>>();
    observations.add(respStream);
    observations.add(abpDiasStream);
    observations.add(abpSysStream);
    observations.add(hrStream);
    observations.add(spo2Stream);
    observations.add(temperatureStream);
    TStream<Observation> allStreams = ecgIStream.union(observations);
    TStream<Observation> multiplePatientStream = allStreams.multiTransform(new Multiplier(numPatientsSupplier, patientPrefixSupplier));
    multiplePatientStream.print();
    PublishConnector.publishObservation(multiplePatientStream, getPublishedTopic());
}
Also used : TStream(com.ibm.streamsx.topology.TStream) ABPDiastolicDataGenerator(com.ibm.streamsx.health.simulate.beacon.generators.ABPDiastolicDataGenerator) TemperatureDataGenerator(com.ibm.streamsx.health.simulate.beacon.generators.TemperatureDataGenerator) SpO2DataGenerator(com.ibm.streamsx.health.simulate.beacon.generators.SpO2DataGenerator) HealthcareDataGenerator(com.ibm.streamsx.health.simulate.beacon.generators.HealthcareDataGenerator) Observation(com.ibm.streamsx.health.ingest.types.model.Observation) HeartRateDataGenerator(com.ibm.streamsx.health.simulate.beacon.generators.HeartRateDataGenerator) ABPSystolicDataGenerator(com.ibm.streamsx.health.simulate.beacon.generators.ABPSystolicDataGenerator) HashSet(java.util.HashSet)

Aggregations

Observation (com.ibm.streamsx.health.ingest.types.model.Observation)9 Reading (com.ibm.streamsx.health.ingest.types.model.Reading)5 Device (com.ibm.streamsx.health.ingest.types.model.Device)4 ReadingSource (com.ibm.streamsx.health.ingest.types.model.ReadingSource)4 ReadingType (com.ibm.streamsx.health.ingest.types.model.ReadingType)2 Channel (com.ibm.streamsx.health.vines.model.Channel)2 ITerm (com.ibm.streamsx.health.vines.model.ITerm)2 ITermValue (com.ibm.streamsx.health.vines.model.ITermValue)2 Patient (com.ibm.streamsx.health.vines.model.Patient)2 Term (com.ibm.streamsx.health.vines.model.Term)2 TermValueString (com.ibm.streamsx.health.vines.model.TermValueString)2 Terms (com.ibm.streamsx.health.vines.model.Terms)2 ParseException (java.text.ParseException)2 DateTimeParseException (java.time.format.DateTimeParseException)2 ConverterFactory (com.ibm.streamsx.health.prepare.uomconverter.ConverterFactory)1 ABPDiastolicDataGenerator (com.ibm.streamsx.health.simulate.beacon.generators.ABPDiastolicDataGenerator)1 ABPSystolicDataGenerator (com.ibm.streamsx.health.simulate.beacon.generators.ABPSystolicDataGenerator)1 HealthcareDataGenerator (com.ibm.streamsx.health.simulate.beacon.generators.HealthcareDataGenerator)1 HeartRateDataGenerator (com.ibm.streamsx.health.simulate.beacon.generators.HeartRateDataGenerator)1 SpO2DataGenerator (com.ibm.streamsx.health.simulate.beacon.generators.SpO2DataGenerator)1