Untitled
vas
plain_text
a year ago
1.9 kB
8
Indexable
public Mono<JsonNode> updateDeviceObject(InputObservation inputObservation, String orgId, String deviceId, String token) throws Exception {
try {
//Search for the deviceID, if deviceId exists and productDetails payload are not null
JsonNode prodNode = inputObservation.getProductDetails()==null ? null : inputObservation.getProductDetails();
if ((deviceId != null && prodNode != null)) {
return deviceService.searchDevice(orgId, deviceId, token).flatMap(searchResp -> {
org.hl7.fhir.r4.model.Device device = FHIRUtils.getFHIRResource(searchResp.toString(),
org.hl7.fhir.r4.model.Device.class);
devicePayload(prodNode, device);
try {
return deviceService.mapPatientToDevice(orgId, deviceId, token, device);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
//create a deviceID if device id not found and productDetails payload are not null
} else if ((deviceId == null && prodNode != null)) {
Device device = new Device();
//if product details are empty, wont create a device resource
devicePayload(prodNode, device);
return deviceService.createDevice(orgId, token, device);
//No updates required when the productDetails payload are empty. The existing details will come as it is.
} else {
ObjectMapper mapper=new ObjectMapper();
JsonNode actualObj=mapper.readTree(AppConstants.NO_UPDATES_REQUIRED);
return Mono.just(actualObj);
}
} catch (Exception e) {
throw new RuntimeException();
}
}Editor is loading...
Leave a Comment