Pārlūkot izejas kodu

[task-1766] 性能验证模块 开发 (二期) / 【后端】验证报告的接口开发

Li Yuan 1 gadu atpakaļ
vecāks
revīzija
eee9c0406a

+ 6 - 1
ibps-provider-root/modules/provider-business/pom.xml

@@ -265,7 +265,12 @@
 			<groupId>com.lc.ibps.components</groupId>
 			<artifactId>ibps-component-upload-api</artifactId>
 		</dependency>
-
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math3</artifactId>
+            <version>3.1.1</version>
+            <scope>compile</scope>
+        </dependency>
 
 
     </dependencies>

+ 1 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelExportTemplateServer.java

@@ -18,7 +18,7 @@ public class PVExcelExportTemplateServer extends ExcelExportServer {
         if (entity.getTitle() != null) {
             rows += createHeaderRow(entity, sheet, workbook, feildWidth);
         }
-        rows += createInspectionDateRow(entity, sheet, rows,workbook, feildWidth);
+//        rows += createInspectionDateRow(entity, sheet, rows,workbook, feildWidth);
         rows += createTitleRow(entity, sheet, workbook, rows, excelParams);
         sheet.createFreezePane(0, rows, 0, rows);
         return rows;

+ 9 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/CalcVO.java

@@ -1,5 +1,7 @@
 package com.lc.ibps.components.verification.model;
 
+import org.apache.commons.math3.distribution.TDistribution;
+
 import java.text.DecimalFormat;
 
 public class CalcVO {
@@ -7,4 +9,11 @@ public class CalcVO {
     public double format(double d,int scale){
         return Double.parseDouble(String.format("%."+scale+"f", d));
     }
+
+    public double getT(double degreesOfFreedom,double p){
+        TDistribution t = new TDistribution(degreesOfFreedom);
+        double value = t.inverseCumulativeProbability(1 - p/2);
+//        double value = t.inverseCumulativeProbability(1 - 0.01/2);
+        return format(value,2);
+    }
 }

+ 16 - 6
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/ConfigVO.java

@@ -8,12 +8,14 @@ public class ConfigVO {
     private String standard;
     private String remark;
     private double tea;
-    private String batchCVS;
+    private double batchCVS;
     private double batchCVSValue;
-    private String dailyCVS;
+    private double dailyCVS;
     private double dailyCVSValue;
     private int decimal;
 
+    private double claimValue;
+
     public String[] getModel() {
         return model;
     }
@@ -54,11 +56,11 @@ public class ConfigVO {
         this.tea = tea;
     }
 
-    public String getBatchCVS() {
+    public double getBatchCVS() {
         return batchCVS;
     }
 
-    public void setBatchCVS(String batchCVS) {
+    public void setBatchCVS(double batchCVS) {
         this.batchCVS = batchCVS;
     }
 
@@ -70,11 +72,11 @@ public class ConfigVO {
         this.batchCVSValue = batchCVSValue;
     }
 
-    public String getDailyCVS() {
+    public double getDailyCVS() {
         return dailyCVS;
     }
 
-    public void setDailyCVS(String dailyCVS) {
+    public void setDailyCVS(double dailyCVS) {
         this.dailyCVS = dailyCVS;
     }
 
@@ -93,4 +95,12 @@ public class ConfigVO {
     public void setDecimal(int decimal) {
         this.decimal = decimal;
     }
+
+    public double getClaimValue() {
+        return claimValue;
+    }
+
+    public void setClaimValue(double claimValue) {
+        this.claimValue = claimValue;
+    }
 }

+ 2 - 3
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/EP15CalcVO.java → ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/EP15PrecisionVO.java

@@ -4,10 +4,9 @@ import com.lc.ibps.components.verification.funcs.xAverage;
 import com.lc.ibps.components.verification.funcs.xFuncStdevVar;
 import com.lc.ibps.components.verification.funcs.xValue;
 
-import java.text.DecimalFormat;
 import java.util.Arrays;
 
-public class EP15CalcVO extends CalcVO{
+public class EP15PrecisionVO extends CalcVO{
 
     private SpecimensCalcVO[] data;
 
@@ -48,7 +47,7 @@ public class EP15CalcVO extends CalcVO{
     private double allowableSr;
     private double allowableS1;
 
-    public EP15CalcVO(SpecimensCalcVO[] data, int repeatNum,double allowableCvr,double allowableCv1,int decimal) {
+    public EP15PrecisionVO(SpecimensCalcVO[] data, int repeatNum, double allowableCvr, double allowableCv1, int decimal) {
         this.data = data;
         this.n = repeatNum;
         this.allowableCvr = allowableCvr;

+ 176 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/EP15TruenessPatientVO.java

@@ -0,0 +1,176 @@
+package com.lc.ibps.components.verification.model;
+
+import com.lc.ibps.components.verification.funcs.xAverage;
+import com.lc.ibps.components.verification.funcs.xFuncArray2Args;
+import com.lc.ibps.components.verification.funcs.xFuncStdevVar;
+import com.lc.ibps.components.verification.funcs.xValue;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.math3.distribution.ChiSquaredDistribution;
+import org.apache.commons.math3.distribution.TDistribution;
+
+public class EP15TruenessPatientVO extends CalcVO{
+    //多个样本均值 y
+    private double[] y;
+    //样本的标示值/理论值 x
+    private double[] x;
+    private xValue[] yx;
+    private xValue[] yxb;
+
+    private double meanX;
+    private double meanY;
+    private double bias;
+    private double sdDiff;
+//    //截距(a)
+//    private double a;
+//    //斜率(b)
+//    private double b;
+//    //相关系数r
+//    private double r;
+    private int n;
+    private double t;//t critical
+
+    private double ucl;//Upper confidence limit
+    private double lcl;//Lower confidence limit
+    private double uvl;//Upper verification limit
+    private double lvl;//Lower verification limit
+    private double sdClaim;//SD assigned value
+
+    public EP15TruenessPatientVO(SpecimensCalcVO y, SpecimensCalcVO x,double sdClaim,double t) {
+        meanX = x.getMean().getDoub();
+        meanY = y.getMean().getDoub();
+        this.y = y.getStoreData();
+        this.x = x.getStoreData();
+        if(t == 0){
+            this.t = getT(this.y.length-1,0.01);
+        }else {
+            this.t = t;
+        }
+        this.n = this.y.length;
+        this.sdClaim = sdClaim;
+        calculate();
+    }
+
+    public void calculate() {
+
+        yx = new xValue[y.length];
+        yxb = new xValue[y.length];
+        for (int i = 0; i < y.length; i++) {
+            yx[i] = new xValue(y[i] - x[i]);
+        }
+        bias = xAverage.eval(yx).getDoub();
+        for (int i = 0; i < y.length; i++) {
+            yxb[i] = new xValue(y[i] - x[i] - bias);
+        }
+        sdDiff = xFuncStdevVar.evalArgs(yxb,xFuncStdevVar.iSTDEV).getDoub();
+
+        double sqrtN = Math.sqrt(n);
+        ucl = bias + t * sdDiff / sqrtN;
+        lcl = bias - t * sdDiff / sqrtN;
+        uvl = sdClaim + t * sdDiff / sqrtN;
+        lvl = sdClaim - t * sdDiff / sqrtN;
+
+//        b = xFuncArray2Args.evalArgs(y, x, xFuncArray2Args.iSLOPE).getDoub();
+//        a = xFuncArray2Args.evalArgs(y, x, xFuncArray2Args.iINTERCEPT).getDoub();
+//        r = xFuncArray2Args.evalArgs(y, x, xFuncArray2Args.iCORREL).getDoub();
+
+    }
+
+    public double getMeanX() {
+        return meanX;
+    }
+
+    public void setMeanX(double meanX) {
+        this.meanX = meanX;
+    }
+
+    public double getMeanY() {
+        return meanY;
+    }
+
+    public void setMeanY(double meanY) {
+        this.meanY = meanY;
+    }
+
+    public double getBias() {
+        return bias;
+    }
+
+    public void setBias(double bias) {
+        this.bias = bias;
+    }
+
+    public double getSdDiff() {
+        return sdDiff;
+    }
+
+    public void setSdDiff(double sdDiff) {
+        this.sdDiff = sdDiff;
+    }
+
+    public int getN() {
+        return n;
+    }
+
+    public void setN(int n) {
+        this.n = n;
+    }
+
+    public double getT() {
+        return t;
+    }
+
+    public void setT(double t) {
+        this.t = t;
+    }
+
+    public double getUcl() {
+        return ucl;
+    }
+
+    public void setUcl(double ucl) {
+        this.ucl = ucl;
+    }
+
+    public double getLcl() {
+        return lcl;
+    }
+
+    public void setLcl(double lcl) {
+        this.lcl = lcl;
+    }
+
+    public double getUvl() {
+        return uvl;
+    }
+
+    public void setUvl(double uvl) {
+        this.uvl = uvl;
+    }
+
+    public double getLvl() {
+        return lvl;
+    }
+
+    public void setLvl(double lvl) {
+        this.lvl = lvl;
+    }
+
+    public double getSdClaim() {
+        return sdClaim;
+    }
+
+    public void setSdClaim(double sdClaim) {
+        this.sdClaim = sdClaim;
+    }
+    public double[][] getData(){
+
+        double[][] d = new double[y.length][4];
+        for (int i = 0; i<y.length;i++){
+            d[i][0] = y[i];
+            d[i][1] = x[i];
+            d[i][2] = yx[i].getDoub();
+            d[i][3] = yxb[i].getDoub();
+        }
+        return d;
+    }
+}

+ 154 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/EP15TruenessReferneceVO.java

@@ -0,0 +1,154 @@
+package com.lc.ibps.components.verification.model;
+
+import com.lc.ibps.components.verification.funcs.xAverage;
+import com.lc.ibps.components.verification.funcs.xFuncStdevVar;
+import com.lc.ibps.components.verification.funcs.xValue;
+
+public class EP15TruenessReferneceVO extends CalcVO{
+
+    private xValue[] data;
+
+    private double target;
+    private double mean;
+    private double sd;
+    private double se;
+    private double ucl;//Upper confidence limit
+    private double lcl;//Lower confidence limit
+    private double uvl;//Upper verification limit
+    private double lvl;//Lower verification limit
+
+    private double t;//t critical
+    private double sdClaim;//SD assigned value
+
+    public EP15TruenessReferneceVO(xValue[] data, double target, double sdClaim, double t){
+        this.data = data;
+        this.target = target;
+        this.sdClaim = sdClaim;
+        if(t == 0){
+            this.t = getT(data.length-1,0.01);
+        }else {
+            this.t = t;
+        }
+        calculate();
+    }
+
+  /*
+  Reference assigned value 50mg/dl
+
+    Day 1	Replicate 1	48
+            Replicate 2	46
+    Day 2	Replicate 1	48
+            Replicate 2	47
+    Day 3	Replicate 1	46
+            Replicate 2	46
+    Day 4	Replicate 1	48
+            Replicate 2	47
+    Day 5	Replicate 1	47
+            Replicate 2	46
+
+    Count	    Count(C3:c12)	    10
+    SQRT        count		        3.16227766
+    Mean	    Average C3 :12	    46.9
+    SD	        SD(C3:C12)	        0.875595036
+    SE of mean                                      C17/SQRT14		0.276887462
+    t critical 		                                                3.25
+    Upper confidence limit	                        c16 +c19*c18	47.79988425
+    Lower confidence limit	                        c16 -c19*c18	46.00011575
+    SD assigned value 		                                        0.15
+    Combined SD uncertainity SE square + SD assign value square		0.099166667
+    Combined SD uncertaininty SQRT (SE square + SD assign)		    0.314907394
+    Upper verification limit		                                47.92344903
+    Lower verification limit		                                45.87655097
+*/
+    public void calculate() {
+
+        mean = xAverage.eval(data).getDoub();
+        sd = xFuncStdevVar.evalArgs(data, xFuncStdevVar.iSTDEV).getDoub();
+        se = sd / Math.sqrt(data.length);
+        ucl = mean + t * se;
+        lcl = mean - t * se;
+        double combinedSD = Math.sqrt(se * se + sdClaim * sdClaim);
+        uvl = mean + t * combinedSD;
+        lvl = mean - t * combinedSD;
+    }
+
+    public double getTarget() {
+        return target;
+    }
+
+    public void setTarget(double target) {
+        this.target = target;
+    }
+
+    public double getMean() {
+        return mean;
+    }
+
+    public void setMean(double mean) {
+        this.mean = mean;
+    }
+
+    public double getSd() {
+        return sd;
+    }
+
+    public void setSd(double sd) {
+        this.sd = sd;
+    }
+
+    public double getSe() {
+        return se;
+    }
+
+    public void setSe(double se) {
+        this.se = se;
+    }
+
+    public double getUcl() {
+        return ucl;
+    }
+
+    public void setUcl(double ucl) {
+        this.ucl = ucl;
+    }
+
+    public double getLcl() {
+        return lcl;
+    }
+
+    public void setLcl(double lcl) {
+        this.lcl = lcl;
+    }
+
+    public double getUvl() {
+        return uvl;
+    }
+
+    public void setUvl(double uvl) {
+        this.uvl = uvl;
+    }
+
+    public double getLvl() {
+        return lvl;
+    }
+
+    public void setLvl(double lvl) {
+        this.lvl = lvl;
+    }
+
+    public double getT() {
+        return t;
+    }
+
+    public void setT(double t) {
+        this.t = t;
+    }
+
+    public double getSdClaim() {
+        return sdClaim;
+    }
+
+    public void setSdClaim(double sdClaim) {
+        this.sdClaim = sdClaim;
+    }
+}

+ 43 - 15
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/InspectionItemVO.java

@@ -87,7 +87,11 @@ public class InspectionItemVO {
         }
         List<ExportParams> exportParamsList = new ArrayList<ExportParams>();
         for (int i = 1; i < config.getDays()+1; i++) {
-            ExportParams exportParams = new ExportParams(config.getName() + " 数据导入模板", String.format("第 %d 天",i));
+            String sheetName = String.format("第 %d 天",i);
+            if(config.getDays() == 1){
+                sheetName = config.getName();
+            }
+            ExportParams exportParams = new ExportParams(config.getName() + " 数据导入模板", sheetName);
             exportParams.setStyle(PVExcelExportStyler.class);
             exportParamsList.add(exportParams);
             exportParams.setType(ExcelType.XSSF);
@@ -168,15 +172,19 @@ public class InspectionItemVO {
 
     public void importExcelRecord(InputStream inputstream) {
         ImportParams params = new ImportParams();
-        params.setTitleRows(2);
+        params.setTitleRows(1);
         params.setHeadRows(1);
         params.setSheetNum(config.getDays());
         List<ExcelSheetRecord> list = PVExcelUtil.importExcel(inputstream, Map.class, params);
         int i = 1;
         for (ExcelSheetRecord record : list) {
-            record.convert(config, String.format("第 %d 天",i));
+            String sheetName = String.format("第 %d 天",i);
+            if(config.getDays() == 1){
+                sheetName = config.getName();
+            }
+            record.convert(config, sheetName);
             if (record.getErrors().size() > 0) {
-                errorMessage.put(String.format("第 %d 天",i), record.getErrors());
+                errorMessage.put(sheetName, record.getErrors());
             }
             i++;
         }
@@ -186,16 +194,6 @@ public class InspectionItemVO {
             dataPass = true;
         }
 
-        if(config.getName().toLowerCase().contains("ep15")){
-            for (String sName : config.getSpecimensName()) {
-                SpecimensCalcVO[] data = new SpecimensCalcVO[config.getDays()];
-                for (int j = 0; j < list.size(); j++) {
-                    final xValue[] xValues = list.get(j).getConvertedData().get(sName);
-                    data[j] = new SpecimensCalcVO(xValues, config.isConvert());
-                }
-                record2.put(sName, new EP15CalcVO(data,config.getRepeatNum(),config.getBatchCVSValue(),config.getDailyCVSValue(),config.getDecimal()));
-            }
-        }
         for (String sName : config.getSpecimensName()) {
             final xValue[] total = new xValue[config.getRepeatNum() * config.getDays()];
             for (int j = 0; j < list.size(); j++) {
@@ -206,7 +204,37 @@ public class InspectionItemVO {
             }
             record.put(sName, new SpecimensCalcVO(total, config.isConvert()));
         }
-        buildItemCalcVO();
+//        buildItemCalcVO();
+
+
+        if(config.getName().toLowerCase().contains("精密度")){
+            for (String sName : config.getSpecimensName()) {
+                SpecimensCalcVO[] data = new SpecimensCalcVO[config.getDays()];
+                for (int j = 0; j < list.size(); j++) {
+                    final xValue[] xValues = list.get(j).getConvertedData().get(sName);
+                    data[j] = new SpecimensCalcVO(xValues, config.isConvert());
+                }
+                record2.put(sName, new EP15PrecisionVO(data,config.getRepeatNum(),config.getBatchCVSValue(),config.getDailyCVSValue(),config.getDecimal()));
+            }
+        }else if(config.getName().equals("定值参考物质验证")){
+            for (String sName : config.getSpecimensName()) {
+                final xValue[] total = new xValue[config.getRepeatNum() * config.getDays()];
+                for (int j = 0; j < list.size(); j++) {
+                    final xValue[] xValues = list.get(j).getConvertedData().get(sName);
+                    for (int k = 0; k < xValues.length; k++) {
+                        total[j * xValues.length + k] = xValues[k];
+                    }
+                }
+                record2.put(sName, new EP15TruenessReferneceVO(total, config.getTargetValue()[0],config.getClaimValue(),0));
+            }
+        }else if(config.getName().equals("EP15-A方法学比对")){
+
+            record2.put("EP15-A方法学比对",
+                    new EP15TruenessPatientVO(record.get(config.getSpecimensName()[0]),record.get(config.getSpecimensName()[1]), config.getClaimValue(),0));
+
+        }
+
+
 
     }
 

+ 1 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ReportFactory.java

@@ -9,8 +9,8 @@ public class ReportFactory {
 
         data.setConfig(item.getConfig());
         data.setData(item.getData());
+        data.setReportData(item.getRecord2());
         if(item.getConfig().getName().toLowerCase().contains("ep15")){
-            data.setReportData(item.getRecord2());
         } else{
 //            data.setData(item.getRecord());
         }