Browse Source

为啥 ~~~

master
sige 2 years ago
parent
commit
84cee26381
  1. 14
      src/main/java/com/dreamworks/boditech/driver/Device.java
  2. 19
      src/main/java/com/dreamworks/boditech/driver/connection/ComLisClient.java
  3. 2
      src/main/java/com/dreamworks/boditech/driver/connection/ComWebsocketClient.java
  4. 6
      src/main/java/com/dreamworks/boditech/driver/entity/LisTestInfo.java
  5. 7
      src/main/java/com/dreamworks/boditech/driver/entity/TaskBatchTubeTestInfo.java
  6. 73
      src/main/java/com/dreamworks/boditech/driver/task/TaskBatchTubePrepare.java
  7. 39
      src/main/java/com/dreamworks/boditech/driver/task/TaskTestBase.java
  8. 4
      src/main/java/com/dreamworks/boditech/driver/task/TaskTestEmergency.java
  9. 12
      src/main/java/com/dreamworks/boditech/driver/task/TaskTestRegular.java
  10. 9
      src/main/java/com/dreamworks/boditech/driver/task/step/Step.java
  11. 22
      src/main/java/com/dreamworks/boditech/driver/task/step/StepBase.java
  12. 1
      src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java
  13. 5
      src/main/java/com/dreamworks/boditech/entity/ParamTestRegularAppendTask.java
  14. 19
      src/main/java/com/dreamworks/boditech/entity/Test.java
  15. 15
      src/main/java/com/dreamworks/boditech/entity/TestStepLogEntry.java
  16. 20
      src/main/java/com/dreamworks/boditech/mapper/TestMapper.java
  17. 19
      src/main/java/com/dreamworks/boditech/mapper/TestStepMapper.java
  18. 4
      src/main/java/com/dreamworks/boditech/service/DeviceService.java
  19. 42
      src/main/java/com/dreamworks/boditech/service/TestService.java

14
src/main/java/com/dreamworks/boditech/driver/Device.java

