FhirDevice extends AbstractConnectedDevice { public static Observation createObservation(String metricId, Number value, Date asOf) { Observation obs = new Observation(); obs.setValue(new QuantityDt(value.doubleValue()).setUnits(MDC_DIM_DIMLESS.VALUE).setCode(metricId).setSystem("OpenICE")); obs.setApplies(new DateTimeDt(asOf, TemporalPrecisionEnum.SECOND, TimeZone.getTimeZone("UTC"))); obs.setStatus(ObservationStatusEnum.PRELIMINARY); return obs; } FhirDevice(Subscriber subscriber, Publisher publisher, EventLoop eventLoop); static Observation createObservation(String metricId, Number value, Date asOf); boolean connect(String address); void connect(ScheduledExecutorService executor); void disconnect();  }
@Test public void testObservationOnIce() throws Exception { Observation obs = FhirDevice.createObservation(rosetta.MDC_CO2_RESP_RATE.VALUE, Math.random(), new Date()); FhirDevice.ObservationConverter converter = new FhirDevice.ObservationConverter() { AbstractDevice.InstanceHolder<Numeric> getInstanceHolderForCode(String code) { return null; } }; FhirDevice.ObservationConverter.NumericObservation ice = converter.observationOnIce(obs); Assert.assertNotNull("Failed to convert observation to ice", ice); }
@Test public void testHashornAPIBridge() throws Exception { ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); InputStream is=getClass().getResourceAsStream("JsDeviceDriver0.js"); engine.eval(new InputStreamReader(is)); Invocable invocable = (Invocable) engine; invocable.invokeFunction("start"); Object result = invocable.invokeFunction("readObservations"); invocable.invokeFunction("stop"); Date asOf = new Date(); Set<Observation> set = new HashSet<>(); ScriptObjectMirror som = (ScriptObjectMirror)result; if(som.isArray()) { Set<String> keys = som.keySet(); for(String key: keys) { ScriptObjectMirror o = (ScriptObjectMirror) som.get(key); String code = (String) ((ScriptObjectMirror) o.get("valueQuantity")).get("code"); Number value = (Number) ((ScriptObjectMirror) o.get("valueQuantity")).get("value"); set.add(FhirDevice.createObservation(code, value.doubleValue(), asOf)); } } Assert.assertTrue("Failed to populate dataset", set.size() != 0); }