@ -3,13 +3,11 @@ import com.dreamworks.boditech.driver.actuator.*;
import com.dreamworks.boditech.driver.connection.ClientRequest;
import com.dreamworks.boditech.driver.connection.ComSerialPort;
import com.dreamworks.boditech.driver.connection.ComWebsocket;
import com.dreamworks.boditech.driver.connection.ComLisClient;
import com.dreamworks.boditech.driver.consumable.*;
import com.dreamworks.boditech.driver.entity.DeviceLogEntry;
import com.dreamworks.boditech.mapper.DeviceLogMapper;
import com.dreamworks.boditech.mapper.ProjectMapper;
import com.dreamworks.boditech.service.ProjectService;
import com.dreamworks.boditech.service.RuntimeOptionService;
import com.dreamworks.boditech.service.RuntimeVariableService;
import com.dreamworks.boditech.service.*;
import com.dreamworks.boditech.utils.MyByteBuffer;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
@ -21,13 +19,11 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class Device {
private static final Logger LOG = LoggerFactory.getLogger(Device.class);
public static final Logger LOG = LoggerFactory.getLogger(Device.class);
@Value("${app.device.connectionType}")
private String connectionType;
@Value("${app.device.debug}")
@ -44,6 +40,10 @@ public class Device {
public DeviceLogMapper deviceLogMapper;
@Resource
public RuntimeVariableService runtimeVariableService;
@Resource
public TestService testService;
@Resource
public ComLisClient lis;
// consumable : test cards
public final CsmTestCardManager testCards = new CsmTestCardManager(this);

19
src/main/java/com/dreamworks/boditech/driver/connection/ComLisClient.java

@ -0,0 +1,19 @@
package com.dreamworks.boditech.driver.connection;
import com.dreamworks.boditech.driver.entity.LisTestInfo;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@Component
public class ComLisClient {
// request test info
public LisTestInfo requestTestInfo( String barCode ) {
if ( barCode.isEmpty() ) {
return null;
}
LisTestInfo testInfo = new LisTestInfo();
testInfo.sampleType = "WB";
testInfo.projectNames = new ArrayList<>();
testInfo.projectNames.add("hsCRP");
return testInfo;
}
}

2
src/main/java/com/dreamworks/boditech/driver/connection/ComWebsocketClient.java

@ -107,7 +107,7 @@ public class ComWebsocketClient extends WebSocketClient {
@Override
public void onOpen(ServerHandshake serverHandshake) {
LOG.info("device connected");
LOG.info("device connected : {}", this.uri);
}
@Override

6
src/main/java/com/dreamworks/boditech/driver/entity/LisTestInfo.java

@ -0,0 +1,6 @@
package com.dreamworks.boditech.driver.entity;
import java.util.List;
public class LisTestInfo {
public List<String> projectNames;
public String sampleType;
}

7
src/main/java/com/dreamworks/boditech/driver/entity/TaskBatchTubeTestInfo.java

@ -1,15 +1,18 @@
package com.dreamworks.boditech.driver.entity;
import java.util.List;
public class TaskBatchTubeTestInfo {
// index
public Integer tubeIndex;
// patient id
public String patientId;
public String patientCode;
// barcode
public String barcode;
// test tube
public String testTube;
// project
public String project;
public List<String> projectNames;
// sample type
public String blood;
// sample process

73
src/main/java/com/dreamworks/boditech/driver/task/TaskBatchTubePrepare.java

@ -1,7 +1,9 @@
package com.dreamworks.boditech.driver.task;
import com.dreamworks.boditech.driver.Device;
import com.dreamworks.boditech.driver.actuator.*;
import com.dreamworks.boditech.driver.entity.LisTestInfo;
import com.dreamworks.boditech.driver.entity.TaskBatchTubeTestInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class TaskBatchTubePrepare extends TaskBase {
@ -13,6 +15,10 @@ public class TaskBatchTubePrepare extends TaskBase {
private ActModuleTestTubeRackMovement testTubeMovement;
// testTubeFeedMotor
private ActMotor testTubeFeedMotor;
// testTubeExistsStatus
private boolean[] testTubeExistsStatus;
// testTubeBarcodes
private String[] testTubeBarcodes;
@Override
public void execute( Executor executor ) {
@ -22,59 +28,84 @@ public class TaskBatchTubePrepare extends TaskBase {
this.testTubeFeedMotor = (ActMotor)this.device.getActuator(ActuatorModule.TEST_TUBE_RACK_FEED_MOTOR);
this.testTubeMovement = (ActModuleTestTubeRackMovement)this.device.getActuator(ActuatorModule.TEST_TUBE_RACK_MOVEMENT);
ActMotor testTubeMoveMotor = (ActMotor)this.device.getActuator(ActuatorModule.TEST_TUBE_RACK_MOVE_MOTOR);
ActMotor testTubeRotateMotor = (ActMotor)this.device.getActuator(ActuatorModule.TEST_TUBE_SHAKING_ROTATE_MOTOR);
ActMotor testTubeRotateMotor = (ActMotor) this.device.getActuator(ActuatorModule.TEST_TUBE_SHAKING_ROTATE_MOTOR);
this.testTubeRackFeed();
// 02. 检查试管有无
boolean[] testTubeExistsStatus = new boolean[10];
this.testTubeExistsStatus = new boolean[10];
int tubeDistance = this.device.getLocationByName("testTubeRackTubeDistance");
int existsCheckStartPos = this.device.getLocationByName("testTubeRackExistsCheckStart");
for ( int i = 0; i < 10; i++ ) {
testTubeMoveMotor.moveTo(existsCheckStartPos + i * tubeDistance);
Integer isExists = this.testTubeMovement.readIO(ActModuleTestTubeRackMovement.IO_TEST_TUBE_EXISTS);
testTubeExistsStatus[i] = Objects.equals(this.device.getIOValueByName("testTubeRackTubeExistsYes"), isExists);
this.testTubeExistsStatus[i] = Objects.equals(this.device.getIOValueByName("testTubeRackTubeExistsYes"), isExists);
}
// 03. 逐个扫描试管
ActCodeScanner testTubeScanner = (ActCodeScanner)this.device.getActuator(ActuatorModule.TEST_TUBE_RACK_SCANNER);
String[] testTubeBarcodes = new String[10];
this.testTubeBarcodes = new String[10];
int scanStartPos = this.device.getLocationByName("testTubeRackScanStart");
for ( int i = 0; i < 10; i++ ) {
if ( !testTubeExistsStatus[i] ) {
testTubeBarcodes[i] = "";
if ( !this.testTubeExistsStatus[i] ) {
this.testTubeBarcodes[i] = "";
continue ;
}
testTubeMoveMotor.moveTo(scanStartPos + i * tubeDistance);
testTubeRotateMotor.rotate(ActMotor.ROTATE_DIRECTION_CLOCKWISE);
String code = testTubeScanner.scan(1000);
testTubeRotateMotor.reset();
testTubeBarcodes[i] = code;
this.testTubeBarcodes[i] = code;
}
// 04. 扫描完成后推送到预备区域
testTubeMoveMotor.moveTo("testTubeRackStandby");
// 05. 追加测试到执行器
for ( TaskBatchTubeTestInfo test : this.tests ) {
if ( !testTubeExistsStatus[test.tubeIndex] ) {
continue;
}
TaskTestRegular task = new TaskTestRegular();
task.tubeIndex = test.tubeIndex;
task.patientId = test.patientId;
task.barcode = test.barcode.isEmpty() ? testTubeBarcodes[test.tubeIndex] : task.barcode;
task.tubeType = test.testTube;
task.projectName = test.project;
task.bloodType = test.blood;
executor.appendTask(task);
}
this.appendTestTasksToExecutor(executor);
TaskBatchTubeExit exitTask = new TaskBatchTubeExit();
executor.appendTask(exitTask);
this.setStatus(Task.STATUS_FINISHED);
}
// 追加测试到执行器
private void appendTestTasksToExecutor(Executor executor) {
for ( TaskBatchTubeTestInfo test : this.tests ) {
if ( !this.testTubeExistsStatus[test.tubeIndex] ) {
continue;
}
String barCode = test.barcode;
if ( barCode.isEmpty() ) {
barCode = this.testTubeBarcodes[test.tubeIndex];
}
// 获取LIS测试信息
LisTestInfo lisTestInfo = device.lis.requestTestInfo(barCode);
if ( null == lisTestInfo ) {
lisTestInfo = new LisTestInfo();
lisTestInfo.sampleType = "";
lisTestInfo.projectNames = new ArrayList<>();
}
lisTestInfo.sampleType = test.blood.isEmpty() ? lisTestInfo.sampleType : test.blood;
lisTestInfo.projectNames = test.projectNames.isEmpty() ? lisTestInfo.projectNames : test.projectNames;
// 追加测试任务
for ( String projectName : lisTestInfo.projectNames ) {
TaskTestRegular task = new TaskTestRegular();
task.tubeIndex = test.tubeIndex;
task.patientCode = test.patientCode;
task.tubeType = test.testTube;
task.barcode = barCode;
task.projectName = projectName;
task.bloodType = lisTestInfo.sampleType;
executor.appendTask(task);
Device.LOG.info("append test task: {}", task.projectName);
}
}
}
// 入料
private void testTubeRackFeed() {
Integer testTubeExistsInTrack = this.testTubeMovement.readIO(ActModuleTestTubeRackMovement.IO_TEST_TUBE_RACK_EXISTS_IN_TRACK);

39
src/main/java/com/dreamworks/boditech/driver/task/TaskTestBase.java

@ -6,6 +6,8 @@ import com.dreamworks.boditech.driver.entity.IncubatorSlot;
import com.dreamworks.boditech.driver.task.step.Step;
import com.dreamworks.boditech.driver.task.step.StepManager;
import com.dreamworks.boditech.entity.Project;
import com.dreamworks.boditech.entity.Test;
import com.dreamworks.boditech.entity.TestStepLogEntry;
import java.util.ArrayList;
import java.util.List;
@ -26,18 +28,21 @@ abstract public class TaskTestBase extends TaskBase implements TaskTest {
private CsmSampleTube sampleTube;
// post steps
private List<Step> postSteps;
// test
private Test test;
// device
private Device device;
@Override
public void execute(Executor executor) {
this.device = executor.getDevice();
this.taskExecutor = executor;
this.setupTask();
// execute steps
while ( this.stepIndex < this.steps.size() ) {
Step step = this.steps.get(this.stepIndex);
if ( step.isEnable() ) {
step.execute(executor, this);
}
this.executeStep(step);
this.stepIndex++;
if ( !Task.STATUS_EXECUTING.equals(this.getStatus()) ) {
break;
@ -73,11 +78,29 @@ abstract public class TaskTestBase extends TaskBase implements TaskTest {
this.postSteps = new ArrayList<>();
this.reactionTube = device.bufferTubes.tubeAllocByProjectName(this.projectName);
this.initTask();
this.test = new Test();
this.initTask(this.test);
device.testService.insert(this.test);
}
// execute step
private void executeStep(Step step) {
if ( !step.isEnable() ) {
return ;
}
this.testStatusUpdate(step.getActionName());
TestStepLogEntry logEntry = new TestStepLogEntry();
logEntry.stepName = step.getActionName();
logEntry.stepOptions = step.getStepNode().toString();
this.device.testService.logStepStart(this.test, logEntry);
step.execute(this.taskExecutor, this);
this.device.testService.logStepEnd(logEntry);
}
// init task
abstract protected void initTask();
abstract protected void initTask(Test test);
// get reaction tube
public CsmBufferTube getReactionTube() {
@ -113,4 +136,10 @@ abstract public class TaskTestBase extends TaskBase implements TaskTest {
public void postStepPush( Step step ) {
this.postSteps.add(step);
}
// update status
public void testStatusUpdate( String status ) {
this.test.status = status;
this.device.testService.statusUpdate(this.test);
}
}

4
src/main/java/com/dreamworks/boditech/driver/task/TaskTestEmergency.java

@ -1,5 +1,7 @@
package com.dreamworks.boditech.driver.task;
import com.dreamworks.boditech.driver.consumable.CsmSampleTube;
import com.dreamworks.boditech.entity.Test;
public class TaskTestEmergency extends TaskTestBase {
// sample bar code
public String barcode;
@ -11,7 +13,7 @@ public class TaskTestEmergency extends TaskTestBase {
public String position;
@Override
protected void initTask() {
protected void initTask(Test test) {
CsmSampleTube sampleTube = new CsmSampleTube(this.taskExecutor.getDevice());
sampleTube.type = CsmSampleTube.TYPE_EPP05;
sampleTube.taskType = CsmSampleTube.TASK_TYPE_EMERGENCY;

12
src/main/java/com/dreamworks/boditech/driver/task/TaskTestRegular.java

@ -3,6 +3,8 @@ import com.dreamworks.boditech.driver.Device;
import com.dreamworks.boditech.driver.actuator.ActMotor;
import com.dreamworks.boditech.driver.actuator.ActuatorModule;
import com.dreamworks.boditech.driver.consumable.CsmSampleTube;
import com.dreamworks.boditech.entity.Test;
public class TaskTestRegular extends TaskTestBase {
// tube index
public Integer tubeIndex;
@ -13,10 +15,10 @@ public class TaskTestRegular extends TaskTestBase {
// bar code
public String barcode;
// user id
public String patientId;
public String patientCode;
@Override
protected void initTask() {
protected void initTask(Test test) {
Device device = this.taskExecutor.getDevice();
ActMotor testTubeMoveMotor = (ActMotor)device.getActuator(ActuatorModule.TEST_TUBE_RACK_MOVE_MOTOR);
@ -27,6 +29,12 @@ public class TaskTestRegular extends TaskTestBase {
sampleTube.locationX = this.taskExecutor.getDevice().getLocationByName("testTubeRackTubeSampling.x");
this.setSampleTube(sampleTube);
// setup test info
test.tubeType = this.tubeType;
test.projectName = this.projectName;
test.sampleType = this.bloodType;
test.patientCode = this.patientCode;
// move tube to sampling position
Integer samplingStartPos = device.getLocationByName("testTubeRackTubeSamplingStart");
Integer samplingDistance = device.getLocationByName("testTubeRackTubeSamplingDistance");

9
src/main/java/com/dreamworks/boditech/driver/task/step/Step.java

@ -1,6 +1,8 @@
package com.dreamworks.boditech.driver.task.step;
import com.dreamworks.boditech.driver.task.Task;
import com.dreamworks.boditech.driver.task.Executor;
import com.fasterxml.jackson.databind.JsonNode;
public interface Step {
// execute step
void execute(Executor executor, Task task);
@ -8,4 +10,11 @@ public interface Step {
void postExecute();
// is enable
boolean isEnable();
// get action name
String getActionName();
void setStepNode(JsonNode stepNode);
JsonNode getStepNode();
}

22
src/main/java/com/dreamworks/boditech/driver/task/step/StepBase.java

@ -1,10 +1,24 @@
package com.dreamworks.boditech.driver.task.step;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
abstract public class StepBase implements Step {
@JsonProperty("action")
public String action;
@JsonProperty("enable")
public Boolean enable;
// step node
private JsonNode stepNode;
// set step node
public void setStepNode(JsonNode stepNode) {
this.stepNode = stepNode;
}
// get step node
public JsonNode getStepNode() {
return this.stepNode;
}
// is enable
public boolean isEnable() {
@ -19,4 +33,12 @@ abstract public class StepBase implements Step {
public boolean isExecutable() {
return true;
}
/**
* 获取步骤名称用于日志记录
* @return 步骤名称
*/
public String getActionName() {
return this.action;
}
}

1
src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java

@ -43,6 +43,7 @@ public class StepManager {
throw new RuntimeException("step class not found: " + name);
}
Step step = jsonMapper.convertValue(stepNode, stepClass);
step.setStepNode(stepNode);
steps.add(step);
}
return steps;

5
src/main/java/com/dreamworks/boditech/entity/ParamTestRegularAppendTask.java

@ -1,15 +1,16 @@
package com.dreamworks.boditech.entity;
import java.util.List;
public class ParamTestRegularAppendTask {
// tube index
public Integer tubeIndex;
// tube type
public String tubeType;
// project name
public String projectName;
public List<String> projectNames;
// blood type
public String bloodType;
// bar code
public String barCode;
// user id
public String patientId;
public String patientCode;
}

19
src/main/java/com/dreamworks/boditech/entity/Test.java

@ -0,0 +1,19 @@
package com.dreamworks.boditech.entity;
public class Test {
// id
public Integer id;
// patient code
public String patientCode;
// patient id
public String projectName;
// tube type
public String tubeType;
// sample type
public String sampleType;
// started at
public String startedAt;
// started by
public Integer startedBy;
// status
public String status;
}

15
src/main/java/com/dreamworks/boditech/entity/TestStepLogEntry.java

@ -0,0 +1,15 @@
package com.dreamworks.boditech.entity;
public class TestStepLogEntry {
// id
public Integer id;
// test id
public Integer testId;
// step name
public String stepName;
// step options
public String stepOptions;
// start time
public String startedAt;
// finished time
public String finishedAt;
}

20
src/main/java/com/dreamworks/boditech/mapper/TestMapper.java

@ -0,0 +1,20 @@
package com.dreamworks.boditech.mapper;
import com.dreamworks.boditech.entity.Test;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;
@Mapper
public interface TestMapper {
@Insert("INSERT INTO bdt_tests (" +
"patientCode, projectName, sampleType, tubeType, startedAt, startedBy" +
") VALUES (" +
"#{patientCode}, #{projectName}, #{sampleType}, #{tubeType}, #{startedAt}, #{startedBy}" +
")")
@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
int insert(Test test);
@Update("UPDATE bdt_tests SET status = #{status} WHERE id = #{id}")
int statusUpdate(Test test);
}

19
src/main/java/com/dreamworks/boditech/mapper/TestStepMapper.java

@ -0,0 +1,19 @@
package com.dreamworks.boditech.mapper;
import com.dreamworks.boditech.entity.TestStepLogEntry;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;
@Mapper
public interface TestStepMapper {
@Insert("INSERT INTO bdt_test_steps (" +
"testId, stepName,stepOptions, startedAt" +
") VALUES (" +
"#{testId}, #{stepName}, #{stepOptions}, #{startedAt}" +
")")
@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
int insert(TestStepLogEntry entry);
@Update("UPDATE bdt_test_steps SET finishedAt = #{finishedAt} WHERE id = #{id}")
int update(TestStepLogEntry entry);
}

4
src/main/java/com/dreamworks/boditech/service/DeviceService.java

@ -180,10 +180,10 @@ public class DeviceService {
for (ParamTestRegularAppendTask taskItem : param.tasks) {
TaskBatchTubeTestInfo test = new TaskBatchTubeTestInfo();
test.tubeIndex = taskItem.tubeIndex;
test.patientId = taskItem.patientId;
test.patientCode = taskItem.patientCode;
test.barcode = taskItem.barCode;
test.testTube = taskItem.tubeType;
test.project = taskItem.projectName;
test.projectNames = taskItem.projectNames;
test.blood = taskItem.bloodType;
task.tests.add(test);
}

42
src/main/java/com/dreamworks/boditech/service/TestService.java

@ -0,0 +1,42 @@
package com.dreamworks.boditech.service;
import com.dreamworks.boditech.entity.Test;
import com.dreamworks.boditech.entity.TestStepLogEntry;
import com.dreamworks.boditech.mapper.TestMapper;
import com.dreamworks.boditech.mapper.TestStepMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Service
public class TestService {
@Resource
private TestMapper testMapper;
@Resource
private TestStepMapper testStepMapper;
// create test
public void insert(Test test) {
test.startedAt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
// @TODO : startedBy should be set to the current user
test.startedBy = 0;
this.testMapper.insert(test);
}
// update test
public void statusUpdate(Test test) {
this.testMapper.statusUpdate(test);
}
// log step start
public void logStepStart(Test test, TestStepLogEntry entry ) {
entry.testId = test.id;
entry.startedAt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
this.testStepMapper.insert(entry);
}
// log step end
public void logStepEnd(TestStepLogEntry entry) {
entry.finishedAt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
this.testStepMapper.update(entry);
}
}
Loading…
Cancel
Save