wangweiqun 6 роки тому
коміт
4973faaaf9
54 змінених файлів з 8224 додано та 0 видалено
  1. 1159 0
      ehr-cloud/pom.xml
  2. 606 0
      ehr-ms-parent-pom/pom.xml
  3. 125 0
      pom.xml
  4. 34 0
      src/main/java/com/yihu/ehr/HealthProfileService.java
  5. 27 0
      src/main/java/com/yihu/ehr/profile/config/TenantConfiguration.java
  6. 62 0
      src/main/java/com/yihu/ehr/profile/controller/prescription/ThridPrescriptionEndPoint.java
  7. 60 0
      src/main/java/com/yihu/ehr/profile/controller/profile/ProfileCDAEndPoint.java
  8. 48 0
      src/main/java/com/yihu/ehr/profile/controller/profile/ProfileDiseaseEndPoint.java
  9. 77 0
      src/main/java/com/yihu/ehr/profile/controller/profile/ProfileEventEndPoint.java
  10. 74 0
      src/main/java/com/yihu/ehr/profile/controller/profile/ProfileInspectionEndPoint.java
  11. 124 0
      src/main/java/com/yihu/ehr/profile/controller/profile/ProfileMedicationEndPoint.java
  12. 40 0
      src/main/java/com/yihu/ehr/profile/controller/profile/ProfileMotherhoodEndPoint.java
  13. 74 0
      src/main/java/com/yihu/ehr/profile/controller/profile/ProfilePatientEndPoint.java
  14. 258 0
      src/main/java/com/yihu/ehr/profile/controller/sanofi/SanofiEndPoint.java
  15. 236 0
      src/main/java/com/yihu/ehr/profile/controller/template/TemplateEndPoint.java
  16. 21 0
      src/main/java/com/yihu/ehr/profile/dao/ArchiveTemplateDao.java
  17. 51 0
      src/main/java/com/yihu/ehr/profile/feign/CDADocumentClient.java
  18. 106 0
      src/main/java/com/yihu/ehr/profile/feign/DictClient.java
  19. 33 0
      src/main/java/com/yihu/ehr/profile/feign/GeographyClient.java
  20. 42 0
      src/main/java/com/yihu/ehr/profile/feign/OrganizationClient.java
  21. 93 0
      src/main/java/com/yihu/ehr/profile/feign/ResourceClient.java
  22. 28 0
      src/main/java/com/yihu/ehr/profile/feign/ThridPrescriptionClient.java
  23. 36 0
      src/main/java/com/yihu/ehr/profile/feign/TransformClient.java
  24. 154 0
      src/main/java/com/yihu/ehr/profile/model/ArchiveTemplate.java
  25. 34 0
      src/main/java/com/yihu/ehr/profile/model/DrugInfo.java
  26. 82 0
      src/main/java/com/yihu/ehr/profile/model/InspectionInfo.java
  27. 178 0
      src/main/java/com/yihu/ehr/profile/model/MCDADocument.java
  28. 103 0
      src/main/java/com/yihu/ehr/profile/model/MedicationStat.java
  29. 107 0
      src/main/java/com/yihu/ehr/profile/service/ProfileBasicService.java
  30. 553 0
      src/main/java/com/yihu/ehr/profile/service/ProfileCDAService.java
  31. 345 0
      src/main/java/com/yihu/ehr/profile/service/ProfileDiseaseService.java
  32. 331 0
      src/main/java/com/yihu/ehr/profile/service/ProfileEventService.java
  33. 462 0
      src/main/java/com/yihu/ehr/profile/service/ProfileInfoBaseService.java
  34. 381 0
      src/main/java/com/yihu/ehr/profile/service/ProfileInspectionService.java
  35. 298 0
      src/main/java/com/yihu/ehr/profile/service/ProfileMedicationService.java
  36. 131 0
      src/main/java/com/yihu/ehr/profile/service/ProfileMotherhoodService.java
  37. 54 0
      src/main/java/com/yihu/ehr/profile/service/RedisService.java
  38. 88 0
      src/main/java/com/yihu/ehr/profile/service/ResourcesTransformService.java
  39. 87 0
      src/main/java/com/yihu/ehr/profile/service/old/MedicationStatService.java
  40. 313 0
      src/main/java/com/yihu/ehr/profile/service/old/PatientInfoDetailService.java
  41. 68 0
      src/main/java/com/yihu/ehr/profile/service/old/ProfileDataSetSerializer.java
  42. 73 0
      src/main/java/com/yihu/ehr/profile/service/old/SanofiService.java
  43. 277 0
      src/main/java/com/yihu/ehr/profile/service/old/ThridPrescriptionService.java
  44. 69 0
      src/main/java/com/yihu/ehr/profile/service/template/ArchiveTemplateService.java
  45. 33 0
      src/main/java/com/yihu/ehr/profile/util/BasicConstant.java
  46. 48 0
      src/main/java/com/yihu/ehr/profile/util/NumberValidationUtils.java
  47. 70 0
      src/main/java/com/yihu/ehr/profile/util/SimpleSolrQueryUtil.java
  48. 62 0
      src/main/resources/application.yml
  49. 29 0
      src/main/resources/banner.txt
  50. 24 0
      src/main/resources/bootstrap.yml
  51. 153 0
      src/main/resources/templates/chinesetemplate.ftl
  52. 126 0
      src/main/resources/templates/westerntemplate.ftl
  53. 24 0
      src/test/java/com/yihu/ehr/DateTest.java
  54. 53 0
      src/test/java/com/yihu/ehr/MapSort.java

+ 1159 - 0
ehr-cloud/pom.xml

@ -0,0 +1,1159 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yihu.ehr</groupId>
    <artifactId>ehr-cloud</artifactId>
    <version>1.2.0</version>
    <packaging>pom</packaging>
    <name>ehr-cloud</name>
    <description>EHR parent pom for all</description>
    <url>http://ehr.yihu.com</url>
    <organization>
        <name>JKZL Software, Inc.</name>
        <url>http://www.yihu.com</url>
    </organization>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <id>sand</id>
            <name>Sand Wen</name>
            <email>sand.fj.wen@gmail.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project lead</role>
                <role>Project designer</role>
                <role>Project programmer</role>
            </roles>
        </developer>
        <developer>
            <id>yzh</id>
            <name>叶泽华</name>
            <email>yzh@qq.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project programmer</role>
            </roles>
        </developer>
        <developer>
            <id>cws</id>
            <name>陈维山</name>
            <email>hill9868@qq.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project programmer</role>
            </roles>
        </developer>
        <developer>
            <id>hzy</id>
            <name>黄志勇</name>
            <email>hzy@qq.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project programmer</role>
            </roles>
        </developer>
    </developers>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.spring-framework>4.3.13.RELEASE</version.spring-framework>
        <version.spring-boot>1.5.9.RELEASE</version.spring-boot>
        <version.spring-cloud-starter>1.3.2.RELEASE</version.spring-cloud-starter>
        <version.spring-cloud>1.4.2.RELEASE</version.spring-cloud>
        <version.spring-security>4.2.3.RELEASE</version.spring-security>
        <version.spring-oauth2>2.0.14.RELEASE</version.spring-oauth2>
        <version.spring-session>1.3.1.RELEASE</version.spring-session>
        <version.spring-session-hazelcast>2.0.1.RELEASE</version.spring-session-hazelcast>
        <version.spring-data-commons>1.13.9.RELEASE</version.spring-data-commons>
        <version.spring-data-hadoop>2.2.0.RELEASE</version.spring-data-hadoop>
        <version.spring-data-solr>2.1.3.RELEASE</version.spring-data-solr>
        <version.spring-data-redis>1.7.1.RELEASE</version.spring-data-redis>
        <version.spring-data-jpa>1.11.10.RELEASE</version.spring-data-jpa>
        <version.spring-kafka>1.0.5.RELEASE</version.spring-kafka>
        <version.commons-bean-utils>1.9.2</version.commons-bean-utils>
        <version.commons-codec>1.9</version.commons-codec>
        <version.commons-collections>3.2.1</version.commons-collections>
        <version.commons-compress>1.9</version.commons-compress>
        <version.commons-dbcp2>2.1.1</version.commons-dbcp2>
        <version.commons-dbutils>1.6</version.commons-dbutils>
        <version.commons-io>2.4</version.commons-io>
        <version.commons-lang3>3.2.1</version.commons-lang3>
        <version.commons-pool2>2.4.2</version.commons-pool2>
        <version.zookeeper>3.4.6</version.zookeeper>
        <version.hadoop-client>2.6.5</version.hadoop-client>
        <version.hbase-client>1.1.1</version.hbase-client>
        <version.solr>5.5.4</version.solr>
        <version.hibernate>4.3.11.Final</version.hibernate>
        <version.hibernate-validator>6.0.10.Final</version.hibernate-validator>
        <version.hibernate-jpa-api>1.0.0.Final</version.hibernate-jpa-api>
        <version.http-core>4.4.3</version.http-core>
        <version.http-client>4.5.1</version.http-client>
        <version.http-mime>4.5.1</version.http-mime>
        <version.io-dropwizard-metrics>3.1.2</version.io-dropwizard-metrics>
        <version.java>1.8</version.java>
        <version.jackson>2.6.6</version.jackson>
        <version.jedis>2.9.0</version.jedis>
        <version.jcl-over-slf4j>1.7.19</version.jcl-over-slf4j>
        <version.jul-over-slf4j>1.7.21</version.jul-over-slf4j>
        <version.joda-time>2.8.2</version.joda-time>
        <version.junit>4.12</version.junit>
        <version.logging>1.2</version.logging>
        <version.log4j>1.2.17</version.log4j>
        <version.log4j2>2.4.1</version.log4j2>
        <version.logback>1.1.7</version.logback>
        <version.mysql>5.1.45</version.mysql>
        <version.pinyin4j>2.5.0</version.pinyin4j>
        <version.quartz>2.2.3</version.quartz>
        <version.servlet-api>3.1.0</version.servlet-api>
        <version.slf4j>1.7.21</version.slf4j>
        <version.statsd-client>3.1.0</version.statsd-client>
        <version.swagger>2.7.0</version.swagger>
        <version.swagger-ui>2.7.0</version.swagger-ui>
        <version.thrift>0.9.1</version.thrift>
        <version.tomcat-embed>8.5.27</version.tomcat-embed>
        <version.websocket-api>1.1</version.websocket-api>
        <version.zip4j>1.3.2</version.zip4j>
        <version.poi>3.12</version.poi>
        <version.scala>2.10.6</version.scala>
        <version.elasticsearch>2.1.0</version.elasticsearch>
        <version.elasticsearch-sql>2.4.1.0</version.elasticsearch-sql>
        <version.jest>2.4.0</version.jest>
        <version.alibaba-druid>1.0.15</version.alibaba-druid>
        <version.feign>9.5.0</version.feign>
        <version.hystrix>1.5.10</version.hystrix>
        <version.archaius>0.7.5</version.archaius>
        <version.ehr>1.2.0</version.ehr>
        <version.eip>1.3.1</version.eip>
        <version.json>20160212</version.json>
        <version.json-lib>2.4</version.json-lib>
        <version.fastjson>1.2.17</version.fastjson>
        <version.commons-net>3.3</version.commons-net>
        <version.jxl>2.6</version.jxl>
        <version.fastdfs>1.27</version.fastdfs>
        <version.spring.boot.admin>1.5.7</version.spring.boot.admin>
        <version.jettison>1.3.7</version.jettison>
    </properties>
    <dependencyManagement>
        <dependencies>
            <!--<dependency>-->
                <!--<groupId>org.springframework.boot</groupId>-->
                <!--<artifactId>spring-boot-dependencies</artifactId>-->
                <!--<version>1.5.9.RELEASE</version>-->
                <!--<type>pom</type>-->
                <!--<scope>import</scope>-->
            <!--</dependency>-->
            <!--<dependency>-->
                <!--<groupId>org.springframework.cloud</groupId>-->
                <!--<artifactId>spring-cloud-dependencies</artifactId>-->
                <!--<version>Finchley.M5</version>-->
                <!--<type>pom</type>-->
                <!--<scope>import</scope>-->
            <!--</dependency>-->
            <!-- Base library-->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>${version.servlet-api}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${version.junit}</version>
                <scope>test</scope>
            </dependency>
            <!-- Spring framework family -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context-support</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-messaging</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-oxm</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka -->
            <dependency>
                <groupId>org.springframework.kafka</groupId>
                <artifactId>spring-kafka</artifactId>
                <version>${version.spring-kafka}</version>
            </dependency>
            <!-- Spring boot family -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-actuator</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-batch</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${version.spring-boot}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-mongodb</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Spring cloud family -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter</artifactId>
                <version>${version.spring-cloud-starter}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-config-server</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-archaius</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka-server</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-netflix-eureka</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-feign</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-ribbon</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-zuul</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <!-- Feign -->
            <dependency>
                <groupId>io.github.openfeign</groupId>
                <artifactId>feign-core</artifactId>
                <version>${version.feign}</version>
            </dependency>
            <!-- Hystrix -->
            <dependency>
                <groupId>com.netflix.hystrix</groupId>
                <artifactId>hystrix-core</artifactId>
                <version>${version.hystrix}</version>
            </dependency>
            <!-- Archaius -->
            <dependency>
                <groupId>com.netflix.archaius</groupId>
                <artifactId>archaius-core</artifactId>
                <version>${version.archaius}</version>
            </dependency>
            <!-- Spring data family -->
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-commons</artifactId>
                <version>${version.spring-data-commons}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-hadoop-hbase</artifactId>
                <version>${version.spring-data-hadoop}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-solr</artifactId>
                <version>${version.spring-data-solr}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Spring session family-->
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session-hazelcast</artifactId>
                <version>${version.spring-session-hazelcast}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session</artifactId>
                <version>${version.spring-session}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session-data-redis</artifactId>
                <version>${version.spring-session}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Spring Security -->
            <!--<dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-config</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-core</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-crypto</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>-->
            <!-- Oauth2 -->
            <dependency>
                <groupId>org.springframework.security.oauth</groupId>
                <artifactId>spring-security-oauth2</artifactId>
                <version>${version.spring-oauth2}</version>
                <scope>${dependency.scope}</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.security</groupId>
                        <artifactId>*</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!--Jackson library -->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>${version.jackson}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>${version.jackson}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${version.jackson}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Http library -->
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpcore</artifactId>
                <version>${version.http-core}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>${version.http-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpmime</artifactId>
                <version>${version.http-mime}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!--Apache commons library -->
            <dependency>
                <groupId>org.codehaus.woodstox</groupId>
                <artifactId>stax2-api</artifactId>
                <version>3.1.4</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.codehaus.woodstox</groupId>
                <artifactId>woodstox-core-asl</artifactId>
                <version>4.4.1</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.noggit</groupId>
                <artifactId>noggit</artifactId>
                <version>0.6</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${version.commons-lang3}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>${version.poi}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils</artifactId>
                <version>${version.commons-bean-utils}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-pool2</artifactId>
                <version>${version.commons-pool2}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-dbutils</groupId>
                <artifactId>commons-dbutils</artifactId>
                <version>${version.commons-dbutils}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-dbcp2</artifactId>
                <version>${version.commons-dbcp2}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>${version.commons-io}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
                <version>${version.commons-collections}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>${version.commons-codec}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-compress</artifactId>
                <version>${version.commons-compress}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Mysql library -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${version.mysql}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Hibernate framework library -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>${version.hibernate}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>${version.hibernate-validator}</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>${version.hibernate}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.1-api</artifactId>
                <version>${version.hibernate-jpa-api}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Zookeeper library -->
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>${version.zookeeper}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Hadoop library -->
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-annotations</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-auth</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-distcp</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-hdfs</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-core</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-jobclient</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-shuffle</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-streaming</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-api</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-client</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-server-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-server-nodemanager</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-client</artifactId>
                <version>${version.hbase-client}</version>
                <scope>${dependency.scope}</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.hadoop</groupId>
                        <artifactId>*</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-common</artifactId>
                <version>${version.hbase-client}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-protocol</artifactId>
                <version>${version.hbase-client}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!-- export library -->
            <dependency>
                <groupId>net.sourceforge.jexcelapi</groupId>
                <artifactId>jxl</artifactId>
                <version>${version.jxl}</version>
            </dependency>
            <!-- Google library -->
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>18.0</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.findbugs</groupId>
                <artifactId>jsr305</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.6.2</version>
            </dependency>
            <dependency>
                <groupId>com.google.protobuf</groupId>
                <artifactId>protobuf-java</artifactId>
                <version>2.5.0</version>
            </dependency>
            <dependency>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
                <version>4.1.0</version>
            </dependency>
            <!-- Solr library -->
            <dependency>
                <groupId>org.apache.solr</groupId>
                <artifactId>solr-core</artifactId>
                <version>${version.solr}</version>
                <scope>${dependency.scope}</scope>
                <exclusions>
                    <exclusion>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.solr</groupId>
                <artifactId>solr-solrj</artifactId>
                <version>${version.solr}</version>
                <exclusions>
                    <exclusion>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!-- Elasticsearch -->
            <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>${version.elasticsearch}</version>
            </dependency>
            <dependency>
                <groupId>org.nlpcn</groupId>
                <artifactId>elasticsearch-sql</artifactId>
                <version>${version.elasticsearch-sql}</version>
            </dependency>
            <!-- Jest -->
            <dependency>
                <groupId>io.searchbox</groupId>
                <artifactId>jest</artifactId>
                <version>${version.jest}</version>
            </dependency>
            <!-- Redis library -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>${version.jedis}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- FastDFS library -->
            <dependency>
                <groupId>org.csource</groupId>
                <artifactId>fastdfs-client-java</artifactId>
                <version>${version.fastdfs}</version>
            </dependency>
            <!-- Quartz library -->
            <dependency>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz</artifactId>
                <version>${version.quartz}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz-jobs</artifactId>
                <version>${version.quartz}</version>
            </dependency>
            <!-- Zip library -->
            <dependency>
                <groupId>net.lingala.zip4j</groupId>
                <artifactId>zip4j</artifactId>
                <version>${version.zip4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Pinyin library -->
            <dependency>
                <groupId>com.belerweb</groupId>
                <artifactId>pinyin4j</artifactId>
                <version>${version.pinyin4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Swagger-ui library -->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${version.swagger}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${version.swagger-ui}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- date Time util library -->
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>${version.joda-time}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.thrift</groupId>
                <artifactId>libthrift</artifactId>
                <version>${version.thrift}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>com.timgroup</groupId>
                <artifactId>java-statsd-client</artifactId>
                <version>${version.statsd-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>io.dropwizard.metrics</groupId>
                <artifactId>metrics-core</artifactId>
                <version>${version.io-dropwizard-metrics}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Log framework library -->
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>${version.logging}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${version.log4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${version.slf4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>${version.logback}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Alibaba -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>${version.alibaba-druid}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>${version.fastjson}</version>
            </dependency>
            <!-- Spring Boot Admin -->
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-server</artifactId>
                <version>${version.spring.boot.admin}</version>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-server-ui</artifactId>
                <version>${version.spring.boot.admin}</version>
            </dependency>
            <!-- Extend library-->
            <dependency>
                <groupId>org.codehaus.jettison</groupId>
                <artifactId>jettison</artifactId>
                <version>${version.jettison}</version>
            </dependency>
            <dependency>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
                <version>${version.json}</version>
            </dependency>
            <dependency>
                <groupId>net.sf.json-lib</groupId>
                <artifactId>json-lib</artifactId>
                <version>${version.json-lib}</version>
            </dependency>
            <dependency>
                <groupId>commons-net</groupId>
                <artifactId>commons-net</artifactId>
                <version>${version.commons-net}</version>
            </dependency>
            <!-- 个推相关 -->
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-sdk-http</artifactId>
                <version>4.0.1.17</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-fastjson</artifactId>
                <version>1.0.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-sdk-base</artifactId>
                <version>4.0.0.22</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-sdk-template</artifactId>
                <version>4.0.0.16</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>protobuf-java</artifactId>
                <version>2.5.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <repositories>
        <repository>
            <id>public</id>
            <name>public</name>
            <url>http://172.19.103.43:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>public</id>
            <name>public</name>
            <url>http://172.19.103.43:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>2.10</version>
            </extension>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-http-lightweight</artifactId>
                <version>2.10</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <verbose/>
                        <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
                <version>3.1</version>
            </plugin>
        </plugins>
    </build>
</project>

+ 606 - 0
ehr-ms-parent-pom/pom.xml

@ -0,0 +1,606 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.yihu.ehr</groupId>
        <artifactId>ehr-cloud</artifactId>
        <version>1.2.0</version>
        <relativePath>../ehr-cloud/pom.xml</relativePath>
    </parent>
    <artifactId>ehr-ms-parent-pom</artifactId>
    <packaging>pom</packaging>
    <description>EHR micro service parent pom</description>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq-codegen-maven</artifactId>
                    <version>${jooq.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.7</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <recompressZippedFiles>false</recompressZippedFiles>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.5</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.18</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-help-plugin</artifactId>
                    <version>2.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.5</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.10.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.7</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.3</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.3</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.doxia</groupId>
                            <artifactId>doxia-module-markdown</artifactId>
                            <version>1.5</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.4</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.18.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.5</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.9.1</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.3.2</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.2</version>
                </plugin>
                <plugin>
                    <groupId>pl.project13.maven</groupId>
                    <artifactId>git-commit-id-plugin</artifactId>
                    <version>2.1.11</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${version.spring-boot}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <executions>
                    <execution>
                        <id>checkstyle-validation</id>
                        <phase>validate</phase>
                        <configuration>
                            <skip>true</skip>
                            <configLocation>src/checkstyle/checkstyle.xml</configLocation>
                            <suppressionsLocation>src/checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
                            <headerLocation>src/checkstyle/checkstyle-header.txt</headerLocation>
                            <propertyExpansion>checkstyle.build.directory=${project.build.directory}</propertyExpansion>
                            <encoding>UTF-8</encoding>
                            <consoleOutput>true</consoleOutput>
                            <failsOnError>true</failsOnError>
                            <includeTestSourceDirectory>true</includeTestSourceDirectory>
                        </configuration>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${version.java}</source>
                    <target>${version.java}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>enforce-rules</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireJavaVersion>
                                    <version>[1.8,)</version>
                                </requireJavaVersion>
                                <!--<requireProperty>
                                    <property>main.basedir</property>
                                </requireProperty>-->
                                <!--<requireProperty>
                                    <property>project.organization.name</property>
                                </requireProperty>-->
                                <!--<requireProperty>
                                    <property>project.name</property>
                                </requireProperty>-->
                                <!--<requireProperty>
                                    <property>project.description</property>
                                </requireProperty>-->
                            </rules>
                            <fail>true</fail>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Tests.java</include>
                    </includes>
                    <excludes>
                        <exclude>**/Abstract*.java</exclude>
                    </excludes>
                    <!--<systemPropertyVariables>-->
                    <!--<java.security.egd>file:/dev/./urandom</java.security.egd>-->
                    <!--<java.awt.headless>true</java.awt.headless>-->
                    <!--</systemPropertyVariables>-->
                    <argLine>-Xmx1024m</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>animal-sniffer-maven-plugin</artifactId>
                <configuration>
                    <skip>${disable.checks}</skip>
                    <signature>
                        <groupId>org.codehaus.mojo.signature</groupId>
                        <artifactId>java16</artifactId>
                        <version>1.0</version>
                    </signature>
                    <annotations>
                        <annotation>org.springframework.lang.UsesJava8</annotation>
                        <annotation>org.springframework.lang.UsesJava7</annotation>
                        <annotation>org.springframework.boot.lang.UsesUnsafeJava</annotation>
                    </annotations>
                </configuration>
                <executions>
                    <execution>
                        <id>enforce-java-6</id>
                        <phase>test</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>-->
        </plugins>
    </build>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-admin-gateway-model</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-elasticsearch</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-fastdfs</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-hbase</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-mysql</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-query</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-redis</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-solr</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-ehr-constants</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-entity</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <!--<dependency>-->
            <!--<groupId>com.yihu.ehr</groupId>-->
            <!--<artifactId>commons-metrics</artifactId>-->
            <!--<version>${version.ehr}</version>-->
            <!--</dependency>-->
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-profile-core</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-redis-mq</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-rest-model</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.hos</groupId>
                <artifactId>common-rest-model</artifactId>
                <version>${version.eip}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-ui-swagger</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-util</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-web</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <!--<dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-metrics</artifactId>
                <version>${version.ehr}</version>
            </dependency>-->
        </dependencies>
    </dependencyManagement>
    <!--
    profiles分为三种场景(dev,test,prod),三种部署模式(jar,war,docker).预计是9种模式,
    但目前仅使用到dev,test,prod的jar,test的war.若有需要可以组合配置这些部署模式.
    - dev的可执行jar包,在本机调试,不需要配置wagon参数。
    - test,prod的可执行jar包,需要在编译后传送到服务器上部署,故需配置wagon参数,参数可根据服务需要自行配置。
    - dev,test,prod的war包,编译后使用tomcat api部署,故需配置tomcat参数,参数可根据服务需要自行配置。
    -->
    <profiles>
        <profile>
            <id>dev-jar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>jar</packaging.type>
                <dependency.scope>compile</dependency.scope>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
                <!--<dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>-->
            </dependencies>
        </profile>
        <profile>
            <id>test-jar</id>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>jar</packaging.type>
                <dependency.scope>compile</dependency.scope>
                <wagonServerId/>
                <wagonUrl/>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>wagon-maven-plugin</artifactId>
                        <version>1.0</version>
                        <configuration>
                            <serverId>${wagonServerId}</serverId>
                            <fromFile>${project.build.directory}/${project.build.finalName}.jar</fromFile>
                            <url>${wagonUrl}</url>
                            <commands>
                                <command>pkill -f ${project.build.finalName}.jar</command>
                                <command>nohub java -Djava.security.egd=file:/dev/./urandom -jar
                                    ${project.build.finalName}.jar &amp;
                                </command>
                            </commands>
                            <displayCommandOutputs>true</displayCommandOutputs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>test-war</id>
            <activation>
                <property>
                    <name>spring.profiles.active</name>
                    <value>default,test</value>
                </property>
            </activation>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>war</packaging.type>
                <dependency.scope>provided</dependency.scope>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <scope>${dependency.scope}</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <url>http://localhost:8080/manager/text</url>
                            <server>tomcat8</server>
                            <username>deployer</username>
                            <password>jkzldeployer</password>
                            <path>/${project.artifactId}</path>
                            <update>true</update>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>prod-jar</id>
            <activation>
                <property>
                    <name>spring.profiles.active</name>
                    <value>default,prod</value>
                </property>
            </activation>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>war</packaging.type>
                <dependency.scope>compile</dependency.scope>
                <wagonServerId>11.1.2.21</wagonServerId>
                <wagonUrl>scp://user:password@11.1.2.21/home/root/ehr-release</wagonUrl>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <scope>${dependency.scope}</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>prod-war</id>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>war</packaging.type>
                <dependency.scope>provided</dependency.scope>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <scope>${dependency.scope}</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

+ 125 - 0
pom.xml

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.yihu.ehr</groupId>
        <artifactId>ehr-ms-parent-pom</artifactId>
        <version>1.2.0</version>
        <relativePath>ehr-ms-parent-pom/pom.xml</relativePath>
    </parent>
    <artifactId>svr-health-profile</artifactId>
    <!--<packaging>${packaging.type}</packaging>-->
    <packaging>war</packaging>
    <properties>
        <wagonServerId>192.168.1.220</wagonServerId>
        <wagonUrl>scp://sand:timeneverstop@192.168.1.221/home/sand/ehr-release</wagonUrl>
    </properties>
    <dependencies>
        <!-- true -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <!-- html转图片工具类 -->
        <dependency>
            <groupId>net.sf.cssbox</groupId>
            <artifactId>cssbox</artifactId>
            <version>4.11</version>
        </dependency>
        <!-- 模板工具类 -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.23</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-ehr-constants</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-util</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-data-mysql</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-rest-model</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.hos</groupId>
            <artifactId>common-rest-model</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-data-redis</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-ui-swagger</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-web</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-data-fastdfs</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-entity</artifactId>
        </dependency>
    </dependencies>
</project>

+ 34 - 0
src/main/java/com/yihu/ehr/HealthProfileService.java

@ -0,0 +1,34 @@
package com.yihu.ehr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.MetricExportAutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
@Configuration
@EnableAutoConfiguration(exclude = {
        SecurityAutoConfiguration.class})
@ComponentScan
@EnableDiscoveryClient
@EnableFeignClients
@EnableSpringDataWebSupport
public class HealthProfileService extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(HealthProfileService.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(HealthProfileService.class);
    }
}

+ 27 - 0
src/main/java/com/yihu/ehr/profile/config/TenantConfiguration.java

@ -0,0 +1,27 @@
package com.yihu.ehr.profile.config;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 *   ehr使用 feginClient 调用eip(涉及到app应用,标准等) 时,需要此类,增加请求头信息
 */
@Configuration
public class TenantConfiguration {
    @Value("${eip.tenant}")
    private String tenant;
    @Bean
    public RequestInterceptor tenantInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                requestTemplate.header("tenant_name", tenant);
            }
        };
    }
}

+ 62 - 0
src/main/java/com/yihu/ehr/profile/controller/prescription/ThridPrescriptionEndPoint.java

@ -0,0 +1,62 @@
package com.yihu.ehr.profile.controller.prescription;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.BaseRestEndPoint;
import com.yihu.ehr.profile.service.old.ThridPrescriptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.io.File;
import java.io.FileInputStream;
/**
 * Created by cwd on 2016/6/14.
 */
/*@RestController
@RequestMapping(ApiVersion.Version1_0+"/thridPrescription")
@Api(value = "第三方处方调阅服务", description = "第三方处方调阅服务")
@ApiIgnore*/
public class ThridPrescriptionEndPoint extends BaseRestEndPoint {
    @Autowired
    private ThridPrescriptionService thridPrescriptionService;
    @ApiOperation(value = "处方模板转图片")
    @RequestMapping(value = "/prescriptioToImage", method = RequestMethod.GET)
    public String prescriptioToImage(@ApiParam(value = "eventNo" ) @RequestParam String eventNo,
                                     @ApiParam(value = "orgId") @RequestParam(required=false) String orgId,
                                     @ApiParam(value = "cdaType") @RequestParam(required=false) String cdaType,
                                     @ApiParam(value = "version") @RequestParam(required=false) String version,
                                     @ApiParam(value = "height(默认600)") @RequestParam(required=false,defaultValue = "600") int height,
                                     @ApiParam(value = "width(默认400)") @RequestParam(required=false,defaultValue = "400") int width) {
        String filePath="";
        try{
             filePath= thridPrescriptionService.prescriptioToImage(eventNo,orgId,cdaType,version,height,width);
        }catch (Exception e){
            e.printStackTrace();
        }
        return filePath;
    }
    @ApiOperation(value = "imagetest")
    @RequestMapping(value = "/imagetest", method = RequestMethod.GET)
    public boolean test() throws Exception
    {
        File file=new File("E:/1.html");
        FileInputStream fis=new FileInputStream(file);
        byte[] buf = new byte[1024];
        StringBuffer sb=new StringBuffer();
        while((fis.read(buf))!=-1) {
            sb.append(new String(buf));
            buf = new byte[1024];//重新生成,避免和上次读取的数据重复
        }
        thridPrescriptionService.htmlToImage(sb.toString(),800,600);
        return true;
    }
}

+ 60 - 0
src/main/java/com/yihu/ehr/profile/controller/profile/ProfileCDAEndPoint.java

@ -0,0 +1,60 @@
package com.yihu.ehr.profile.controller.profile;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.profile.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
 * EndPoint - 档案CDA接口(兼容 pc & mobile)
 * 档案CDA接口
 * @author hzp
 * @version 1.0
 * @created 2017.06.22
 * @modifier progr1mmer
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "ProfileCDAEndPoint", description = "档案CDA接口", tags = "档案影像服务 - 档案CDA接口")
public class ProfileCDAEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ProfileCDAService profileCDAService;
    @ApiOperation("CDA分类")
    @RequestMapping(value = ServiceApi.Profiles.CDAClass, method = RequestMethod.GET)
    public List<Map<String, Object>> CDAClass(
            @ApiParam(name = "profile_id", value = "档案ID", required = true, defaultValue = "49229004X_000406450000000UX0_1485608518000")
            @RequestParam(value = "profile_id") String profile_id,
            @ApiParam(name = "template_name", value = "cda文档标题", defaultValue = "门诊摘要")
            @RequestParam(value = "template_name", required = false) String template_name) throws Exception {
        return profileCDAService.getCDAClass(profile_id, template_name);
    }
    @ApiOperation("CDA数据")
    @RequestMapping(value = ServiceApi.Profiles.CDAData, method = RequestMethod.GET)
    public Map<String, Object> CDAData(
            @ApiParam(name = "profile_id", value = "档案ID", required =  true, defaultValue = "449229004X_000001186960_1513419334000")
            @RequestParam(value = "profile_id") String profile_id,
            @ApiParam(name = "cda_document_id", value = "模板ID", required = true, defaultValue = "82e8a0b5317a11e7b186a1ae879a6c51")
            @RequestParam(value = "cda_document_id") String cda_document_id,
            @ApiParam(name = "transform", value = "是否转换成标准数据", defaultValue = "false")
            @RequestParam(value = "transform", required = false) boolean transform,
            @ApiParam(name = "mark", value = "是否转换成标准数据")
            @RequestParam(value = "mark", required = false) String mark) throws Exception {
        return profileCDAService.getCDAData(profile_id, true, mark, cda_document_id);
    }
}

+ 48 - 0
src/main/java/com/yihu/ehr/profile/controller/profile/ProfileDiseaseEndPoint.java

@ -0,0 +1,48 @@
package com.yihu.ehr.profile.controller.profile;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.profile.service.ProfileDiseaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
 * EndPoint - 健康问题
 * Created by progr1mmer on 2017/12/12.
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "ProfileDiseaseEndPoint", description = "健康问题", tags = {"档案影像服务 - 健康问题"})
public class ProfileDiseaseEndPoint extends EnvelopRestEndPoint{
    @Autowired
    private ProfileDiseaseService profileDiseaseService;
    @ApiOperation("慢病情况")
    @RequestMapping(value = ServiceApi.Profiles.HealthProblem, method = RequestMethod.GET)
    public List<Map<String, Object>> healthProblem(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) throws Exception {
        return profileDiseaseService.getHealthProblem(demographic_id);
    }
    @ApiOperation("历史健康情况 - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.HealthCondition, method = RequestMethod.GET)
    public List<Map<String, Object>> healthCondition(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) {
        return profileDiseaseService.getHealthCondition(demographic_id);
    }
}

+ 77 - 0
src/main/java/com/yihu/ehr/profile/controller/profile/ProfileEventEndPoint.java

@ -0,0 +1,77 @@
package com.yihu.ehr.profile.controller.profile;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.profile.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
 * EndPoint - 档案事件接口(兼容 pc & mobile)
 * 档案事件接口
 * @author hzp
 * @version 1.0
 * @created 2017.06.22
 * @modifier progr1mmer
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "ProfileEventEndPoint", description = "档案事件接口", tags = {"档案影像服务 - 档案事件接口"})
public class ProfileEventEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ProfileEventService patientEvent;
    @ApiOperation("门诊/住院事件(时间轴)")
    @RequestMapping(value = ServiceApi.Profiles.MedicalEvents, method = RequestMethod.GET)
    public List<Map<String, Object>> visits (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "filter", value = "过滤条件(key1=val1;key2=val2)")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "blurry_type", value = "针对需要对特殊档案类型进行查询的参数" +
                    "(0-门诊 1-住院 2-体检 3-影像 4-检查 5-检验 6-妇幼 7-免疫);" +
                    "此处有值的话filter参数中不能再包含event_type")
            @RequestParam(value = "blurry_type", required = false) String blurry_type,
            @ApiParam(name = "date", value = "时间,格式如:{\"start\":\"2018-01-01T00:00:00Z\",\"end\":\"2018-02-01T00:00:00Z\",\"month\":\"2018-03\"}")
            @RequestParam(value = "date", required = false) String date,
            @ApiParam(name = "searchParam", value = "搜索条件(此参数只针对机构和诊断)")
            @RequestParam(value = "searchParam", required = false) String searchParam) throws Exception {
        return patientEvent.visits(demographic_id, filter, blurry_type, date, searchParam);
    }
    @ApiOperation("最近的一条就诊记录 - 上饶APP")
    @RequestMapping(value = ServiceApi.Profiles.RecentMedicalEvents, method = RequestMethod.GET)
    public Map<String, Object> recentVisit (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) throws Exception {
        return patientEvent.recentVisit(demographic_id, -30);
    }
    @ApiOperation("近期就诊列表 - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.RecentVisits, method = RequestMethod.GET)
    public List<Map<String, Object>> recentVisits (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) throws Exception {
        return patientEvent.recentVisits(demographic_id, -180);
    }
    @ApiOperation("近期就诊详情 - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.RecentVisitsSub, method = RequestMethod.GET)
    public Map<String, Object> recentVisitsSub (
            @ApiParam(name = "profile_id", value = "档案ID", required = true, defaultValue = "49229004X_000000481520_1513758586000")
            @RequestParam(value = "profile_id") String profile_id) throws Exception {
        return patientEvent.recentVisitsSub(profile_id);
    }
}

+ 74 - 0
src/main/java/com/yihu/ehr/profile/controller/profile/ProfileInspectionEndPoint.java

@ -0,0 +1,74 @@
package com.yihu.ehr.profile.controller.profile;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.profile.model.InspectionInfo;
import com.yihu.ehr.profile.service.ProfileInspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
 * EndPoint - 检查检验
 * Created by progr1mmer on 2018/3/13.
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "ProfileInspectionEndPoint", description = "检查检验", tags = {"档案影像服务 - 检查检验"})
public class ProfileInspectionEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ProfileInspectionService profileInspectionService;
    @ApiOperation("检查检验记录 - 上饶APP")
    @RequestMapping(value = ServiceApi.Profiles.InspectionRecords, method = RequestMethod.GET)
    public List inspectionRecords(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "filter", value = "健康问题health_problem?hpCode(不传默认查找所有)")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "date", value = "时间 {'start':'2018-03-12T12:00:00Z','end':'2018-03-15T12:00:00Z'}")
            @RequestParam(value = "date", required = false) String date,
            @ApiParam(name = "searchParam", value = "搜索条件")
            @RequestParam(value = "searchParam", required = false) String searchParam) throws Exception {
        return profileInspectionService.inspectionRecords(demographic_id, filter, date, searchParam);
    }
    @ApiOperation("检查检验记录统计 - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.InspectionStatistics, method = RequestMethod.GET)
    public List<InspectionInfo> inspectionStatistics(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "table", required = true, value = "HDSD00_79 - 检查, HDSD00_77 - 检验")
            @RequestParam(value = "table") String table) throws Exception {
        return profileInspectionService.inspectionStatistics(demographic_id, table);
    }
    @ApiOperation("检查检验记录子项详情(某次检验记录) - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.InspectionStatisticsOneSub, method = RequestMethod.GET)
    public Map<String, String> inspectionStatisticsOneSub(
            @ApiParam(name = "profile_id", value = "档案ID", required = true, defaultValue = "49236052X_17022473_1503229954000$HDSD00_77$3")
            @RequestParam(value = "profile_id") String profile_id) throws Exception {
        return profileInspectionService.inspectionStatisticsOneSub(profile_id);
    }
    @ApiOperation("检查检验记录子项详情(相关检验全部记录) - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.InspectionStatisticsAllSub, method = RequestMethod.GET)
    public Map<String, Map<String, Integer>> inspectionStatisticsAllSub(
            @ApiParam(name = "demographic_id", value = "身份证号码", required = true, defaultValue = "9d2970b8-dac5-40bb-816d-d3e841a29afc")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "name", required = true, value = "检验名称")
            @RequestParam(value = "name") String name) throws Exception {
        return profileInspectionService.inspectionStatisticsAllSub(demographic_id, name);
    }
}

+ 124 - 0
src/main/java/com/yihu/ehr/profile/controller/profile/ProfileMedicationEndPoint.java

@ -0,0 +1,124 @@
package com.yihu.ehr.profile.controller.profile;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.profile.model.DrugInfo;
import com.yihu.ehr.profile.service.ProfileMedicationService;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * EndPoint - 用药记录
 * Created by progr1mmer on 2018/3/13.
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "ProfileMedicationEndPoint", description = "用药记录", tags = {"档案影像服务 - 用药记录"})
public class ProfileMedicationEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ProfileMedicationService profileMedicationService;
    @ApiOperation("用药排行")
    @RequestMapping(value = ServiceApi.Profiles.MedicationRanking, method = RequestMethod.GET)
    public Map<String, Integer> medicationRanking(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "filter", value = "过滤条件org_code=xxxxx")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "hp_code", value = "健康问题代码,不传默认查找所有(接口改造后此参数可在filter中体现)")
            @RequestParam(value = "hp_code", required = false) String hp_code,
            @ApiParam(name = "date", value = "某个时间段内(不传默认查找所有)")
            @RequestParam(value = "date", required = false) String date) throws Exception {
        return profileMedicationService.medicationRanking(demographic_id, filter, hp_code, date);
    }
    @ApiOperation("用药排行(带药物类型)")
    @RequestMapping(value = ServiceApi.Profiles.MedicationRankingWithTable, method = RequestMethod.GET)
    public List<DrugInfo> medicationRankingWithTable (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "filter", value = "过滤条件org_code=xxxxx")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "hp_code", value = "健康问题代码,不传默认查找所有(接口改造后此参数可在filter中体现)")
            @RequestParam(value = "hp_code", required = false) String hp_code,
            @ApiParam(name = "date", value = "某个时间段内(不传默认查找所有)")
            @RequestParam(value = "date", required = false) String date,
            @ApiParam(name = "table", value = "HDSD00_83 - 中药, HDSD00_84 - 西药")
            @RequestParam(value = "table", required = false) String table) throws Exception {
        return profileMedicationService.medicationRankingWithTable(demographic_id, filter, hp_code, date, table);
    }
    @ApiOperation("用药记录 - 上饶PP")
    @RequestMapping(value = ServiceApi.Profiles.MedicationRecords, method = RequestMethod.GET)
    public List<Map<String, Object>> medicationRecords(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "filter", value = "健康问题health_problem?hpCode(不传默认查找所有)")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "date", value = "时间")
            @RequestParam(value = "date", required = false) String date,
            @ApiParam(name = "key_word", value = "关键字(药品)")
            @RequestParam(value = "key_word", required = false) String key_word) throws Exception {
        return profileMedicationService.medicationRecords(demographic_id, filter, date, key_word);
    }
    @ApiOperation("用药记录 - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.MedicationRecordsPage, method = RequestMethod.GET)
    public Envelop medicationRecordsPage (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "filter", value = "健康问题health_problem?hpCode(不传默认查找所有)")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "date", value = "时间")
            @RequestParam(value = "date", required = false) String date,
            @ApiParam(name = "key_word", value = "关键字(药品)")
            @RequestParam(value = "key_word", required = false) String key_word,
            @ApiParam(name = "page", value = "页码", required = true)
            @RequestParam(value = "page") Integer page,
            @ApiParam(name = "size", value = "分页大小", required = true)
            @RequestParam(value = "size") Integer size) throws Exception {
        List<Map<String, Object>> list = profileMedicationService.medicationRecords(demographic_id, filter, date, key_word);
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        envelop.setCurrPage(page);
        envelop.setPageSize(size);
        envelop.setTotalPage(list.size() % size > 0 ? list.size() / size + 1 : list.size() / size);
        envelop.setTotalCount(list.size());
        List result = new ArrayList();
        for (int i = (page - 1) * size; i < page * size; i ++) {
            if (i > list.size() - 1) {
                break;
            }
            result.add(list.get(i));
        }
        envelop.setDetailModelList(result);
        return envelop;
    }
    @ApiOperation("最近的处方清单 - 档案浏览器")
    @RequestMapping(value = ServiceApi.Profiles.RecentMedicationSub, method = RequestMethod.GET)
    public Envelop recentMedicationSub(
            @ApiParam(name = "demographic_id", value = "身份证号码", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "page", value = "页码", required = true)
            @RequestParam(value = "page") Integer page,
            @ApiParam(name = "size", value = "分页大小", required = true)
            @RequestParam(value = "size") Integer size) throws Exception {
        return profileMedicationService.recentMedicationSub(demographic_id, null, page, size);
    }
}

+ 40 - 0
src/main/java/com/yihu/ehr/profile/controller/profile/ProfileMotherhoodEndPoint.java

@ -0,0 +1,40 @@
package com.yihu.ehr.profile.controller.profile;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.profile.service.ProfileMotherhoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
 * Created by progr1mmer on 2018/5/14.
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "ProfileMotherhoodEndPoint", description = "孕产情况", tags = {"档案影像服务 - 孕产情况"})
public class ProfileMotherhoodEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ProfileMotherhoodService profileMotherhoodService;
    @ApiOperation("概况")
    @RequestMapping(value = ServiceApi.Profiles.MotherhoodOverview, method = RequestMethod.GET)
    public Map<String, Object> overview(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "version", value = "版本号", defaultValue = "59083976eebd")
            @RequestParam(value = "version", required = false) String version) throws Exception {
        return profileMotherhoodService.overview(demographic_id, version);
    }
}

+ 74 - 0
src/main/java/com/yihu/ehr/profile/controller/profile/ProfilePatientEndPoint.java

@ -0,0 +1,74 @@
package com.yihu.ehr.profile.controller.profile;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.profile.service.ProfileInfoBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
 * EndPoint - 患者基本信息(兼容 pc & mobile)
 * Created by progr1mmer on 2018/1/7.
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "ProfilePatientEndPoint ", description = "患者基本信息", tags = {"档案影像服务 - 患者基本信息"})
public class ProfilePatientEndPoint extends EnvelopRestEndPoint{
    @Autowired
    private ProfileInfoBaseService patientInfoBaseService;
    @ApiOperation("患者基本信息OK")
    @RequestMapping(value = ServiceApi.Profiles.ProfileInfo, method = RequestMethod.GET)
    public Map<String, Object> profileInfo(
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id,
            @ApiParam(name = "version", value = "版本号", defaultValue = "59083976eebd")
            @RequestParam(value = "version", required = false) String version) throws Exception {
        return patientInfoBaseService.getPatientInfo(demographic_id, version);
    }
    @ApiOperation("既往史 - 上饶APP")
    @RequestMapping(value = ServiceApi.Profiles.PastHistory, method = RequestMethod.GET)
    public List<Map<String, Object>> pastHistory (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) throws Exception {
        return patientInfoBaseService.pastHistory(demographic_id);
    }
    @ApiOperation("过敏史 - 上饶APP")
    @RequestMapping(value = ServiceApi.Profiles.AllergensHistory, method = RequestMethod.GET)
    public Map<String, Object> allergensHistory (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) throws Exception  {
        return patientInfoBaseService.allergensHistory(demographic_id);
    }
    @ApiOperation("家族史 - 上饶APP")
    @RequestMapping(value = ServiceApi.Profiles.FamilyHistory, method = RequestMethod.GET)
    public Map<String, Object> familyHistory (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) {
        return patientInfoBaseService.familyHistory(demographic_id);
    }
    @ApiOperation("个人史 - 上饶APP")
    @RequestMapping(value = ServiceApi.Profiles.PersonHistory, method = RequestMethod.GET)
    public Map<String, Object> personHistory (
            @ApiParam(name = "demographic_id", value = "身份证号", required = true, defaultValue = "362301195002141528")
            @RequestParam(value = "demographic_id") String demographic_id) {
        return patientInfoBaseService.personHistory(demographic_id);
    }
}

+ 258 - 0
src/main/java/com/yihu/ehr/profile/controller/sanofi/SanofiEndPoint.java

@ -0,0 +1,258 @@
package com.yihu.ehr.profile.controller.sanofi;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.LisEntry;
import com.yihu.ehr.lang.SpringContext;
import com.yihu.ehr.model.resource.MStdTransformDto;
import com.yihu.ehr.profile.feign.TransformClient;
import com.yihu.ehr.profile.util.BasicConstant;
import com.yihu.ehr.profile.service.old.SanofiService;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.io.IOException;
import java.util.*;
/**
 * 康赛(赛诺菲)项目患者体征数据提取API。体征数据包括:
 * - 体温、呼吸与脉搏
 * - 血液检验数据
 * - 尿液检验数据
 *
 * @author Sand
 * @version 1.0
 * @created 2015.12.26 16:08
 */
/*@RestController
@RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "赛诺菲数据服务", description = "赛诺菲项目体征数据提取服务")
@ApiIgnore*/
public class SanofiEndPoint {
    @Autowired
    private SanofiService sanofiService;
    @Autowired
    private TransformClient transformClient;
    @Autowired
    private ObjectMapper objectMapper;
    @ApiOperation(value = "获取体征数据", notes = "获取体征数据")
    @RequestMapping(value = ServiceApi.SanofiSupport.PhysicSigns, method = RequestMethod.POST)
    public ResponseEntity<String> getBodySigns(
            @ApiParam(value = "身份证号", defaultValue = "360101200006011131")
            @RequestParam(value = "demographic_id", required = false) String demographicId,
            @ApiParam(value = "患者姓名")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "联系电话")
            @RequestParam(value = "telephone", required = false) String telephone,
            @ApiParam(value = "性别")
            @RequestParam(value = "gender", required = false) String gender,
            @ApiParam(value = "出生日期")
            @RequestParam(value = "birthday", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday,
            @ApiParam(value = "起始日期", defaultValue = "1900-01-01")
            @RequestParam("since") @DateTimeFormat(pattern = "yyyy-MM-dd") Date since,
            @ApiParam(value = "结束日期", defaultValue = "2016-10-01")
            @RequestParam("to") @DateTimeFormat(pattern = "yyyy-MM-dd") Date to) throws Exception {
        List<Map<String, Object>> profileList = sanofiService.findByDemographic(demographicId, name, telephone, gender, birthday);
        List<String> profileIds = new ArrayList<>();
        for (Map<String, Object> profile : profileList) {
            String profileId = (String) profile.get("rowkey");
            profileIds.add(profileId);
        }
        if (profileIds.size() == 0) return new ResponseEntity<>("", HttpStatus.NOT_FOUND);
        ObjectMapper objectMapper = SpringContext.getService(ObjectMapper.class);
        ArrayNode document = objectMapper.createArrayNode();
        ObjectNode section = objectMapper.createObjectNode();
        convert(section, profileIds, since, to);
        document.addPOJO(section);
        return new ResponseEntity<>(document.toString(), HttpStatus.OK);
    }
    private void convert(ObjectNode document, List<String> profileIds, Date since, Date to) throws Exception {
        JsonNode section;
        String[] innerCodes;
        MStdTransformDto stdTransformDto = new MStdTransformDto();
        List<Map<String, Object>> dataSetList;
        String query;
        // 人口学信息
        query = "{\"q\":\"profile_id:" + profileIds.get(0);
        dataSetList = sanofiService.getDataSet(BasicConstant.patientInfo, query);
        stdTransformDto.setVersion("56395d75b854");
        stdTransformDto.setSource(objectMapper.writeValueAsString(dataSetList));
        dataSetList = transformClient.stdTransformList(objectMapper.writeValueAsString(stdTransformDto));
        if (dataSetList.size() > 0) {
            section = document.with("demographic_info");
            innerCodes = new String[]{
                    "HDSA00_01_012",                   //生日
                    "HDSA00_01_011",                   //性别代码,男1,女2
//                    "HDSA00_01_011_VALUE",             //性别文字描述
                    "HDSA00_01_017",                   //身份证号
                    "HDSD00_01_002"};                  //姓名
            mergeData(section, dataSetList, innerCodes);
        }
        // 生命体征:住院护理体征记录 // TODO: 2016/7/5 暂时未资源化
        document.withArray("physical_exam");
//        dataSet = profile.getDataSet("HDSD00_08");
//        for (String profileId : profileIds) {
//            section = document.withArray("physical_exam");
//            query = "{\"q\":\"profile_id:" + profileIds.get(0);
//            query += " AND EHR_000384:[" + DateTimeUtil.utcDateTimeFormat(since)+" TO " + DateTimeUtil.utcDateTimeFormat(since) + "]\"}".replace(" ","+");
//            dataSetList = sanofiService.getDataSet("生命体征", query);
//            stdTransformDto.setVersion("56395d75b854");
//            stdTransformDto.setSource(objectMapper.writeValueAsString(dataSetList));
//            dataSetList = transformClient.stdTransformList(objectMapper.writeValueAsString(stdTransformDto));
//            if (dataSetList != null && dataSetList.size() > 0) {
//                innerCodes = new String[]{
//                        "HDSD00_08_025",   // 呼吸频率(次/min)
//                        "HDSD00_08_075",   // 体温
//                        "HDSD00_08_041",   // 脉率(次/min)
//                        "HDSD00_08_060",   // 收缩压(mmHg)
//                        "HDSD00_08_068",   // 舒张压(mmHg)
//                        "HDSD00_08_036"    // 记录日期时间
//                };
//                mergeData(section, dataSetList, innerCodes);
//            }
//        }
        // 检验
        for (String profileId : profileIds) {
            section = document.withArray("lis");
            query = "{\"q\":\"profile_id:" + profileId;
            query += " AND EHR_000384:[" + DateTimeUtil.utcDateTimeFormat(since) + " TO " + DateTimeUtil.utcDateTimeFormat(to) + "]";
            query += "\"}";
            query = query.replace(" ", "+");
            dataSetList = sanofiService.getDataSet(BasicConstant.laboratoryProject, query);
            stdTransformDto.setVersion("56395d75b854");
            stdTransformDto.setSource(objectMapper.writeValueAsString(dataSetList));
            dataSetList = transformClient.stdTransformList(objectMapper.writeValueAsString(stdTransformDto));
            if (dataSetList != null && dataSetList.size() > 0) {
                innerCodes = new String[]{
                        "JDSD02_03_13", // 中文名
                        "JDSD02_03_14", // 英文名
                        "JDSD02_03_04", // 结果值
                        "JDSD02_03_05", // 结果类型
                        "HDSD00_01_547",// 单位
                        "JDSD02_03_06", // 参考值上限
                        "JDSD02_03_07", // 参考值下限
                        "JDSD02_03_10"  // 创建时间
                };
                //检验项目过滤 符合要求的项目有{"PRO", "CREA", "GLU", "TCHO", "HDL-C", "TG", "K", "HbAc1", "GLU(2h)", "cTnI", "PRO", "UTP"}
                for (Map<String, Object> dataSet : dataSetList) {
                    String JDSD02_03_14 = (String) dataSet.get("JDSD02_03_14");
                    String JDSD02_03_04 = (String) dataSet.get("JDSD02_03_04");
                    String[] entryNames = LisEntry.ENTRY_NAME;
                    List<String> entryNameList = Arrays.asList(entryNames);
                    if (entryNameList.contains(JDSD02_03_14) && !StringUtils.isEmpty(JDSD02_03_04)) {
                        mergeData(section, dataSetList, innerCodes);
                    }
                    mergeData(section, dataSetList, innerCodes);
                }
            }
        }
        // 临时医嘱
        for (String profileId : profileIds) {
            section = document.withArray("stat_order");
            query = "{\"q\":\"profile_id:" + profileId;
            query += " AND EHR_000207:[" + DateTimeUtil.utcDateTimeFormat(since) + " TO " + DateTimeUtil.utcDateTimeFormat(to) + "]";
            query += "\"}";
            query = query.replace(" ", "+");
            dataSetList = sanofiService.getDataSet(BasicConstant.hospitalizedOrdersTemporary, query);
            stdTransformDto.setVersion("56395d75b854");
            stdTransformDto.setSource(objectMapper.writeValueAsString(dataSetList));
            dataSetList = transformClient.stdTransformList(objectMapper.writeValueAsString(stdTransformDto));
            if (dataSetList != null && dataSetList.size() > 0) {
                innerCodes = new String[]{
                        "HDSD00_15_020",  //医嘱下嘱时间
                        "HDSD00_15_028"   //医嘱名称
                };
                mergeData(section, dataSetList, innerCodes);
            }
        }
        // 长期医嘱
        for (String profileId : profileIds) {
            section = document.withArray("stand_order");
            query = "{\"q\":\"profile_id:" + profileId;
            query += " AND EHR_000207:[" + DateTimeUtil.utcDateTimeFormat(since) + " TO " + DateTimeUtil.utcDateTimeFormat(to) + "]";
            query += "\"}";
            query = query.replace(" ", "+");
            dataSetList = sanofiService.getDataSet(BasicConstant.hospitalizedOrdersLongtime, query);
            stdTransformDto.setVersion("56395d75b854");
            stdTransformDto.setSource(objectMapper.writeValueAsString(dataSetList));
            dataSetList = transformClient.stdTransformList(objectMapper.writeValueAsString(stdTransformDto));
            if (dataSetList != null && dataSetList.size() > 0) {
                innerCodes = new String[]{
                        "HDSD00_15_020",  //医嘱下嘱时间
                        "HDSD00_15_026",  //医嘱停嘱时间
                        "HDSD00_15_028"   //医嘱名称
                };
                mergeData(section, dataSetList, innerCodes);
            }
        }
    }
    private void mergeData(JsonNode section, List<Map<String, Object>> dataSetList, String[] metaDataCodes) throws IOException {
        ObjectMapper objectMapper = SpringContext.getService(ObjectMapper.class);
        if (section.isArray()) {
            ArrayNode array = (ArrayNode) section;
            for (Map<String, Object> dataSet : dataSetList) {
                ObjectNode arrayNode = objectMapper.createObjectNode();
                boolean flag = false;
                for (String metaDataCode : metaDataCodes) {
                    String value = (String) dataSet.get(metaDataCode);
                    if (!StringUtils.isEmpty(value)) {
                        flag = true;
                    }
                    arrayNode.put(metaDataCode, StringUtils.isEmpty(value) ? "" : value);
                }
                if (flag) {
                    array.addPOJO(arrayNode);
                }
            }
        } else if (section.isObject()) {
            //人口学信息只要取一条记录
            Map<String, Object> dataSet = dataSetList.get(0);
            ObjectNode objectNode = (ObjectNode) section;
            for (String metaDataCode : metaDataCodes) {
                String value = dataSet.get(metaDataCode) == null ? null : dataSet.get(metaDataCode).toString();
                objectNode.put(metaDataCode, StringUtils.isEmpty(value) ? "" : value);
            }
        }
    }
}

+ 236 - 0
src/main/java/com/yihu/ehr/profile/controller/template/TemplateEndPoint.java

@ -0,0 +1,236 @@
package com.yihu.ehr.profile.controller.template;
import com.google.common.io.Files;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.profile.model.ArchiveTemplate;
import com.yihu.ehr.profile.service.template.ArchiveTemplateService;
import com.yihu.ehr.util.compress.Zipper;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.List;
/**
 * @author Sand
 * @version 1.0
 * @created 2016.04.08 9:45
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "健康档案模板服务", description = "维护/获取健康档案模板", tags = {"档案影像服务 - CDA模板"})
public class TemplateEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ArchiveTemplateService templateService;
    @ApiOperation(value = "创建模板")
    @RequestMapping(value = ServiceApi.ProfileTemplate.Templates,  method = RequestMethod.POST)
    public Envelop saveTemplate(
            @ApiParam(name = "model", value = "健康档案模板")
            @RequestParam(value = "model") String model) throws Exception {
        ArchiveTemplate template = toEntity(model, ArchiveTemplate.class);
        String filters = "cdaVersion=" + template.getCdaVersion() + ";cdaDocumentId=" + template.getCdaDocumentId();
        if (templateService.search(filters).size() > 0) {
            return failed("该类型模版已存在!");
        }
        templateService.save(template);
        return success(true);
    }
    @ApiOperation(value = "删除模板")
    @RequestMapping(value = ServiceApi.ProfileTemplate.Template, method = RequestMethod.DELETE)
    public void deleteTemplate (
            @ApiParam(name = "id", value = "模板ID")
            @PathVariable(value = "id") int id) throws Exception {
        templateService.delete(id);
    }
    @ApiOperation(value = "更新模板属性")
    @RequestMapping(value = ServiceApi.ProfileTemplate.Template, method = RequestMethod.PUT)
    public Envelop getTemplate(
            @ApiParam(name = "id", value = "模板ID")
            @PathVariable(value = "id") int id,
            @ApiParam(name = "model", value = "模板JSON")
            @RequestParam(value = "model") String model,
            @ApiParam(name = "mode", value = "模式:copy(拷贝),update(更新)")
            @RequestParam(value = "mode") String mode) throws Exception {
        ArchiveTemplate tpl = templateService.getTemplate(id);
        if (null == tpl) {
            return failed("更新模板不存在!");
        }
        ArchiveTemplate _tpl = toEntity(model, ArchiveTemplate.class);
        if (!tpl.getCdaVersion().equals(_tpl.getCdaVersion()) || !tpl.getCdaDocumentId().equals(_tpl.getCdaDocumentId())) {
            String filters = "cdaVersion=" + _tpl.getCdaVersion() + ";cdaDocumentId=" + _tpl.getCdaDocumentId();
            if (templateService.search(filters).size() > 0) {
                return failed("该类型模版已存在!");
            }
        }
        if ("copy".equals(mode)) {
            _tpl.setId(0);
            templateService.save(_tpl);
            return success(true);
        }
        tpl.setTitle(_tpl.getTitle());
        tpl.setCdaVersion(_tpl.getCdaVersion());
        tpl.setCdaDocumentId(_tpl.getCdaDocumentId());
        tpl.setCdaDocumentName(_tpl.getCdaDocumentName());
        tpl.setType(_tpl.getType());
        templateService.save(tpl);
        return success(true);
    }
    @ApiOperation(value = "更新模板展示文件")
    @RequestMapping(value = ServiceApi.ProfileTemplate.TemplateCtn, method = RequestMethod.POST)
    public boolean setTemplateContent(
            @ApiParam(name = "id", value = "模板ID")
            @PathVariable(value = "id") int id,
            @ApiParam(name = "pc", value = "true表示PC端,false表示移动端")
            @RequestParam(value = "pc", defaultValue = "true") boolean pc,
            @ApiParam(value = "展示文件")
            @RequestPart() MultipartFile file) throws Exception {
        ArchiveTemplate template = templateService.getTemplate(id);
        if (template == null) {
            return false;
        }
        InputStream stream = file.getInputStream();
        template.setContent(pc, stream);
        templateService.save(template);
        return true;
    }
    @ApiOperation(value = "获取模板列表")
    @RequestMapping(value = ServiceApi.ProfileTemplate.Templates, method = RequestMethod.GET)
    public Envelop getTemplates(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小")
            @RequestParam(value = "size", defaultValue = "15", required = false) int size,
            @ApiParam(name = "page", value = "页码")
            @RequestParam(value = "page", defaultValue = "1", required = false) int page) throws ParseException {
        List<ArchiveTemplate> templateList = templateService.search(fields, filters, sorts, page, size);
        int count = (int)templateService.getCount(filters);
        Envelop envelop = getPageResult(templateList, count, page, size);
        return envelop;
    }
    @ApiOperation(value = "获取模板")
    @RequestMapping(value = ServiceApi.ProfileTemplate.Template, method = RequestMethod.GET)
    public ArchiveTemplate getTemplate(
            @ApiParam(name = "id", value = "模板ID")
            @PathVariable(value = "id") int id) {
        ArchiveTemplate template = templateService.getTemplate(id);
        return template;
    }
    @ApiOperation(value = "判断模版名称是否已存在")
    @RequestMapping(value = ServiceApi.ProfileTemplate.TemplateTitleExistence, method = RequestMethod.GET)
    public boolean isNameExist(
            @ApiParam(name = "title", value = "标题")
            @RequestParam(value = "title") String title,
            @ApiParam(name = "version", value = "版本")
            @RequestParam(value = "version") String version) {
        return templateService.isExistName(title, version);
    }
    @ApiOperation(value = "下载模板展示文件")
    @RequestMapping(value = ServiceApi.ProfileTemplate.TemplateCtn, method = RequestMethod.GET)
    public void getTemplateContent(
            @ApiParam(name = "id", value = "模板ID")
            @PathVariable(value = "id") int id,
            @ApiParam(value = "true表示PC端,false表示移动端")
            @RequestParam(value = "pc", defaultValue = "true") boolean pc,
            HttpServletResponse response) throws Exception {
        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        ArchiveTemplate template = templateService.getTemplate(id);
        if (template == null) {
            throw new ApiException(HttpStatus.NO_CONTENT, ErrorCode.NO_CONTENT, "Template not found");
        }
        if (pc && StringUtils.isEmpty(template.getPcUrl())) {
            throw new ApiException(HttpStatus.NO_CONTENT, ErrorCode.NO_CONTENT, "Template content is empty.");
        }
        if (!pc && StringUtils.isEmpty(template.getMobileUrl())) {
            throw new ApiException(HttpStatus.NO_CONTENT, ErrorCode.NO_CONTENT, "Template content is empty.");
        }
        IOUtils.copy(new ByteArrayInputStream(template.getContent(pc)), response.getOutputStream());
        String extension = ".file";
        if (pc) {
            if (template.getPcUrl().split("\\.").length == 2) {
                extension = template.getPcUrl().split("\\.")[1];
            }
        } else {
            if (template.getMobileUrl().split("\\.").length == 2) {
                extension = template.getMobileUrl().split("\\.")[1];
            }
        }
        response.setHeader("Content-Disposition", "attachment; filename=" + template.getTitle() + "." + extension);
        response.flushBuffer();
    }
    @ApiOperation(value = "打包下载模板")
    @RequestMapping(value = ServiceApi.ProfileTemplate.TemplatesDownloads, method = RequestMethod.GET)
    public void downloadTemplates(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "organizationCode=41872607-9")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", defaultValue = "+id", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小")
            @RequestParam(value = "size", defaultValue = "15", required = false) int size,
            @ApiParam(name = "page", value = "页码")
            @RequestParam(value = "page", defaultValue = "1", required = false) int page,
            HttpServletResponse response) throws Exception {
        File tempFile = Files.createTempDir();
        String zipName = tempFile.getAbsolutePath() + ".zip";
        File zipFile = null;
        try {
            // download and zip templates
            List<ArchiveTemplate> templateList = templateService.search("", filters, sorts, reducePage(page), size);
            for (ArchiveTemplate template : templateList) {
                byte pc[] = template.getContent(true);
                byte mobile[] = template.getContent(false);
                writeTplContent(tempFile, template, "-pc.html", pc);
                writeTplContent(tempFile, template, "-mobile.html", mobile);
            }
            zipFile = new Zipper().zipFile(tempFile, zipName);
            // send file
            IOUtils.copy(new ByteArrayInputStream(FileUtils.readFileToByteArray(zipFile)), response.getOutputStream());
            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
            response.setHeader("Content-Disposition", "attachment; filename=" + tempFile.getName() + ".zip");
            response.flushBuffer();
        } finally {
            FileUtils.deleteQuietly(tempFile);
            FileUtils.deleteQuietly(zipFile);
        }
    }
    private void writeTplContent(File location, ArchiveTemplate template, String suffix, byte content[]) throws IOException {
        if (content != null) {
            String fileName = location.getAbsolutePath() + File.separator + template.getId() + suffix;
            FileUtils.writeByteArrayToFile(new File(fileName), content);
        }
    }
}

+ 21 - 0
src/main/java/com/yihu/ehr/profile/dao/ArchiveTemplateDao.java

@ -0,0 +1,21 @@
package com.yihu.ehr.profile.dao;
import com.yihu.ehr.profile.model.ArchiveTemplate;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author Sand
 * @version 1.0
 * @created 2016.04.08 11:56
 */
public interface ArchiveTemplateDao extends PagingAndSortingRepository<ArchiveTemplate, Integer> {
    List<ArchiveTemplate> findByTitleAndCdaVersion (String title, String cdaVersion);
    List<ArchiveTemplate> findByCdaVersionAndAndCdaCode (String version, String code);
    List<ArchiveTemplate> findByCdaDocumentId(List<String> docIds);
}

+ 51 - 0
src/main/java/com/yihu/ehr/profile/feign/CDADocumentClient.java

@ -0,0 +1,51 @@
package com.yihu.ehr.profile.feign;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.profile.model.MCDADocument;
import com.yihu.hos.model.standard.MCdaDataSet;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;
/**
 * @author Sand
 * @version 1.0
 * @created 2016.04.11 9:03
 */
@ApiIgnore
@RequestMapping(ApiVersion.Version1_0)
@FeignClient(MicroServices.Standard)
public interface CDADocumentClient {
    @RequestMapping(value = ServiceApi.Standards.Documents, method = RequestMethod.GET)
    List<MCDADocument> getCDADocumentByIds(@RequestParam(value = "fields") String fields,
                                           @RequestParam(value = "filters") String filters,
                                           @RequestParam(value = "sorts") String sorts,
                                           @RequestParam(value = "size") int size,
                                           @RequestParam(value = "page") int page,
                                           @RequestParam(value = "version") String version);
    @RequestMapping(value = ServiceApi.Standards.Document, method = RequestMethod.GET)
    MCDADocument getCDADocuments(@RequestParam(value = "version") String version,
                                           @RequestParam(value = "id") String id);
    @RequestMapping(value = ServiceApi.Standards.DocumentList, method = RequestMethod.GET)
    Map<String,MCDADocument> getCDADocumentsList(@RequestParam(value = "version") String version,
                                 @RequestParam(value = "idList") String[] id);
    @RequestMapping(value = ServiceApi.Standards.DocumentDataSet, method = RequestMethod.GET)
    List<MCdaDataSet> getCDADataSetByCDAId(
            @RequestParam(value = "version") String version,
            @RequestParam(value = "document_Id") String cdaDocumentId);
    @RequestMapping(value = ServiceApi.Standards.DocumentDataSetList, method = RequestMethod.GET)
    Map<String, List<MCdaDataSet>> getCDADataSetByCDAIdList(
            @RequestParam(value = "version") String version,
            @RequestParam(value = "document_Id") String[] cdaDocumentId);
}

+ 106 - 0
src/main/java/com/yihu/ehr/profile/feign/DictClient.java

@ -0,0 +1,106 @@
package com.yihu.ehr.profile.feign;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.specialdict.MDrugDict;
import com.yihu.ehr.model.specialdict.MHealthProblemDict;
import com.yihu.ehr.model.specialdict.MIcd10Dict;
import com.yihu.ehr.model.specialdict.MIndicatorsDict;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author hzp
 * @version 1.0
 * @created 2016.06.27 14:58
 * 字典服务
 */
@ApiIgnore
@RequestMapping(ApiVersion.Version1_0)
@FeignClient(value = MicroServices.Dictionary)
public interface DictClient {
    /**************************** 系统字典 ********************************************/
    /**
     * 获取档案数据来源的字典
     * @return
     */
    @RequestMapping(value = "/dictionaries/record_data_sources", method = RequestMethod.GET)
    List<MConventionalDict> getRecordDataSourceList();
    /**************************** 健康问题 **********************************************/
    //根据健康问题代码获取指标信息
    @RequestMapping(value = "/dict/hp/{code}/indicators" , method = RequestMethod.GET)
    List<MIndicatorsDict> getIndicatorsByHpCode(@RequestParam(value = "code") String code);
    //根据健康问题代码获取药品信息
    @RequestMapping(value = "/dict/hp/{code}/drug" , method = RequestMethod.GET)
    List<MDrugDict> getDrugDictListByHpCode(@RequestParam(value = "code") String code);
    //根据健康问题代码获取ICD10代码列表
    @RequestMapping(value = "/dict/hp/{code}/icd10" , method = RequestMethod.GET)
    List<MIcd10Dict> getIcd10ByHpCode(@RequestParam(value = "code") String code);
    /**
     * Redis通过疾病ID获取健康问题
     *//*
    @RequestMapping(value = "/hp_icd10_relation_cache/one" , method = RequestMethod.GET)
    public MHealthProblemDict getHealthProblemByIcd10(@RequestParam(value = "icd10_id") String icd10Id);
    *//**
     * Redis通过疾病ID获取健康问题
     *//*
    @RequestMapping(value = "/hp_icd10_relation_cache/list" , method = RequestMethod.POST)
    public List<MHealthProblemDict> getHealthProblemListByIcd10List(@RequestParam(value = "icd10_idList",required = true) List<String> icd10_idList);
    *//**************************** ICD10疾病 *******************************************//*
    *//*
     * 通过Code获取单个疾病字典
     *//*
    @RequestMapping(value = "/dict/icd10/code/{code}", method = RequestMethod.GET)
    public MIcd10Dict getIcd10ByCode(@RequestParam(value = "code") String code);
    *//*
    * 通过CodeList获取疾病字典
    *//*
    @RequestMapping(value = "/dict/icd10/codeList", method = RequestMethod.POST)
    public List<MIcd10Dict> getIcd10ByCodeList(@RequestParam(value = "codeList") List<String> codeList);
    *//**
     * 根据id列表获取ICD10字典信息
     *//*
    @RequestMapping(value = "/dict/icd10/ids" , method = RequestMethod.GET)
    public List<MIcd10Dict> getIcd10DictListByIds(@RequestParam(value = "ids") List<String> ids);*/
    /************************** 药品 **************************************/
    /**
     * 根据ID列表获取相应的药品字典信息
     */
    @RequestMapping(value = "/dict/drugs/ids", method = RequestMethod.GET)
    List<MDrugDict> getDrugDictByIds(@RequestParam(value = "ids") List<String> ids);
    /****************** 指标 *******************************/
    //根据ids获取相应的指标字典信息
    @RequestMapping(value = "/dict/indicators/ids", method = RequestMethod.GET)
    List<MIndicatorsDict> getIndicatorsDictByIds(@RequestParam(value = "ids") List<String> ids);
    //根据Code获取相应的指标字典信息
    @RequestMapping(value = "/dict/indicators/code", method = RequestMethod.GET)
    MIndicatorsDict getIndicatorsDictByCode(@RequestParam(value = "code") String code);
    //根据CodeList获取相应的指标字典信息
    @RequestMapping(value = "/dict/indicators/codeList", method = RequestMethod.POST)
    List<MIndicatorsDict> getIndicatorsDictByCodeList(@RequestParam(value = "codeList",required = true) List<String> codeList);
}

+ 33 - 0
src/main/java/com/yihu/ehr/profile/feign/GeographyClient.java

@ -0,0 +1,33 @@
package com.yihu.ehr.profile.feign;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.geography.MGeographyDict;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
@ApiIgnore
@FeignClient(name = MicroServices.Geography)
public interface GeographyClient {
    @RequestMapping(value = ApiVersion.Version1_0+"/geography_entries/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询行政区划地址")
    MGeographyDict getAddressDictById(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
    @RequestMapping(value = ApiVersion.Version1_0+"/geography_entries_list", method = RequestMethod.POST)
    List<MGeographyDict> getAddressDictByIdList(
            @ApiParam(name = "idList", value = "idList", defaultValue = "")
            @RequestParam(value = "idList") List<String> idList);
}

+ 42 - 0
src/main/java/com/yihu/ehr/profile/feign/OrganizationClient.java

@ -0,0 +1,42 @@
package com.yihu.ehr.profile.feign;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.org.MOrganization;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.28 11:40
 */
@ApiIgnore
@RequestMapping(ApiVersion.Version1_0)
@FeignClient(name = MicroServices.Organization)
public interface OrganizationClient {
    @RequestMapping(value = "/organizations/org_codes", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构代码列表批量查询机构")
    List<MOrganization> getOrgs(
            @RequestParam(value = "org_codes") List<String> orgCodes);
    @RequestMapping(value = "/organizations/{org_code}", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构代码获取机构")
    MOrganization getOrg(
            @PathVariable(value = "org_code") String orgCode);
    @ApiOperation(value = "根据地区代码获取机构列表")
    @RequestMapping(value = "/organizations/areas/{area}", method = RequestMethod.GET)
    List<MOrganization> getOrganizationByAreaCode(
            @ApiParam(name = "area", value = "地区代码", defaultValue = "")
            @PathVariable(value = "area") String area);
}

+ 93 - 0
src/main/java/com/yihu/ehr/profile/feign/ResourceClient.java

@ -0,0 +1,93 @@
package com.yihu.ehr.profile.feign;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.util.rest.Envelop;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Map;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
/**
 * @author hzp
 * @version 1.0
 */
@ApiIgnore
@RequestMapping(ApiVersion.Version1_0)
@FeignClient(value = MicroServices.Resource)
public interface ResourceClient {
    @RequestMapping(value = ServiceApi.Resources.ResourceQuery, method = RequestMethod.POST)
    Envelop getResources(
            @RequestParam(value = "resourcesCode") String resourcesCode,
            @RequestParam(value = "orgCode") String orgCode,
            @RequestParam(value = "areaCode") String areaCode,
            @RequestParam(value = "queryParams", required = false) String queryParams,
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "size", required = false) Integer size);
    @RequestMapping(value = ServiceApi.Resources.ResourceQueryTransform, method = RequestMethod.POST)
    Envelop ResourcesQueryTransform(
            @RequestParam(value = "resourcesCode") String resourcesCode,
            @RequestParam(value = "roleId") String roleId,
            @RequestParam(value = "orgCode") String orgCode,
            @RequestParam(value = "areaCode", required = false) String areaCode,
            @RequestParam(value = "queryParams", required = false) String queryParams,
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "size", required = false) Integer size,
            @RequestParam(value = "version", required = true) String version);
    //查询主表数据
    @RequestMapping(value = ServiceApi.Resources.ResourceMasterData, method = GET)
    Envelop getMasterData(@RequestParam(value = "queryParams", required = true) String queryParams,
                          @RequestParam(value = "page", required = false) Integer page,
                          @RequestParam(value = "size", required = false) Integer size,
                          @RequestParam(value = "version", required = true) String version);
    //查询细表数据
    @RequestMapping(value = ServiceApi.Resources.ResourceSubData, method = GET)
    Envelop getSubData(@RequestParam(value = "queryParams", required = true) String queryParams,
                       @RequestParam(value = "page", required = false) Integer page,
                       @RequestParam(value = "size", required = false) Integer size,
                       @RequestParam(value = "version", required = true) String version);
    //查询主表统计数据
    @RequestMapping(value = ServiceApi.Resources.ResourceMasterStat, method = GET)
    Envelop getMasterStat(@RequestParam(value = "queryParams", required = true) String queryParams,
                         @RequestParam(value = "page", required = false) Integer page,
                       @RequestParam(value = "size", required = false) Integer size);
    //查询细表统计数据
    @RequestMapping(value = ServiceApi.Resources.ResourceSubStat, method = GET)
    Envelop getSubStat(@RequestParam(value = "queryParams", required = true) String queryParams,
                       @RequestParam(value = "page", required = false) Integer page,
                       @RequestParam(value = "size", required = false) Integer size);
    //获取非结构化数据
    @RequestMapping(value = ServiceApi.Resources.ResourceHealthFile, method = RequestMethod.GET)
    Envelop healthFile(
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "page") Integer page,
            @RequestParam(value = "size") Integer size);
    @RequestMapping(value = ServiceApi.Resources.ResourceRawFiles, method = GET)
    Envelop getRawFiles(@RequestParam(value = "profileId", required = false) String profileId,
                        @RequestParam(value = "cdaDocumentId", required = false) String cdaDocumentId,
                        @RequestParam(value = "page", required = false) Integer page,
                        @RequestParam(value = "size", required = false) Integer size);
    @RequestMapping(value = ServiceApi.Resources.ResourceRawFilesList, method = GET)
    Map<String,Envelop> getRawFilesList(@RequestParam(value = "profileId", required = true) String profileId,
                        @RequestParam(value = "cdaDocumentId", required = true) String[] cdaDocumentIdList);
}

+ 28 - 0
src/main/java/com/yihu/ehr/profile/feign/ThridPrescriptionClient.java

@ -0,0 +1,28 @@
package com.yihu.ehr.profile.feign;
import com.yihu.ehr.constants.ApiVersion;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Created by Administrator on 2016/6/14.
 */
@ApiIgnore
@FeignClient(value ="svr-prescription")
public interface ThridPrescriptionClient {
    @RequestMapping(value = ApiVersion.Version1_0+"/prescriptioToImage/htmlToImage", method = RequestMethod.GET)
    String prescriptioToImage(
            @ApiParam(value = "eventNo" ) @RequestParam String eventNo,
            @ApiParam(value = "处方ID" ) @RequestParam String prescriptoId,
            @ApiParam(value = "orgId") @RequestParam(required=false) String orgId,
            @ApiParam(value = "cdaType") @RequestParam(required=false) String cdaType,
            @ApiParam(value = "version") @RequestParam(required=false) String version,
            @ApiParam(value = "height(默认600)") @RequestParam(required=false,defaultValue = "600") int height,
            @ApiParam(value = "width(默认400)") @RequestParam(required=false,defaultValue = "400") int width);
}

+ 36 - 0
src/main/java/com/yihu/ehr/profile/feign/TransformClient.java

@ -0,0 +1,36 @@
package com.yihu.ehr.profile.feign;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;
/**
 * @author hzp
 * @version 1.0
 * @created 2016.06.12 14:58
 */
@ApiIgnore
@RequestMapping(ApiVersion.Version1_0)
@FeignClient(value = MicroServices.Resource)
public interface TransformClient {
    @RequestMapping(value = "/rs/transform/stdTransformList", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    List<Map<String, Object>> stdTransformList(
            @RequestBody String stdTransformDtoJson);
    @RequestMapping(value = "/rs/transform/stdTransform", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    Map<String, Object> stdTransform(
            @RequestBody String stdTransformDtoJson);
    @RequestMapping(value = "/rs/transform/stdMasterTransform", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    Map<String, Object> stdMasterTransform(
            @RequestBody String stdTransformDtoJson);
}

+ 154 - 0
src/main/java/com/yihu/ehr/profile/model/ArchiveTemplate.java

@ -0,0 +1,154 @@
package com.yihu.ehr.profile.model;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.entity.BaseIdentityEntity;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.lang.SpringContext;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.*;
import java.io.InputStream;
/**
 * @author Sand
 * @version 1.0
 * @created 2016.04.08 11:42
 */
@Entity
@Table(name = "archive_template")
@Access(value = AccessType.PROPERTY)
public class ArchiveTemplate extends BaseIdentityEntity {
    public final static String UrlSeparator = ";";
    public enum Type {
        clinic, //门诊
        resident, //住院
        medicalExam, //体检
        universal //通用
    }
    private String title;
    private String cdaVersion;
    private String cdaDocumentId;
    private String cdaDocumentName;
    private String cdaCode;
    private String pcUrl;
    private String mobileUrl;
    private Type type;
    @Column(name = "title", nullable = false)
    public String getTitle() {
        return title;
    }
    public void setTitle(String name) {
        this.title = name;
    }
    @Column(name = "cda_version", nullable = false)
    public String getCdaVersion() {
        return cdaVersion;
    }
    public void setCdaVersion(String version) {
        this.cdaVersion = version;
    }
    @Column(name = "cda_document_id")
    public String getCdaDocumentId() {
        return cdaDocumentId;
    }
    public void setCdaDocumentId(String cdaDocumentId) {
        this.cdaDocumentId = cdaDocumentId;
    }
    @Column(name = "cda_document_name")
    public String getCdaDocumentName() {
        return cdaDocumentName;
    }
    public void setCdaDocumentName(String cdaDocumentName) {
        this.cdaDocumentName = cdaDocumentName;
    }
    @Column(name = "cda_code")
    public String getCdaCode() {
        return cdaCode;
    }
    public void setCdaCode(String cdaCode) {
        this.cdaCode = cdaCode;
    }
    @Column(name = "pc_url")
    public String getPcUrl() {
        return pcUrl;
    }
    public void setPcUrl(String pcUrl) {
        this.pcUrl = pcUrl;
    }
    @Column(name = "mobile_url")
    public String getMobileUrl() {
        return mobileUrl;
    }
    public void setMobileUrl(String mobileUrl) {
        this.mobileUrl = mobileUrl;
    }
    @Column(name = "type")
    public Type getType() {
        return type;
    }
    public void setType(Type type) {
        this.type = type;
    }
    /**
     * 读取模板内容。
     *
     * @return
     */
    public byte[] getContent(boolean pc) throws Exception {
        String url = pc ? pcUrl : mobileUrl;
        if (StringUtils.isEmpty(url)) {
            return null;
        }
        String[] tokens = url.split(UrlSeparator);
        byte[] bytes = fastDFSUtil().download(tokens[0], tokens[1]);
        return bytes;
    }
    /**
     * 设置模板内容。
     *
     * @param fileStream
     * @throws Exception
     */
    public void setContent (boolean pc, InputStream fileStream) throws Exception {
        if (pc){
            if (StringUtils.isNotEmpty(pcUrl)) {
                fastDFSUtil().delete(pcUrl.split(UrlSeparator)[0], pcUrl.split(UrlSeparator)[1]);
            }
            ObjectNode objectNode = fastDFSUtil().upload(fileStream, "html", "健康档案展示模板");
            String group = objectNode.get(FastDFSUtil.GROUP_NAME).asText();
            String remoteFile = objectNode.get(FastDFSUtil.REMOTE_FILE_NAME).asText();
            String url = group + UrlSeparator + remoteFile;
            pcUrl = url;
        } else {
            if (StringUtils.isNotEmpty(mobileUrl)) {
                fastDFSUtil().delete(mobileUrl.split(UrlSeparator)[0], mobileUrl.split(UrlSeparator)[1]);
            }
            ObjectNode objectNode = fastDFSUtil().upload(fileStream, "html", "健康档案展示模板");
            String group = objectNode.get(FastDFSUtil.GROUP_NAME).asText();
            String remoteFile = objectNode.get(FastDFSUtil.REMOTE_FILE_NAME).asText();
            String url = group + UrlSeparator + remoteFile;
            mobileUrl = url;
        }
    }
    private FastDFSUtil fastDFSUtil(){
        return SpringContext.getService(FastDFSUtil.class);
    }
}

+ 34 - 0
src/main/java/com/yihu/ehr/profile/model/DrugInfo.java

@ -0,0 +1,34 @@
package com.yihu.ehr.profile.model;
/**
 * Created by progr1mmer on 2018/8/14.
 */
public class DrugInfo {
    private String name;
    private String label;
    private int count;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getLabel() {
        return label;
    }
    public void setLabel(String label) {
        this.label = label;
    }
    public int getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
}

+ 82 - 0
src/main/java/com/yihu/ehr/profile/model/InspectionInfo.java

@ -0,0 +1,82 @@
package com.yihu.ehr.profile.model;
/**
 * Created by progr1mmer on 2018/8/14.
 */
public class InspectionInfo {
    private String name;
    private Integer count;
    private String firstTime;
    private String lastTime;
    private String lastOrg;
    private String lastRecord;
    //1.检查结果信息
    //2.因为检验的检测结果在子项目中,故此处没有值
    private Integer exCount = 0;
    private String result = "";
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getCount() {
        return count;
    }
    public void setCount(Integer count) {
        this.count = count;
    }
    public String getFirstTime() {
        return firstTime;
    }
    public void setFirstTime(String firstTime) {
        this.firstTime = firstTime;
    }
    public String getLastTime() {
        return lastTime;
    }
    public void setLastTime(String lastTime) {
        this.lastTime = lastTime;
    }
    public String getLastOrg() {
        return lastOrg;
    }
    public void setLastOrg(String lastOrg) {
        this.lastOrg = lastOrg;
    }
    public String getLastRecord() {
        return lastRecord;
    }
    public void setLastRecord(String lastRecord) {
        this.lastRecord = lastRecord;
    }
    public Integer getExCount() {
        return exCount;
    }
    public void setExCount(Integer exCount) {
        this.exCount = exCount;
    }
    public String getResult() {
        return result;
    }
    public void setResult(String result) {
        this.result = result;
    }
}

+ 178 - 0
src/main/java/com/yihu/ehr/profile/model/MCDADocument.java

@ -0,0 +1,178 @@
package com.yihu.ehr.profile.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
/**
 * Created by progr1mmer on 2018/3/26.
 */
public class MCDADocument {
    private String id;
    private String code;
    private String name;
    private Date createDate;
    private String createUser;
    private String description;
    private Date updateDate;
    private String updateUser;
    private String versionCode;
    private String type;
    private String printOut;
    private String schema;
    private String sourceId;
    private int hashCode;
    private String fileGroup;
    private String staged;
    private Long standardId;
    private String stdVersion;
    public MCDADocument() {
    }
    public String getCode() {
        return this.code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getCreateDate() {
        return this.createDate;
    }
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
    public String getCreateUser() {
        return this.createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    public String getDescription() {
        return this.description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public String getId() {
        return this.id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return this.name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getUpdateDate() {
        return this.updateDate;
    }
    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }
    public String getUpdateUser() {
        return this.updateUser;
    }
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }
    public String getVersionCode() {
        return this.versionCode;
    }
    public void setVersionCode(String versionCode) {
        this.versionCode = versionCode;
    }
    public String getPrintOut() {
        return this.printOut;
    }
    public void setPrintOut(String printOut) {
        this.printOut = printOut;
    }
    public String getSchema() {
        return this.schema;
    }
    public void setSchema(String schema) {
        this.schema = schema;
    }
    public String getSourceId() {
        return this.sourceId;
    }
    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }
    public int getHashCode() {
        return this.hashCode;
    }
    public void setHashCode(int hashCode) {
        this.hashCode = hashCode;
    }
    public String getFileGroup() {
        return this.fileGroup;
    }
    public void setFileGroup(String fileGroup) {
        this.fileGroup = fileGroup;
    }
    public String getType() {
        return this.type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getStaged() {
        return this.staged;
    }
    public void setStaged(String staged) {
        this.staged = staged;
    }
    public Long getStandardId() {
        return this.standardId;
    }
    public void setStandardId(Long standardId) {
        this.standardId = standardId;
    }
    public String getStdVersion() {
        return this.stdVersion;
    }
    public void setStdVersion(String stdVersion) {
        this.stdVersion = stdVersion;
    }
}

+ 103 - 0
src/main/java/com/yihu/ehr/profile/model/MedicationStat.java

@ -0,0 +1,103 @@
package com.yihu.ehr.profile.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.Date;
/**
 * @author Sand
 * @version 1.0
 * @created 2016.04.08 11:42
 */
@Entity
@Table(name = "rs_medication_list")
@Access(value = AccessType.PROPERTY)
public class MedicationStat {
    private int drugId;
    private String drugName;
    private int month3;
    private int month6;
    private String code;
    private String unit;
    private String specifications;
    private Date lastTime = new Date();
    @Id
    @GeneratedValue(generator = "Generator")
    @GenericGenerator(name = "Generator", strategy = "increment")
    @Column(name = "drug_id")
    public int getDrugId() {
        return drugId;
    }
    public void setDrugId(int drugId) {
        this.drugId = drugId;
    }
    @Column(name = "drug_name")
    public String getDrugName() {
        return drugName;
    }
    public void setDrugName(String drugName) {
        this.drugName = drugName;
    }
    @Column(name = "month3")
    public int getMonth3() {
        return month3;
    }
    public void setMonth3(int month3) {
        this.month3 = month3;
    }
    @Column(name = "month6")
    public int getMonth6() {
        return month6;
    }
    public void setMonth6(int month6) {
        this.month6 = month6;
    }
    @Column(name = "code")
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Column(name = "unit")
    public String getUnit() {
        return unit;
    }
    public void setUnit(String unit) {
        this.unit = unit;
    }
    @Column(name = "specifications")
    public String getSpecifications() {
        return specifications;
    }
    public void setSpecifications(String specifications) {
        this.specifications = specifications;
    }
    @Column(name = "last_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getLastTime() {
        return lastTime;
    }
    public void setLastTime(Date lastTime) {
        this.lastTime = lastTime;
    }
}

+ 107 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileBasicService.java

@ -0,0 +1,107 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.profile.feign.CDADocumentClient;
import com.yihu.ehr.profile.feign.ResourceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * Created by progr1mmer on 2018/5/31.
 */
public abstract class ProfileBasicService {
    @Value("${spring.application.id}")
    protected String appId;
    @Autowired
    protected ResourceClient resource;
    @Autowired
    protected RedisService redisService;
    @Autowired
    protected CDADocumentClient cdaService;
    protected Map<String, Object> simpleEvent (Map<String, Object> detailsEvent, String searchParam) {
        Map<String, Object> simpleEvent = new HashMap<>();
        simpleEvent.put("profileId", detailsEvent.get(ResourceCells.ROWKEY));
        simpleEvent.put("orgCode", detailsEvent.get(ResourceCells.ORG_CODE));
        simpleEvent.put("orgName", detailsEvent.get(ResourceCells.ORG_NAME));
        simpleEvent.put("demographicId", detailsEvent.get(ResourceCells.DEMOGRAPHIC_ID));
        simpleEvent.put("cdaVersion", detailsEvent.get(ResourceCells.CDA_VERSION));
        simpleEvent.put("eventDate", detailsEvent.get(ResourceCells.EVENT_DATE));
        simpleEvent.put("profileType", detailsEvent.get(ResourceCells.PROFILE_TYPE));
        simpleEvent.put("eventType", detailsEvent.get(ResourceCells.EVENT_TYPE));
        simpleEvent.put("eventNo", detailsEvent.get(ResourceCells.EVENT_NO));
        //诊断名称
        String healthProblemName = "";
        if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.DIAGNOSIS_NAME))) {
            healthProblemName = ((String) detailsEvent.get(ResourceCells.DIAGNOSIS_NAME)).replaceAll(";", "、");
        } else if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.DIAGNOSIS))) {
            String [] diagnosisCode = ((String) detailsEvent.get(ResourceCells.DIAGNOSIS)).split(";");
            for (String code : diagnosisCode) {
                String name = redisService.getIcd10Name(code);
                if (!StringUtils.isEmpty(name)) {
                    healthProblemName += name + "、";
                }
            }
        } else if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.HEALTH_PROBLEM_NAME))) {
            healthProblemName = ((String) detailsEvent.get(ResourceCells.HEALTH_PROBLEM_NAME)).replaceAll(";", "、");
        } else if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.HEALTH_PROBLEM))) {
            String [] _hpCode = ((String) detailsEvent.get(ResourceCells.HEALTH_PROBLEM)).split(";");
            for (String code : _hpCode) {
                String name = redisService.getHealthProblem(code);
                if (!StringUtils.isEmpty(name)) {
                    healthProblemName += name + "、";
                }
            }
        }
        simpleEvent.put("healthProblemName", healthProblemName);
        if (!StringUtils.isEmpty(searchParam)) {
            Set<String> searchSet = new HashSet<>();
            //诊断检索数据
            if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.DIAGNOSIS_NAME))) {
                String [] data = detailsEvent.get(ResourceCells.DIAGNOSIS_NAME).toString().split(";");
                for (String datum : data) {
                    searchSet.add(datum);
                }
            }
            if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.DIAGNOSIS))) {
                String [] data = detailsEvent.get(ResourceCells.DIAGNOSIS).toString().split(";");
                for (String datum : data) {
                    String name = redisService.getIcd10Name(datum);
                    if (!StringUtils.isEmpty(name)) {
                        searchSet.add(name);
                    }
                }
            }
            if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.HEALTH_PROBLEM_NAME))) {
                String [] data = detailsEvent.get(ResourceCells.HEALTH_PROBLEM_NAME).toString().split(";");
                for (String datum : data) {
                    searchSet.add(datum);
                }
            }
            if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.HEALTH_PROBLEM))) {
                String [] data = detailsEvent.get(ResourceCells.HEALTH_PROBLEM).toString().split(";");
                for (String datum : data) {
                    String name = redisService.getHealthProblem(datum);
                    if (!StringUtils.isEmpty(name)) {
                        searchSet.add(name);
                    }
                }
            }
            String orgName = "";
            if (!StringUtils.isEmpty(detailsEvent.get(ResourceCells.ORG_NAME))) {
                orgName = (String) detailsEvent.get(ResourceCells.ORG_NAME);
            }
            String disease = org.apache.commons.lang3.StringUtils.join(searchSet.toArray(),";");
            if (disease.contains(searchParam) || orgName.contains(searchParam)) {
                return simpleEvent;
            } else {
                return null;
            }
        }
        return simpleEvent;
    }
}

+ 553 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileCDAService.java

@ -0,0 +1,553 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.profile.model.ArchiveTemplate;
import com.yihu.ehr.profile.service.template.ArchiveTemplateService;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.hos.model.standard.MCdaDataSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * CDA相关接口服务
 * @author hzp 2016-06-16
 */
@Service
public class ProfileCDAService extends ProfileBasicService {
    @Autowired
    private ArchiveTemplateService archiveTemplateService;
    @Autowired
    private ResourcesTransformService resourcesTransformService;
    /**
     * 根据ProfileId查询CDA分类
     *
     * 因为数据格式的问题,请注意次接口的注意事项
     * 1.没有子项目的模板用 multi = false,详细数据存放在在data字段,如门诊摘要、住院摘要之类的
     * 2.有子项目的模板用 multi = true,详细数据用列表的形式存放在records字段,如检查报告、检验报告,并用mark字段提供关联的主键信息
     * @param profileId
     * @param templateName
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> getCDAClass (String profileId, String templateName) throws Exception {
        String _profileId = profileId;
        if (profileId.split("_")[0].length() == 1) {
            profileId = profileId.substring(profileId.indexOf("_") + 1);
        }
        //根据profileId或者eventNo获取主记录
        Envelop envelop = resource.getMasterData("{\"q\":\"rowkey:" + profileId + "\"}", 1, 1, null);
        List<Map<String, Object>> dataList = envelop.getDetailModelList();
        List<Map<String, Object>> result = new ArrayList<>();
        if (dataList.size() > 0) {
            Map<String, Object> event = dataList.get(0);
            if (event.get(ResourceCells.PROFILE_TYPE).equals("0") || event.get(ResourceCells.PROFILE_TYPE).equals("1")) { //profileType = 0 为之前数据存储错误的问题,已更改过来
                //根据机构获取定制模板
                List<ArchiveTemplate> list;
                if (StringUtils.isEmpty(templateName)) {
                    //pc接口
                    list = archiveTemplateService.search("type=universal," + ArchiveTemplate.Type.values()[new Integer(event.get(ResourceCells.EVENT_TYPE).toString())]
                            + ";cdaVersion=" + event.get(ResourceCells.CDA_VERSION));
                } else {
                    //mobile接口
                    list = archiveTemplateService.search("type=universal," + ArchiveTemplate.Type.values()[new Integer(event.get(ResourceCells.EVENT_TYPE).toString())]
                            + ";cdaVersion=" + event.get(ResourceCells.CDA_VERSION)
                            + ";title?" + templateName);
                }
                //遍历模板
                List<Map<String, Object>> prescription = new ArrayList<>();
                for (ArchiveTemplate item : list) {
                    Map<String, Object> temp = new HashMap<>();
                    if (item.getTitle().contains("检查报告")) {
                        String subQ = "{\"q\":\"rowkey:" + profileId + "$HDSD00_79$*\"}";
                        Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                        List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                        List<Map<String, Object>> data = new ArrayList<>();
                        subList.forEach(item2 -> {
                            Map<String, Object> dataMap = new HashMap<>();
                            String item2Name = (String) item2.get("EHR_002883"); //检查名称
                            dataMap.put(ResourceCells.PROFILE_ID, item2.get(ResourceCells.ROWKEY));
                            dataMap.put(ResourceCells.PROFILE_TYPE, event.get(ResourceCells.PROFILE_TYPE));
                            dataMap.put("cda_document_id", item.getCdaDocumentId());
                            dataMap.put("cda_code", item.getCdaCode());
                            dataMap.put("pc_template", item.getPcUrl());
                            dataMap.put("mobile_template", item.getMobileUrl());
                            dataMap.put("template_id", item.getId());
                            dataMap.put("name", item2Name);
                            dataMap.put("mark", item2.get("EHR_000316")); //检查报告单号
                            data.add(dataMap);
                        });
                        temp.put("template_name", item.getTitle());
                        temp.put("multi", true);
                        temp.put("data", new HashMap<>());
                        temp.put("records", data);
                    } else if (item.getTitle().contains("检验报告")) {
                        String subQ = "{\"q\":\"rowkey:" + profileId + "$HDSD00_77$*\"}";
                        Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                        List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                        List<Map<String, Object>> data = new ArrayList<>();
                        subList.forEach(item2 -> {
                            Map<String, Object> dataMap = new HashMap<>();
                            String item2Name = (String) item2.get("EHR_000352"); //检验项目
                            dataMap.put(ResourceCells.PROFILE_ID, item2.get(ResourceCells.ROWKEY));
                            dataMap.put(ResourceCells.PROFILE_TYPE, event.get(ResourceCells.PROFILE_TYPE));
                            dataMap.put("cda_document_id", item.getCdaDocumentId());
                            dataMap.put("cda_code", item.getCdaCode());
                            dataMap.put("pc_template", item.getPcUrl());
                            dataMap.put("mobile_template", item.getMobileUrl());
                            dataMap.put("template_id", item.getId());
                            dataMap.put("name", item2Name);
                            dataMap.put("mark", item2.get("EHR_000363")); //检验报告单号
                            data.add(dataMap);
                        });
                        temp.put("template_name", item.getTitle());
                        temp.put("multi", true);
                        temp.put("data", new HashMap<>());
                        temp.put("records", data);
                    } else if (item.getTitle().contains("手术记录")) {
                        String subQ = "{\"q\":\"rowkey:" + profileId + "$HDSD00_06$*\"}";
                        Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                        List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                        List<Map<String, Object>> data = new ArrayList<>();
                        subList.forEach(item2 -> {
                            Map<String, Object> dataMap = new HashMap<>();
                            String item2Name = (String) item2.get("EHR_000418"); //手术名称
                            dataMap.put(ResourceCells.PROFILE_ID, item2.get(ResourceCells.ROWKEY));
                            dataMap.put(ResourceCells.PROFILE_TYPE, event.get(ResourceCells.PROFILE_TYPE));
                            dataMap.put("cda_document_id", item.getCdaDocumentId());
                            dataMap.put("cda_code", item.getCdaCode());
                            dataMap.put("pc_template", item.getPcUrl());
                            dataMap.put("mobile_template", item.getMobileUrl());
                            dataMap.put("template_id", item.getId());
                            dataMap.put("name", item2Name);
                            dataMap.put("mark", item2.get("EHR_000423")); //手术申请单号
                            data.add(dataMap);
                        });
                        temp.put("template_name", item.getTitle());
                        temp.put("multi", true);
                        temp.put("data", new HashMap<>());
                        temp.put("records", data);
                    } else if (item.getTitle().contains("处方")) {
                        //中西药特殊处理
                        if (item.getTitle().contains("中药")) {
                            String subQ = "{\"q\":\"rowkey:" + profileId + "$HDSD00_83$*\"}";
                            Envelop subEnvelop = resource.getSubData(subQ, 1, 1, null);
                            if (subEnvelop.getDetailModelList() != null && subEnvelop.getDetailModelList().size() > 0) {
                                Map<String, Object> dataMap = new HashMap<>();
                                dataMap.put(ResourceCells.PROFILE_ID, profileId);
                                dataMap.put(ResourceCells.PROFILE_TYPE, event.get(ResourceCells.PROFILE_TYPE));
                                dataMap.put("cda_document_id", item.getCdaDocumentId());
                                dataMap.put("cda_code", item.getCdaCode());
                                dataMap.put("pc_template", item.getPcUrl());
                                dataMap.put("mobile_template", item.getMobileUrl());
                                dataMap.put("template_id", item.getId());
                                dataMap.put("name", "中药处方");
                                dataMap.put("mark", "01");
                                prescription.add(dataMap);
                            }
                        } else if (item.getTitle().contains("西药")) {
                            String subQ = "{\"q\":\"rowkey:" + profileId + "$HDSD00_84$*\"}";
                            Envelop subEnvelop = resource.getSubData(subQ, 1, 1, null);
                            if (subEnvelop.getDetailModelList() != null && subEnvelop.getDetailModelList().size() > 0) {
                                Map<String, Object> dataMap = new HashMap<>();
                                dataMap.put(ResourceCells.PROFILE_ID, profileId);
                                dataMap.put(ResourceCells.PROFILE_TYPE, event.get(ResourceCells.PROFILE_TYPE));
                                dataMap.put("cda_document_id", item.getCdaDocumentId());
                                dataMap.put("cda_code", item.getCdaCode());
                                dataMap.put("pc_template", item.getPcUrl());
                                dataMap.put("mobile_template", item.getMobileUrl());
                                dataMap.put("template_id", item.getId());
                                dataMap.put("name", "西药处方");
                                dataMap.put("mark", "02");
                                prescription.add(dataMap);
                            }
                        }
                        continue;
                    } else {
                        Map<String, Object> dataMap = new HashMap<>();
                        dataMap.put(ResourceCells.PROFILE_ID, profileId);
                        dataMap.put(ResourceCells.PROFILE_TYPE, event.get(ResourceCells.PROFILE_TYPE));
                        dataMap.put("cda_document_id", item.getCdaDocumentId());
                        dataMap.put("cda_code", item.getCdaCode());
                        dataMap.put("pc_template", item.getPcUrl());
                        dataMap.put("mobile_template", item.getMobileUrl());
                        dataMap.put("template_id", item.getId());
                        dataMap.put("name", item.getTitle());
                        dataMap.put("mark", "single");
                        temp.put("template_name", item.getTitle());
                        temp.put("multi", false);
                        temp.put("data", dataMap);
                        temp.put("records", new ArrayList<>());
                    }
                    result.add(temp);
                }
                if (prescription.size() > 0) {
                    Map<String, Object> temp = new HashMap<>();
                    temp.put("template_name", "门诊处方");
                    temp.put("multi", true);
                    temp.put("data", new HashMap<>());
                    temp.put("records", prescription);
                    result.add(temp);
                }
            }
        }
        if (_profileId.split("_")[0].length() == 1) {
            envelop = resource.healthFile("_id=" + _profileId, null, 1, 1);
            dataList = envelop.getDetailModelList();
            if (dataList.size() > 0) {
                Map<String, Object> obj = dataList.get(0);
                List<Map<String, String>> fileList = obj.get("file_list") != null ? (List) obj.get("file_list") : new ArrayList<>();
                Map<String, List<Map<String, Object>>> classify = new HashMap<>();
                fileList.forEach(item -> {
                    Map<String, Object> dataMap = new HashMap<>();
                    dataMap.put(ResourceCells.PROFILE_ID, obj.get(ResourceCells.ROWKEY));
                    dataMap.put(ResourceCells.PROFILE_TYPE, obj.get(ResourceCells.PROFILE_TYPE));
                    dataMap.put("cda_code", item.get("cda_document_id"));
                    dataMap.put("name", item.get("emr_name"));
                    dataMap.put("mark", "files");
                    dataMap.put("mime", item.get("mime"));
                    dataMap.put("url", item.get("url"));
                    String cdaDocumentName = item.get("cda_document_name") == null ? "CDA文档(" + item.get("cda_document_id") + ")" : item.get("cda_document_name");
                    if (classify.containsKey(cdaDocumentName)) {
                        classify.get(cdaDocumentName).add(dataMap);
                    } else {
                        List<Map<String, Object>> data = new ArrayList<>();
                        data.add(dataMap);
                        classify.put(cdaDocumentName, data);
                    }
                });
                classify.forEach((key, val) -> {
                    Map<String, Object> temp = new HashMap<>();
                    temp.put("template_name", key);
                    temp.put("multi", true);
                    temp.put("data", new HashMap<>());
                    temp.put("records", val);
                    result.add(temp);
                });
            }
        }
        return result;
    }
    /**
     * 获取某个CDA文档数据
     * @param profileId 就诊时间主索引
     * @param cdaDocumentId cda文档ID
     * @param transform 是否转换
     * @return
     * @throws Exception
     */
    public Map<String, Object> getCDAData(String profileId, boolean transform, String mark, String cdaDocumentId) throws Exception {
        return (Map<String, Object>)getCDAPartData(profileId, transform, mark, cdaDocumentId).get(cdaDocumentId);
    }
    /**
     * 获取CDA文档数据片段
     * @param profileId
     * @param transform
     * @param cdaDocumentIdList
     * @return
     * @throws Exception
     */
    private Map<String, Object> getCDAPartData(String profileId, boolean transform, String mark, String...cdaDocumentIdList) throws Exception {
        //标准包档案的主键以机构编码开头
        Map<String, Object> result = new HashMap<>();
        if (profileId.split("_")[0].length() > 1) {
            final boolean is_multi = profileId.contains("$") ? true : false;
            Envelop envelop;
            if (is_multi) {
                envelop = resource.getMasterData("{\"q\":\"rowkey:" + profileId.split("\\$")[0] + "\"}", 1, 1, null);
            } else {
                envelop = resource.getMasterData("{\"q\":\"rowkey:" + profileId + "\"}", 1, 1, null);
            }
            List<Map<String, Object>> eventList = envelop.getDetailModelList();
            if (eventList != null && eventList.size() > 0) {
                Map<String, Object> event = eventList.get(0);
                String cdaVersion = String.valueOf(event.get(ResourceCells.CDA_VERSION));
                Map<String, Object> dataMap = new HashMap<>();
                Map<String, List<MCdaDataSet>> cdaDataSetMap = cdaService.getCDADataSetByCDAIdList(cdaVersion, cdaDocumentIdList);
                if (transform) {
                    cdaDataSetMap.keySet().forEach(cdaDocId -> {
                        List<MCdaDataSet> cdaDataSets = cdaDataSetMap.get(cdaDocId);
                        Map<String, Object> tempMap = new HashMap<>();
                        List<String> multipleDataset = new ArrayList<>();
                        if (cdaDataSets != null && cdaDataSets.size() > 0) {
                            cdaDataSets.forEach(item -> {
                                String dataSetCode = item.getDataSetCode();
                                if (item.getMultiRecord().equals("0")) {
                                    //主表数据
                                    if (!tempMap.containsKey(dataSetCode)) {
                                        List<Map<String, Object>> tempList = new ArrayList<>();
                                        tempList.add(resourcesTransformService.stdTransform(event, dataSetCode, cdaVersion));
                                        tempMap.put(dataSetCode, tempList);
                                    }
                                } else {
                                    multipleDataset.add(dataSetCode);
                                }
                            });
                        }
                        //细表数据
                        if (is_multi) {
                            String[] combination = profileId.split("\\$");
                            String subQ = "{\"q\":\"profile_id:" + combination[0] + "\"}";
                            Envelop subData = resource.getSubData(subQ, 1, 2000, null);
                            List<Map<String, Object>> subList = subData.getDetailModelList();
                            subList.forEach(item -> {
                                item.put(ResourceCells.ORG_AREA, event.get(ResourceCells.ORG_AREA));
                                item.put(ResourceCells.ORG_NAME, event.get(ResourceCells.ORG_NAME));
                                item.put(ResourceCells.EVENT_DATE, event.get(ResourceCells.EVENT_DATE));
                                String dataSetCode = String.valueOf(item.get(ResourceCells.ROWKEY)).split("\\$")[1];
                                if (combination[1].equals(dataSetCode)) {
                                    if (profileId.equals(item.get(ResourceCells.ROWKEY))) {
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (combination[1].equals("HDSD00_79") && dataSetCode.equals("HDSD00_78") && !StringUtils.isEmpty(mark)) {
                                    if (mark.equals(item.get("EHR_006291"))) { //报告单号
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (combination[1].equals("HDSD00_77") && dataSetCode.equals("HDSD00_76") && !StringUtils.isEmpty(mark)) {
                                    if (mark.equals(item.get("EHR_006294"))) { //报告单号
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (combination[1].equals("HDSD00_77") && dataSetCode.equals("HDSD00_75") && !StringUtils.isEmpty(mark)) {
                                    if (mark.equals(item.get("EHR_006339"))) { //报告单号
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (tempMap.containsKey(dataSetCode)) {
                                    List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                    tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                } else {
                                    List<Map<String, Object>> tempList = new ArrayList<>();
                                    tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                    tempMap.put(dataSetCode, tempList);
                                }
                            });
                            multipleDataset.forEach(item -> {
                                if (!tempMap.containsKey(item)) {
                                    tempMap.put(item, new ArrayList<>());
                                }
                            });
                            dataMap.put(cdaDocId, tempMap);
                        } else {
                            String subQ = "{\"q\":\"profile_id:" + profileId + "\"}";
                            Envelop subData = resource.getSubData(subQ, 1, 2000, null);
                            List<Map<String, Object>> subList = subData.getDetailModelList();
                            subList.forEach(item -> {
                                item.put(ResourceCells.ORG_AREA, event.get(ResourceCells.ORG_AREA));
                                item.put(ResourceCells.ORG_NAME, event.get(ResourceCells.ORG_NAME));
                                item.put(ResourceCells.EVENT_DATE, event.get(ResourceCells.EVENT_DATE));
                                String dataSetCode = String.valueOf(item.get(ResourceCells.ROWKEY)).split("\\$")[1];
                                if (tempMap.containsKey(dataSetCode)) {
                                    List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                    tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                } else {
                                    List<Map<String, Object>> tempList = new ArrayList<>();
                                    tempList.add(resourcesTransformService.stdTransform(item, dataSetCode, cdaVersion));
                                    tempMap.put(dataSetCode, tempList);
                                }
                            });
                            multipleDataset.forEach(item -> {
                                if (!tempMap.containsKey(item)) {
                                    tempMap.put(item, new ArrayList<>());
                                }
                            });
                            dataMap.put(cdaDocId, tempMap);
                        }
                    });
                } else {
                    cdaDataSetMap.keySet().forEach(cdaDocId -> {
                        List<MCdaDataSet> cdaDataSets = cdaDataSetMap.get(cdaDocId);
                        Map<String, Object> tempMap = new HashMap<>();
                        List<String> multipleDataset = new ArrayList<>();
                        if (cdaDataSets != null) {
                            cdaDataSets.forEach(cdaDataSet -> {
                                String dataSetCode = cdaDataSet.getDataSetCode();
                                if (cdaDataSet.getMultiRecord().equals("0")) {
                                    //主表数据
                                    if (!tempMap.containsKey(dataSetCode)) {
                                        List<Map<String, Object>> tempList = new ArrayList<>();
                                        tempList.add(resourcesTransformService.stdMerge(event, dataSetCode, cdaVersion));
                                        tempMap.put(dataSetCode, tempList);
                                    }
                                } else {
                                    multipleDataset.add(dataSetCode);
                                }
                            });
                        }
                        //细表数据
                        if (is_multi) {
                            String[] combination = profileId.split("\\$");
                            String subQ = "{\"q\":\"profile_id:" + combination[0] + "\"}";
                            Envelop subData = resource.getSubData(subQ, 1, 2000, null);
                            List<Map<String, Object>> subList = subData.getDetailModelList();
                            subList.forEach(item -> {
                                item.put(ResourceCells.ORG_AREA, event.get(ResourceCells.ORG_AREA));
                                item.put(ResourceCells.ORG_NAME, event.get(ResourceCells.ORG_NAME));
                                item.put(ResourceCells.EVENT_DATE, event.get(ResourceCells.EVENT_DATE));
                                String dataSetCode = String.valueOf(item.get(ResourceCells.ROWKEY)).split("\\$")[1];
                                if (combination[1].equals(dataSetCode)) {
                                    if (profileId.equals(item.get(ResourceCells.ROWKEY))) {
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(item);
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(item);
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (combination[1].equals("HDSD00_79") && dataSetCode.equals("HDSD00_78") && !StringUtils.isEmpty(mark)) {
                                    if (mark.equals(item.get("EHR_006291"))) { //报告单号
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(item);
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(item);
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (combination[1].equals("HDSD00_77") && dataSetCode.equals("HDSD00_76") && !StringUtils.isEmpty(mark)) {
                                    if (mark.equals(item.get("EHR_006294"))) { //报告单号
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(item);
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(item);
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (combination[1].equals("HDSD00_77") && dataSetCode.equals("HDSD00_75") && !StringUtils.isEmpty(mark)) {
                                    if (mark.equals(item.get("EHR_006339"))) { //报告单号
                                        if (tempMap.containsKey(dataSetCode)) {
                                            List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                            tempList.add(item);
                                        } else {
                                            List<Map<String, Object>> tempList = new ArrayList<>();
                                            tempList.add(item);
                                            tempMap.put(dataSetCode, tempList);
                                        }
                                    }
                                    return;
                                }
                                if (tempMap.containsKey(dataSetCode)) {
                                    List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                    tempList.add(item);
                                } else {
                                    List<Map<String, Object>> tempList = new ArrayList<>();
                                    tempList.add(item);
                                    tempMap.put(dataSetCode, tempList);
                                }
                            });
                            multipleDataset.forEach(item -> {
                                if (!tempMap.containsKey(item)) {
                                    tempMap.put(item, new ArrayList<>());
                                }
                            });
                            dataMap.put(cdaDocId, tempMap);
                        } else {
                            String subQ = "{\"q\":\"profile_id:" + profileId + "\"}";
                            Envelop subData = resource.getSubData(subQ, 1, 2000, null);
                            List<Map<String, Object>> subList = subData.getDetailModelList();
                            subList.forEach(item -> {
                                item.put(ResourceCells.ORG_AREA, event.get(ResourceCells.ORG_AREA));
                                item.put(ResourceCells.ORG_NAME, event.get(ResourceCells.ORG_NAME));
                                item.put(ResourceCells.EVENT_DATE, event.get(ResourceCells.EVENT_DATE));
                                String dataSetCode = String.valueOf(item.get(ResourceCells.ROWKEY)).split("\\$")[1];
                                if (tempMap.containsKey(dataSetCode)) {
                                    List<Map<String, Object>> tempList = (List<Map<String, Object>>) tempMap.get(dataSetCode);
                                    tempList.add(item);
                                } else {
                                    List<Map<String, Object>> tempList = new ArrayList<>();
                                    tempList.add(item);
                                    tempMap.put(dataSetCode, tempList);
                                }
                            });
                            multipleDataset.forEach(item -> {
                                if (!tempMap.containsKey(item)) {
                                    tempMap.put(item, new ArrayList<>());
                                }
                            });
                            dataMap.put(cdaDocId, tempMap);
                        }
                    });
                }
                //获取cda document数据
                List<ArchiveTemplate> archiveTemplates = archiveTemplateService.findByCdaDocumentId(Arrays.asList(cdaDocumentIdList));
                archiveTemplates.forEach(item -> {
                    Map<String, Object> temp = new HashMap<>();
                    temp.put("cda_version", cdaVersion);
                    temp.put("cda_document_id", item.getCdaDocumentId());
                    temp.put("cda_document_name", item.getCdaDocumentName());
                    temp.put("data_sets", dataMap.get(item.getCdaDocumentId()));
                    temp.put("event_type", event.get("event_type"));
                    temp.put("patient_id", event.get("patient_id"));
                    temp.put("org_code", event.get("org_code"));
                    temp.put("org_name", event.get("org_name"));
                    temp.put("event_no", event.get("event_no"));
                    temp.put("event_date", event.get("event_date"));
                    result.put(item.getCdaDocumentId(), temp);
                });
                return result;
            }
        } else {
            Envelop envelop = resource.healthFile("_id=" + profileId, null, 1, 1);
            List<Map<String, Object>> dataList = envelop.getDetailModelList();
            if (dataList.size() > 0) {
                Map<String, Object> event = dataList.get(0);
                result.put(cdaDocumentIdList[0], event);
                return result;
            }
        }
        return result;
    }
}

+ 345 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileDiseaseService.java

@ -0,0 +1,345 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.util.rest.Envelop;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * Created by progr1mmer on 2018/1/7.
 */
@Service
public class ProfileDiseaseService extends ProfileBasicService {
    @Autowired
    private ProfileMedicationService profileMedicationService;
    /**
     * 根据就诊记录,获取慢病记录
     * @param demographicId
     * @return
     */
    public List<Map<String, Object>> getHealthProblem (String demographicId) throws Exception {
        List<Map<String, Object>> result = new ArrayList<>();
        //获取门诊住院记录
        Envelop envelop = resource.getMasterData("{\"q\":\"demographic_id:" + demographicId + "\"}", 1, 500, null);
        List<Map<String, Object>> eventList = envelop.getDetailModelList();
        Map<String, List<Map<String, Object>>> hpMap = new HashedMap();
        if (eventList.size() > 0) {
            //进行降序
            Collections.sort(eventList, new ProfileDiseaseService.EventDateComparatorDesc());
            eventList.forEach(item -> {
                if (item.containsKey(ResourceCells.DIAGNOSIS)) {
                    String diagnosis = (String) item.get(ResourceCells.DIAGNOSIS);
                    String [] _diagnosis = diagnosis.split(";");
                    for (String code : _diagnosis) {
                        String chronicInfo = redisService.getChronicInfo(code);
                        if (!StringUtils.isEmpty(chronicInfo)) {
                            String [] _chronicInfo = chronicInfo.split("-");
                            if (!"0".equals(_chronicInfo[1])) {
                                String healthProblem = redisService.getHpCodeByIcd10(code); //祝金仙
                                if (!StringUtils.isEmpty(healthProblem)) {
                                    for (String hpCode : healthProblem.split(";")) {
                                        List<Map<String, Object>> profileList = new ArrayList<>();
                                        if (hpMap.containsKey(hpCode)) {
                                            profileList = hpMap.get(hpCode);
                                        }
                                        profileList.add(item);
                                        hpMap.put(hpCode, profileList);
                                    }
                                }
                            }
                        }
                    }
                }
            });
            for (String hpCode : hpMap.keySet()) {
                Map<String, Object> obj = new HashedMap();
                obj.put("healthProblemCode", hpCode);
                obj.put("healthProblemName", redisService.getHealthProblem(hpCode));
                int visitTimes = 0;
                int hospitalizationTimes = 0;
                List<Map<String, Object>> profileList = hpMap.get(hpCode);
                Map<String, List<Map<String, Object>>> complication = new HashMap<>();
                for (int i = 0; i < profileList.size(); i++) {
                    Map<String, Object> profile = profileList.get(i);
                    //事件类型
                    String eventType = (String) profile.get(ResourceCells.EVENT_TYPE);
                    String recentEvent = "";
                    if ("0".equals(eventType)) {
                        recentEvent = "门诊";
                        visitTimes ++;
                    } else if ("1".equals(eventType)) {
                        recentEvent = "住院";
                        hospitalizationTimes ++;
                    } else if ("2".equals(eventType)) {
                        recentEvent = "体检";
                    }
                    //第一条
                    if (i == 0) {
                        obj.put("lastVisitDate", profile.get(ResourceCells.EVENT_DATE));
                        obj.put("lastVisitOrgCode", profile.get(ResourceCells.ORG_CODE));
                        obj.put("lastVisitOrg", profile.get(ResourceCells.ORG_NAME));
                        obj.put("lastVisitRecord", profile.get(ResourceCells.ROWKEY));
                        obj.put("recentEvent", recentEvent);
                        obj.put("eventType", eventType);
                    }
                    //最后一条
                    if (i == profileList.size() - 1) {
                        obj.put("ageOfDisease", getAgeOfDisease(profile.get(ResourceCells.EVENT_DATE)));
                        obj.put("firstVisitDate", profile.get(ResourceCells.EVENT_DATE));
                        obj.put("firstVisitOrgCode", profile.get(ResourceCells.ORG_CODE));
                        obj.put("firstVisitOrg", profile.get(ResourceCells.ORG_NAME));
                        obj.put("firstVisitRecord", profile.get(ResourceCells.ROWKEY));
                    }
                    //提取并发症
                    if (profile.containsKey(ResourceCells.DIAGNOSIS)) {
                        String diagnosis = (String) profile.get(ResourceCells.DIAGNOSIS);
                        String [] _diagnosis = diagnosis.split(";");
                        for (String diagnosisCode : _diagnosis) {
                            String _hpCode = redisService.getHpCodeByIcd10(diagnosisCode);
                            if (_hpCode != null && !_hpCode.contains(hpCode)) {
                                if (complication.containsKey(diagnosisCode)) {
                                    complication.get(diagnosisCode).add(profile);
                                } else {
                                    List<Map<String, Object>> diagnosisList = new ArrayList<>();
                                    diagnosisList.add(profile);
                                    complication.put(diagnosisCode, diagnosisList);
                                }
                            }
                        }
                    }
                }
                //近3个月常用药物
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                Date now = calendar.getTime();
                Date before = DateUtils.addDays(now, -180);
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
                String start = dateFormat.format(before);
                String end = dateFormat.format(DateUtils.addDays(now, 1));
                String date = "{\"start\":\"" + start + "\",\"end\":\"" + end + "\"}";
                Map<String, Integer> medication = profileMedicationService.medicationRanking(demographicId, null, hpCode, date);
                obj.put("medical", medication);
                //并发症确诊
                List<Map<String, Object>> complicationList = new ArrayList<>();
                complication.forEach((key, value) -> {
                    Map<String, Object> data = new HashMap<>();
                    Collections.sort(value, new ProfileDiseaseService.EventDateComparatorDesc());
                    Map<String, Object> profile = value.get(value.size() - 1);
                    data.put("name", redisService.getIcd10Name(key));
                    data.put("date", profile.get(ResourceCells.EVENT_DATE));
                    data.put("org", profile.get(ResourceCells.ORG_NAME));
                    data.put("record", profile.get(ResourceCells.ROWKEY));
                    complicationList.add(data);
                });
                obj.put("complication", complicationList);
                obj.put("visitTimes", visitTimes);
                obj.put("hospitalizationTimes", hospitalizationTimes);
                obj.put("demographicId", demographicId);
                result.add(obj);
            }
        }
        return result;
    }
    /**
     * 根据就诊记录,分析历史健康情况
     * @param demographicId
     * @return
     */
    public List<Map<String, Object>> getHealthCondition (String demographicId) {
        List<Map<String, Object>> result = new ArrayList<>();
        //获取门诊住院记录
        Envelop envelop = resource.getMasterData("{\"q\":\"demographic_id:" + demographicId + "\"}", 1, 500, null);
        List<Map<String, Object>> eventList = envelop.getDetailModelList();
        Map<String, List<Map<String, Object>>> hpMap = new HashedMap();
        if (eventList.size() > 0) {
            //进行降序
            Collections.sort(eventList, new ProfileDiseaseService.EventDateComparatorDesc());
            for (Map<String, Object> item : eventList) {
                if (item.containsKey(ResourceCells.HEALTH_PROBLEM)) {
                    String healthProblem = (String) item.get(ResourceCells.HEALTH_PROBLEM);
                    String [] _healthProblem = healthProblem.split(";");
                    for (String code : _healthProblem) {
                        List<Map<String, Object>> profileList = new ArrayList<>();
                        if (hpMap.containsKey(code)) {
                            profileList = hpMap.get(code);
                        }
                        profileList.add(item);
                        hpMap.put(code, profileList);
                    }
                }
            }
            hpMap = sortByValue(hpMap);
            for (String hpCode : hpMap.keySet()) {
                Map<String, Object> obj = new HashedMap();
                obj.put("healthProblemCode", hpCode);
                obj.put("healthProblemName", redisService.getHealthProblem(hpCode));
                int visitTimes = 0;
                int hospitalizationTimes = 0;
                int operateTimes = 0;
                Map<String, Integer> commonSymptoms = new HashMap<>();
                List<Map<String, Object>> profileList = hpMap.get(hpCode);
                for (int i = 0; i < profileList.size(); i++) {
                    Map<String, Object> profile = profileList.get(i);
                    //事件类型
                    String eventType = (String) profile.get(ResourceCells.EVENT_TYPE);
                    String recentEvent = "";
                    if ("0".equals(eventType)) {
                        recentEvent = "门诊";
                        visitTimes ++;
                    } else if ("1".equals(eventType)) {
                        recentEvent = "住院";
                        hospitalizationTimes ++;
                    } else if ("2".equals(eventType)) {
                        recentEvent = "体检";
                    }
                    String subQ = "{\"q\":\"rowkey:" + profile.get(ResourceCells.ROWKEY) + "$HDSD00_06$*" + "\"}";
                    Envelop subEnvelop = resource.getSubData(subQ, 1, 1, null);
                    if (subEnvelop.getDetailModelList().size() > 0) {
                        operateTimes ++;
                    }
                    //第一条
                    if (i == 0) {
                        obj.put("lastVisitDate", profile.get(ResourceCells.EVENT_DATE));
                        obj.put("lastVisitOrgCode", profile.get(ResourceCells.ORG_CODE));
                        obj.put("lastVisitOrg", profile.get(ResourceCells.ORG_NAME));
                        obj.put("lastVisitRecord", profile.get(ResourceCells.ROWKEY));
                        obj.put("recentEvent", recentEvent);
                        obj.put("eventType", eventType);
                    }
                    //最后一条
                    if (i == profileList.size() - 1) {
                        obj.put("firstVisitDate", profile.get(ResourceCells.EVENT_DATE));
                        obj.put("firstVisitOrgCode", profile.get(ResourceCells.ORG_CODE));
                        obj.put("firstVisitOrg", profile.get(ResourceCells.ORG_NAME));
                        obj.put("firstVisitRecord", profile.get(ResourceCells.ROWKEY));
                    }
                    //提取常见症状
                    if (profile.containsKey(ResourceCells.DIAGNOSIS)) {
                        String diagnosis = (String) profile.get(ResourceCells.DIAGNOSIS);
                        String [] _diagnosis = diagnosis.split(";");
                        for (String diagnosisCode : _diagnosis) {
                            String healthProblem = redisService.getHpCodeByIcd10(diagnosisCode);//通过ICD10获取健康问题
                            if (!StringUtils.isEmpty(healthProblem)) {
                                if (healthProblem.contains(hpCode)) {
                                    if (commonSymptoms.containsKey(diagnosisCode)) {
                                        int count = commonSymptoms.get(diagnosisCode);
                                        commonSymptoms.put(diagnosisCode, count++) ;
                                    } else {
                                        commonSymptoms.put(diagnosisCode, 1) ;
                                    }
                                }
                            }
                        }
                    }
                }
                //常见症状
                List<Map<String, Object>> commonSymptomsList = new ArrayList<>();
                commonSymptoms.forEach((key, value) -> {
                    Map<String, Object> data = new HashMap<>();
                    data.put("name", redisService.getIcd10Name(key));
                    data.put("count", value);
                    commonSymptomsList.add(data);
                });
                obj.put("commonSymptoms", commonSymptomsList);
                obj.put("visitTimes", visitTimes);
                obj.put("hospitalizationTimes", hospitalizationTimes);
                obj.put("operateTimes", operateTimes);
                obj.put("demographicId", demographicId);
                result.add(obj);
            }
        }
        return result;
    }
    /**
     * 根据时间获取病龄
     * @param eventData
     * @return
     */
    private String getAgeOfDisease(Object eventData){
        SimpleDateFormat sd = new SimpleDateFormat("yyyyMM");
        String eventDataYear=eventData.toString().substring(0, 7).substring(0,4);
        String eventDataMonth=eventData.toString().substring(0, 7).substring(5,7);
        String ageOfDisease;
        if (Integer.parseInt(sd.format(new Date()).substring(4, 6)) - Integer.parseInt(eventDataMonth)<0){
            Integer year = Integer.parseInt(sd.format(new Date()).substring(0, 4)) - Integer.parseInt(eventDataYear)-1;
            Integer month = Integer.parseInt(sd.format(new Date()).substring(4, 6))+12- Integer.parseInt(eventDataMonth);
            if (year>0) {
                ageOfDisease = year + "年" + month + "个月";
            } else {
                ageOfDisease = month + "个月";
            }
        } else {
            Integer year = Integer.parseInt(sd.format(new Date()).substring(0, 4)) - Integer.parseInt(eventDataYear);
            Integer month = Integer.parseInt(sd.format(new Date()).substring(4, 6))- Integer.parseInt(eventDataMonth);
            if (year>0) {
                ageOfDisease = year + "年" + month + "个月";
            } else {
                ageOfDisease = month + "个月";
            }
        }
        return ageOfDisease;
    }
    static class EventDateComparatorDesc implements Comparator<Map<String, Object>> {
        @Override
        public int compare(Map<String, Object> m1, Map<String, Object> m2) {
            String eventDate1 = (String)m1.get(ResourceCells.EVENT_DATE);
            String eventDate2 = (String)m2.get(ResourceCells.EVENT_DATE);
            String str1 = eventDate1.substring(0, eventDate1.length()-1).replaceAll("[a-zA-Z]"," ");
            String str2 = eventDate2.substring(0, eventDate1.length()-1).replaceAll("[a-zA-Z]"," ");
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date v1 = null;
            Date v2 = null;
            try {
                v1 = dateFormat.parse(str1);
                v2 = dateFormat.parse(str2);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (v2 != null) {
                return v2.compareTo(v1);
            }
            return 0;
        }
    }
    private Map<String, List<Map<String, Object>>> sortByValue(Map<String, List<Map<String, Object>>> sourceMap) {
        if (sourceMap == null || sourceMap.isEmpty()) {
            return sourceMap;
        }
        Map<String, List<Map<String, Object>>> sortedMap = new LinkedHashMap<>();
        List<Map.Entry<String, List<Map<String, Object>>>> entryList = new ArrayList<>(sourceMap.entrySet());
        Collections.sort(entryList, new ProfileDiseaseService.MapValueComparator());
        Iterator<Map.Entry<String, List<Map<String, Object>>>> iterator = entryList.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, List<Map<String, Object>>> tmpEntry = iterator.next();
            sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
        }
        return sortedMap;
    }
    class MapValueComparator implements Comparator<Map.Entry<String, List<Map<String, Object>>>> {
        @Override
        public int compare(Map.Entry<String,  List<Map<String, Object>>> me1, Map.Entry<String,  List<Map<String, Object>>> me2) {
            return - new Integer(me1.getValue().size()).compareTo(new Integer(me2.getValue().size()));
        }
    }
}

+ 331 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileEventService.java

@ -0,0 +1,331 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.profile.util.SimpleSolrQueryUtil;
import com.yihu.ehr.util.rest.Envelop;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @author hzp 2016-06-27
 */
@Service
public class ProfileEventService extends ProfileBasicService {
    /**
     *
     * @param demographicId
     * @param filter
     *  1. key=value的形式,多个条件用;分隔
     * @param blurryType
     *  1. 针对需要对特殊档案类型进行查询的参数(0-门诊 1-住院 2-体检 3-影像 4-检查 5-检验 6-妇幼 7-免疫)
     *  2. 此处有值的话filter参数中不能再包含event_type
     * @param date
     *  1. {"start":"2018-01-01T00:00:00Z","end":"2018-02-01T00:00:00Z","month":"2018-03"}
     * @param searchParam
     *  1. 此参数只针对机构和诊断
     * @return
     * @throws Exception
     */
    public List<Map<String,Object>> visits (String demographicId, String filter, String blurryType, String date, String searchParam) throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
        String query = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        Envelop envelop;
        if (!StringUtils.isEmpty(blurryType)) {
            if ("0".equals(blurryType)) { //门诊 clinic
                query = "{\"q\":\"demographic_id:" + demographicId + " AND event_type:0\"}";
            } else if ("1".equals(blurryType)) { //住院 resident
                query = "{\"q\":\"demographic_id:" + demographicId + " AND event_type:1\"}";
            } else if ("2".equals(blurryType)) { //体检 medicalExam
                query = "{\"q\":\"demographic_id:" + demographicId + " AND event_type:2\"}";
            } else if ("3".equals(blurryType)) { //影像 imagery
                Envelop envelop1 = resource.healthFile("profile_type=2;id_card_no=" + demographicId, "-event_date", 1, 1000);
                List<Map<String, Object>> list1 = envelop1.getDetailModelList();
                if (list1 != null && list1.size() > 0) {
                    for (Map<String, Object> temp : list1) {
                        Map<String, Object> resultMap = simpleEvent(temp, searchParam);
                        if (resultMap != null) {
                            resultMap.put("eventType", blurryType);
                            resultMap.put("mark", "mark"); //临时处理
                            resultList.add(resultMap);
                        }
                    }
                }
                return resultList;
            } else if ("4".equals(blurryType)) { //检查 inspect
                query = SimpleSolrQueryUtil.getQuery(filter, date, query);
                envelop = resource.getMasterData(query, 1, 1000, null);
                List<Map<String, Object>> eventList = envelop.getDetailModelList();
                if (eventList != null && eventList.size() > 0) {
                    for (Map<String, Object> temp : eventList) {
                        String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$HDSD00_79$*\"}";
                        Envelop subEnvelop = resource.getSubData(subQ, 1, 1, null);
                        List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                        if (subList != null && subList.size() > 0) {
                            Map<String, Object> resultMap = simpleEvent(temp, searchParam);
                            if (resultMap != null) {
                                resultMap.put("eventType", blurryType);
                                resultMap.put("mark", subList.get(0).get("EHR_000316")); //检查报告单号
                                resultList.add(resultMap);
                            }
                        }
                    }
                }
                return resultList;
            } else if ("5".equals(blurryType)) { //检验 examine
                query = SimpleSolrQueryUtil.getQuery(filter, date, query);
                envelop = resource.getMasterData(query, 1, 1000, null);
                List<Map<String, Object>> eventList = envelop.getDetailModelList();
                if (eventList != null && eventList.size() > 0) {
                    for (Map<String, Object> temp : eventList) {
                        String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$HDSD00_77$*\"}";
                        Envelop subEnvelop = resource.getSubData(subQ, 1, 1, null);
                        List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                        if (subList != null && subList.size() > 0) {
                            Map<String, Object> resultMap = simpleEvent(temp, searchParam);
                            if (resultMap != null) {
                                resultMap.put("eventType", blurryType);
                                resultMap.put("mark", subList.get(0).get("EHR_000363")); //检验报告单号
                                resultList.add(resultMap);
                            }
                        }
                    }
                }
                return resultList;
            } else if ("6".equals(blurryType)) { //妇幼 immunity
                //query = "{\"q\":\"demographic_id:" + demographicId + " AND EHR_002443:*\"}";
                return resultList;
            } else if ("7".equals(blurryType)){  //免疫 immunity
                query = SimpleSolrQueryUtil.getQuery(filter, date, query);
                envelop = resource.getMasterData(query, 1, 1000, null);
                List<Map<String, Object>> eventList = envelop.getDetailModelList();
                if (eventList != null && eventList.size() > 0) {
                    for (Map<String, Object> temp : eventList) {
                        String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$HDSB03_12$*\"}";
                        Envelop subEnvelop = resource.getSubData(subQ, 1, 1, null);
                        List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                        if (subList != null && subList.size() > 0) {
                            Map<String, Object> resultMap = simpleEvent(temp, searchParam);
                            if (resultMap != null) {
                                resultMap.put("eventType", blurryType);
                                resultMap.put("mark", subList.get(0).get("EHR_002438")); //预防接种卡编号
                                resultList.add(resultMap);
                            }
                        }
                    }
                }
                return resultList;
            } else {
                return resultList;
            }
            query = SimpleSolrQueryUtil.getQuery(filter, date, query);
            envelop = resource.getMasterData(query, 1, 1000, null);
            List<Map<String, Object>> eventList = envelop.getDetailModelList();
            if (eventList != null && eventList.size() > 0) {
                for (Map<String ,Object> temp : eventList) {
                    Map<String, Object> resultMap = simpleEvent(temp, searchParam);
                    if (resultMap != null) {
                        resultMap.put("eventType", blurryType);
                        resultList.add(resultMap);
                    }
                }
            }
            return resultList;
        } else {
            query = SimpleSolrQueryUtil.getQuery(filter, date, query);
            envelop = resource.getMasterData(query, 1, 1000, null);
            List<Map<String, Object>> eventList = envelop.getDetailModelList();
            if (eventList != null && eventList.size() > 0) {
                for (Map<String ,Object> temp : eventList) {
                    Map<String, Object> resultMap = simpleEvent(temp, searchParam);
                    if (resultMap != null) {
                        resultList.add(resultMap);
                    }
                }
            }
        }
        return resultList;
    }
    /**
     * 获取最近的一条就诊信息
     * @param demographicId
     * @return
     * @throws Exception
     */
    public Map<String, Object> recentVisit (String demographicId, Integer days) throws Exception {
        String q = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date now = calendar.getTime();
        Date before = DateUtils.addDays(now, days);
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        String start = dateFormat.format(before);
        String end = dateFormat.format(now);
        String date = "{\"start\":\"" + start + "\",\"end\":\"" + end + "\"}";
        q = SimpleSolrQueryUtil.getQuery(null, date, q);
        Envelop envelop = resource.getMasterData(q, 1, 500, null);
        List<Map<String, Object>> eventList = envelop.getDetailModelList();
        for (Map<String, Object> temp : eventList) {
            if (temp.get(ResourceCells.EVENT_TYPE) != null && temp.get(ResourceCells.EVENT_TYPE).equals("2")) {
                continue;
            }
            return simpleEvent(temp, null);
        }
        return new HashMap<>();
    }
    /**
     * 获取半年内的就诊记录
     * @param demographicId
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> recentVisits (String demographicId, Integer days) throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<>();
        String q = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date now = calendar.getTime();
        Date before = DateUtils.addDays(now, days);
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        String start = dateFormat.format(before);
        String end = dateFormat.format(DateUtils.addDays(now, 1));
        String date = "{\"start\":\"" + start + "\",\"end\":\"" + end + "\"}";
        q = SimpleSolrQueryUtil.getQuery(null, date, q);
        Envelop envelop = resource.getMasterData(q, 1, 500, null);
        List<Map<String, Object>> eventList = envelop.getDetailModelList();
        for (Map<String, Object> temp : eventList) {
            if (temp.get(ResourceCells.EVENT_TYPE) != null && temp.get(ResourceCells.EVENT_TYPE).equals("2")) {
                continue;
            }
            resultList.add(simpleEvent(temp, null));
        }
        return resultList;
    }
    public Map<String, Object> recentVisitsSub (String profileId) throws Exception {
        String q = "{\"q\":\"rowkey:" + profileId + "\"}";
        Envelop envelop = resource.getMasterData(q, 1, 1, null);
        List<Map<String, Object>> eventList = envelop.getDetailModelList();
        if (eventList.size() > 0) {
            Map<String ,Object> temp = eventList.get(0);
            Map<String, Object> resultMap = simpleEvent(temp, null);
            List<Map<String, Object>> diagnosisList = new ArrayList<>();
            if (!StringUtils.isEmpty(temp.get(ResourceCells.DIAGNOSIS))) {
                String [] diagnosisCode = ((String) temp.get(ResourceCells.DIAGNOSIS)).split(";");
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                Date now = calendar.getTime();
                Date before = DateUtils.addDays(now, -180);
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
                String start = dateFormat.format(before);
                String end = dateFormat.format(DateUtils.addDays(now, 1));
                String date = "{\"start\":\"" + start + "\",\"end\":\"" + end + "\"}";
                for (String code : diagnosisCode) {
                    q = SimpleSolrQueryUtil.getQuery("diagnosis?" + code, date, q);
                    envelop = resource.getMasterData(q, 1, 500, null);
                    String name = redisService.getIcd10Name(code);
                    Map<String, Object> diagnosisMap = new HashMap<>();
                    diagnosisMap.put("healthProblemName", name == null ? "自定义" : name);
                    diagnosisMap.put("count", envelop.getDetailModelList().size());
                    diagnosisList.add(diagnosisMap);
                }
            }
            resultMap.put("diagnosis", diagnosisList);
            String subQ = "{\"q\":\"profile_id:" + profileId + "\"}";
            Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
            List<Map<String, Object>> subList = subEnvelop.getDetailModelList(); //细表数据
            if (temp.get(ResourceCells.EVENT_TYPE).equals("0")) { //门诊信息
                resultMap.put("department", temp.get("EHR_000082") == null ? "" : temp.get("EHR_000082") );
                resultMap.put("doctor", temp.get("EHR_000079") == null ? "" : temp.get("EHR_000079"));
                resultMap.put("diagnosticResult", resultMap.get("healthProblemName")); //诊断结果
                //检查
                List<Map<String, Object>> inspectResult = new ArrayList<>();
                for (Map<String, Object> temp1 : subList) {
                    if (temp1.get(ResourceCells.ROWKEY).toString().contains("HDSD00_79")) {
                        if (temp1.get("EHR_002883") != null) {
                            Map<String, Object> data = new HashMap<>();
                            data.put("name", temp1.get("EHR_002883"));
                            data.put("mark", temp1.get("EHR_000316")); //检查报告单号
                            inspectResult.add(data);
                        }
                    }
                }
                resultMap.put("inspectResult", inspectResult);
                //检验
                List<Map<String, Object>> examineResult = new ArrayList<>();
                for (Map<String, Object> temp1 : subList) {
                    if (temp1.get(ResourceCells.ROWKEY).toString().contains("HDSD00_77")) {
                        if (temp1.get("EHR_000352") != null) {
                            Map<String, Object> data = new HashMap<>();
                            data.put("name", temp1.get("EHR_000352"));
                            data.put("mark", temp1.get("EHR_000363")); //检验报告单号
                            examineResult.add(data);
                        }
                    }
                }
                resultMap.put("examineResult", examineResult);
            } else if (temp.get(ResourceCells.EVENT_TYPE).equals("1")) { //住院信息
                String department = "";
                if (!StringUtils.isEmpty(temp.get("EHR_006209"))) {
                    department = (String) temp.get("EHR_006209");
                }
                if (StringUtils.isEmpty(department) && !StringUtils.isEmpty("EHR_000228_VALUE")) {
                    department = (String) temp.get("EHR_000228_VALUE");
                }
                if (StringUtils.isEmpty(department) && !StringUtils.isEmpty("EHR_000228")) {
                    department = (String) temp.get("EHR_000228");
                }
                resultMap.put("department", department);
                String doctor = "";
                for (Map<String, Object> temp1 : subList) {
                    if (temp1.get(ResourceCells.ROWKEY).toString().contains("HDSD00_11")) {
                        if (!StringUtils.isEmpty(temp1.get("EHR_005072"))) {
                            doctor = (String) temp1.get("EHR_005072");
                            break;
                        }
                    }
                }
                resultMap.put("doctor", doctor);
                resultMap.put("inSituation", temp.get("EHR_005203") == null ? "" : temp.get("EHR_005203")); //入院情况
                resultMap.put("outSituation", temp.get("EHR_000154") == null ? "" : temp.get("EHR_000154")); //出院情况
                String inResult = "";
                String outResult = "";
                for (Map<String, Object> temp1 : subList) {
                    if (temp1.get(ResourceCells.ROWKEY).toString().contains("HDSD00_69")) {
                        if (temp1.get("EHR_006081") != null) {
                            if (temp1.get("EHR_006081").equals("入院诊断")) {
                                inResult = temp1.get("EHR_000293_VALUE") != null ?  (String) temp1.get("EHR_000293_VALUE") :  (String) temp1.get("EHR_000293");
                            }
                            if (temp1.get("EHR_006081").equals("出院诊断")) {
                                outResult = temp1.get("EHR_000293_VALUE") != null ?  (String) temp1.get("EHR_000293_VALUE") :  (String) temp1.get("EHR_000293");
                            }
                        }
                    }
                }
                resultMap.put("inResult", inResult); //入院诊断
                resultMap.put("outResult", outResult); //出院诊断
                resultMap.put("treatmentResults", temp.get("EHR_000299") == null ? "" : temp.get("EHR_000299")); //治疗结果
                resultMap.put("dischargeInstructions", temp.get("EHR_000157") == null ? "" :  temp.get("EHR_000157")); //出院医嘱
            }
            return resultMap;
        }
        return new HashMap<>();
    }
}

+ 462 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileInfoBaseService.java

@ -0,0 +1,462 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.profile.feign.*;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.ehr.util.datetime.DateUtil;
import com.yihu.ehr.util.http.HttpResponse;
import com.yihu.ehr.util.http.HttpUtils;
import com.yihu.ehr.util.rest.Envelop;
import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * @author hzp 2016-05-26
 */
@Service
public class ProfileInfoBaseService extends BaseJpaService {
    @Autowired
    private ResourceClient resource;
    @Autowired
    private ProfileDiseaseService profileDiseaseService;
    @Autowired
    private RedisService redisService;
    /**
     * @获取患者档案基本信息
     */
    public Map<String, Object> getPatientInfo(String demographicId, String version) throws Exception {
        Envelop envelop = resource.getMasterData("{\"q\":\"demographic_id:" + demographicId + "\"}", 1, 1000, null);
        List<Map<String, Object>> list = envelop.getDetailModelList();
        Map<String, Object> patientMap = new HashMap<>();
        if (list != null && list.size() > 0) {
            Map<String, Object> result = new HashMap<>();
            List<String> allergyMedicine = new ArrayList<>();
            List<String> allergens = new ArrayList<>();
            if (list.size() == 1) {
                result = list.get(0);
                if (result.containsKey("EHR_004971")) {
                    allergyMedicine.add((String) result.get("result"));
                }
                if (result.containsKey("EHR_000011")) {
                    allergens.add((String) result.get("EHR_000011"));
                }
            } else {
                //合并数据
                for (Map<String, Object> obj : list) {
                    for (String key : obj.keySet()) {
                        if ("EHR_004971".equals(key)) {
                            if (!allergyMedicine.contains(obj.get("EHR_004971"))) {
                                allergyMedicine.add((String) obj.get("EHR_004971"));
                            }
                            continue;
                        }
                        if ("EHR_000011".equals(key)) {
                            if (!allergens.contains(obj.get("EHR_000011"))) {
                                allergens.add((String) obj.get("EHR_000011"));
                            }
                            continue;
                        }
                        if (!result.containsKey(key) && obj.get(key) != null) {
                            result.put(key, obj.get(key));
                        }
                    }
                }
            }
            //提取档案类型信息
            //身高
            String height = "";
            if (!StringUtils.isEmpty(result.get("EHR_000590"))) {
                height = (String) result.get("EHR_000590");
            }
            if (StringUtils.isEmpty(height) && !StringUtils.isEmpty(result.get("EHR_000778"))) {
                height = (String) result.get("EHR_000778");
            }
            if (StringUtils.isEmpty(height) && !StringUtils.isEmpty(result.get("EHR_001339"))) {
                height = (String) result.get("EHR_001339");
            }
            if (StringUtils.isEmpty(height) && !StringUtils.isEmpty(result.get("EHR_004263"))) {
                height = (String) result.get("EHR_004263");
            }
            if (StringUtils.isEmpty(height) && !StringUtils.isEmpty(result.get("EHR_005142"))) {
                height = (String) result.get("EHR_005142");
            }
            patientMap.put("height", height);
            //体重
            String weight = "";
            if (!StringUtils.isEmpty(result.get("EHR_000073"))) {
                weight = (String) result.get("EHR_000073");
            }
            if (StringUtils.isEmpty(weight) && !StringUtils.isEmpty(result.get("EHR_000785"))) {
                weight = (String) result.get("EHR_000785");
            }
            if (StringUtils.isEmpty(weight) && !StringUtils.isEmpty(result.get("EHR_001340"))) {
                weight = (String) result.get("EHR_001340");
            }
            if (StringUtils.isEmpty(weight) && !StringUtils.isEmpty(result.get("EHR_004002"))) {
                weight = (String) result.get("EHR_004002");
            }
            if (StringUtils.isEmpty(weight) && !StringUtils.isEmpty(result.get("EHR_004718"))) {
                weight = (String) result.get("EHR_004718");
            }
            if (StringUtils.isEmpty(weight) && !StringUtils.isEmpty(result.get("EHR_005148"))) {
                weight = (String) result.get("EHR_005148");
            }
            patientMap.put("weight", weight);
            List<String> labels = new ArrayList<>();
            if (result.get(ResourceCells.DIAGNOSIS) != null && result.get(ResourceCells.DIAGNOSIS).toString().contains("Z37")) { //1 新生儿
                labels.add("新生儿");
                //出生身高
                patientMap.put("height", result.get("EHR_001256") == null ? "" : result.get("EHR_001256"));
                //出生体重
                patientMap.put("weight", result.get("EHR_001257") == null ? "" : result.get("EHR_001257")); //单位(g)
            } else if (result.get(ResourceCells.DIAGNOSIS) != null && result.get(ResourceCells.DIAGNOSIS).toString().contains("O80")) { //2 孕妇
                labels.add("孕妇");
            } else if (profileDiseaseService.getHealthProblem(demographicId).size() > 0){
                labels.add("慢病");
            }
            Map<String, Object> params = new HashMap<>();
            params.put("idcard", demographicId);
            try {
                HttpResponse httpResponse = HttpUtils.doGet("http://localhost:8080/label/searchehrbaseinfo", params);
                if (httpResponse.isSuccessFlg()) {
                    Map<String, Object> labelResult = objectMapper.readValue(httpResponse.getContent(), Map.class);
                    labels = (List) labelResult.get("label");
                }
            } catch (Exception e) {
            }
            patientMap.put("label", labels);
            //姓名
            patientMap.put("name", result.get("patient_name") == null ? "" : result.get("patient_name"));
            //性别
            String gender = result.get("EHR_000019") == null ? "" : (String) result.get("EHR_000019");
            if ("1".equals(gender)) {
                patientMap.put("gender", "男");
            } else if ("2".equals(gender)) {
                patientMap.put("gender", "女");
            } else {
                patientMap.put("gender", "未知");
            }
            //出生日期
            String birthday = "";
            if (StringUtils.isEmpty(birthday) && !StringUtils.isEmpty(result.get("EHR_000007"))) {
                birthday = (String) result.get("EHR_000007");
            }
            if (StringUtils.isEmpty(birthday) && !StringUtils.isEmpty(result.get("EHR_000320"))) {
                birthday = (String) result.get("EHR_000320");
            }
            patientMap.put("birthday", birthday);
            //年龄
            if (!StringUtils.isEmpty(patientMap.get("birthday"))) {
                String date1 = patientMap.get("birthday").toString();
                String date2 = date1.substring(0, date1.indexOf("T"));
                Date date3 = DateUtil.formatCharDateYMD(date2, "yyyy-MM-dd");
                Calendar calendar = Calendar.getInstance();
                int now = calendar.get(Calendar.YEAR);
                Calendar calendar1 = Calendar.getInstance();
                calendar1.setTime(date3);
                int birthdayYear = calendar1.get(Calendar.YEAR);
                patientMap.put("age", String.valueOf(now - birthdayYear));
            } else {
                patientMap.put("age", "");
            }
            //民族
            patientMap.put("nation", result.get("EHR_000016_VALUE") == null ? "" : result.get("EHR_000016_VALUE"));
            //婚姻状态
            String marriage = "";
            if (!StringUtils.isEmpty(result.get("EHR_000014_VALUE"))) {
                marriage = (String) result.get("EHR_000014_VALUE");
            }
            if (StringUtils.isEmpty(marriage) && !StringUtils.isEmpty(result.get("EHR_004984_VALUE"))) {
                marriage = (String) result.get("EHR_004984_VALUE");
            }
            patientMap.put("marriage", marriage);
            //婚育
            patientMap.put("fertility", result.get("EHR_000540") == null ? "" : result.get("EHR_000540"));
            //ABO血型
            patientMap.put("ABO", result.get("EHR_000001_VALUE") == null ? "" : result.get("EHR_000001_VALUE"));
            //Rh血型
            patientMap.put("Rh", result.get("EHR_000002_VALUE") == null ? "" : result.get("EHR_000002_VALUE"));
            //过敏药物
            patientMap.put("allergyMedicine", allergyMedicine.isEmpty() ? "" : org.apache.commons.lang3.StringUtils.join(allergyMedicine, "、"));
            //过敏源
            patientMap.put("allergens", allergens.isEmpty() ? "" : org.apache.commons.lang3.StringUtils.join(allergens, "、"));
            //电话
            patientMap.put("patientTel", result.get("EHR_000003") == null ? "" : result.get("EHR_000003"));
            //国籍
            patientMap.put("country", result.get("EHR_004970_VALUE") == null ? "" : result.get("EHR_004970_VALUE"));
            //工作单位
            patientMap.put("employer", result.get("EHR_002930") == null ? "" : result.get("EHR_002930"));
            //户籍
            if (result.get("EHR_004945") != null && result.get("EHR_004946") != null) {
                patientMap.put("householdRegister", result.get("EHR_004945") + "-" + result.get("EHR_004946"));
            } else if (result.get("EHR_004945") != null && result.get("EHR_004946") == null) {
                patientMap.put("householdRegister", result.get("EHR_004945"));
            } else if (result.get("EHR_004945") == null && result.get("EHR_004946") != null) {
                patientMap.put("householdRegister", result.get("EHR_004946"));
            } else {
                patientMap.put("householdRegister", "");
            }
            patientMap.put("imgRemotePath", imgRemotePath(demographicId));
            return patientMap;
        } else {
            return patientMap;
        }
    }
    /**
     * 既往史
     * @param demographic_id
     * @return
     */
    public List<Map<String, Object>> pastHistory(String demographic_id) throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<>();
        //药物过敏
        Map<String, Object> patientInfo = getPatientInfo(demographic_id, null);
        Map<String, Object> allergyMedicine = new HashMap<>();
        allergyMedicine.put("label", "药物过敏");
        allergyMedicine.put("info", patientInfo.get("allergyMedicine"));
        resultList.add(allergyMedicine);
        //疾病 & 手术
        Envelop envelop;
        Map<String, Object> medicalHistory = new HashMap<>();
        Map<String, Object> surgery = new HashMap<>();
        String q4 = "{\"q\":\"demographic_id:" + demographic_id + "\"}";
        envelop = resource.getMasterData(q4, 1, 1000, null);
        List<Map<String, Object>> list4 = envelop.getDetailModelList();
        Set<String> hpSet = new HashSet<>();
        StringBuilder stringBuilder4 = new StringBuilder();
        if (list4 != null && list4.size() > 0) {
            for (Map temp : list4) {
                if (!StringUtils.isEmpty(temp.get(ResourceCells.HEALTH_PROBLEM_NAME))) {
                    String [] hpNames = temp.get(ResourceCells.HEALTH_PROBLEM_NAME).toString().split(";");
                    for (String hpName : hpNames) {
                        hpSet.add(hpName);
                    }
                } else if (!StringUtils.isEmpty(temp.get(ResourceCells.HEALTH_PROBLEM))) {
                    String [] _hpCode = ((String) temp.get(ResourceCells.HEALTH_PROBLEM)).split(";");
                    for (String code : _hpCode) {
                        String name = redisService.getHealthProblem(code);
                        if (!StringUtils.isEmpty(name)) {
                            hpSet.add(name);
                        }
                    }
                }
                String masterRowKey = (String) temp.get("rowkey");
                String subQ = "{\"q\":\"rowkey:" + masterRowKey + "$HDSD00_06$*" + "\"}";
                envelop = resource.getSubData(subQ, 1, 1000, null);
                List<Map<String, Object>> subList = envelop.getDetailModelList();
                if (subList != null && subList.size() > 0) {
                    for (Map subTemp : subList) {
                        if (subTemp.get("EHR_000418") != null) {
                            String operateName = (String) subTemp.get("EHR_000418");
                            stringBuilder4.append(operateName);
                            stringBuilder4.append("、");
                            break;
                        }
                    }
                }
            }
        }
        medicalHistory.put("label", "疾病");
        medicalHistory.put("info", org.apache.commons.lang3.StringUtils.join(hpSet, "、"));
        resultList.add(medicalHistory);
        surgery.put("label", "手术");
        surgery.put("info", stringBuilder4.toString());
        resultList.add(surgery);
        //外伤
        Map<String, Object> trauma = new HashMap<>();
        trauma.put("label", "外伤");
        trauma.put("info", "");
        resultList.add(trauma);
        //输血
        Map<String, Object> bloodTransfusion = new HashMap<>();
        bloodTransfusion.put("label", "输血");
        bloodTransfusion.put("info", "");
        resultList.add(bloodTransfusion);
        //预防接种
        Map<String, Object> vaccination = new HashMap<>(2);
        String q5 = "{\"q\":\"demographic_id:" + demographic_id + "\"}";
        envelop = resource.getMasterData(q5, 1, 1000, null);
        List<Map<String, Object>> list5 = envelop.getDetailModelList();
        StringBuilder stringBuilder5 = new StringBuilder();
        if (list5 != null && list5.size() > 0) {
            for (Map temp : list5) {
                String masterRowKey = (String) temp.get("rowkey");
                String subQ = "{\"q\":\"rowkey:" + masterRowKey + "$HDSB03_12$*" + "\"}";
                envelop = resource.getSubData(subQ, 1, 1000, null);
                List<Map<String, Object>> subList = envelop.getDetailModelList();
                if (subList != null && subList.size() > 0) {
                    for (Map subTemp : subList) {
                        if (subTemp.get("EHR_002449") != null) {
                            String operateName = (String) subTemp.get("EHR_002449");
                            stringBuilder5.append(operateName);
                            stringBuilder5.append("、");
                            break;
                        }
                    }
                }
            }
        }
        vaccination.put("label", "预防接种");
        vaccination.put("info", stringBuilder5.toString());
        resultList.add(vaccination);
        return resultList;
    }
    /**
     * 过敏史
     * @param demographic_id
     * @return
     */
    public Map<String, Object> allergensHistory(String demographic_id) throws Exception {
        Map<String, Object> patientInfo = getPatientInfo(demographic_id, null);
        Map<String, Object> allergens = new HashMap<>();
        allergens.put("label", "过敏源");
        allergens.put("info", patientInfo.get("allergens"));
        return allergens;
    }
    /**
     * 家族史
     * @param demographic_id
     * @return
     */
    public Map<String, Object> familyHistory(String demographic_id) {
        Map<String, Object> familyHistory = new HashMap<>();
        familyHistory.put("label", "家族史");
        familyHistory.put("info", "");
        return familyHistory;
    }
    /**
     * 个人史
     * @param demographic_id
     * @return
     */
    public Map<String, Object> personHistory(String demographic_id) {
        Envelop envelop = resource.getMasterData("{\"q\":\"demographic_id:" + demographic_id + "\"}", 1, 1000, null);
        List<Map<String, Object>> list = envelop.getDetailModelList();
        Map<String, Object> personHistory = new HashMap<>();
        if (list != null && list.size() > 0) {
            Map<String, Object> result = new HashMap<>();
            if (list.size() == 1) {
                result = list.get(0);
            } else {
                //合并数据
                for (Map<String, Object> obj : list) {
                    for (String key : obj.keySet()) {
                        if (!result.containsKey(key)) {
                            result.put(key, obj.get(key));
                        }
                    }
                }
            }
            personHistory.put("name", result.get("patient_name") == null? "" : result.get("patient_name"));
            //出生地
            String placeOfBirth = "";
            String province = (String) result.get("EHR_004945");
            String city = (String) result.get("EHR_004946") ;
            String county = (String) result.get("EHR_004947");
            if (!StringUtils.isEmpty(province) && !province.equals("-")) {
                placeOfBirth += province + "-";
            }
            if (!StringUtils.isEmpty(city) && !city.equals("-")) {
                placeOfBirth += city + "-";
            }
            if (!StringUtils.isEmpty(county) && !county.equals("-")) {
                placeOfBirth += county;
            }
            personHistory.put("placeOfBirth", placeOfBirth);
            //居住地
            String placeOfResidence = "";
            if (!StringUtils.isEmpty(result.get("EHR_000760"))) {
                placeOfResidence = (String) result.get("EHR_000760");
            }
            if (StringUtils.isEmpty(placeOfResidence) && !StringUtils.isEmpty(result.get("EHR_003051"))) {
                placeOfResidence = (String) result.get("EHR_003051");
            }
            personHistory.put("placeOfResidence", placeOfResidence);
            //生活条件
            personHistory.put("livingCondition", "");
            //文化程度
            personHistory.put("educationLevel", result.get("EHR_000790") == null? "" : result.get("EHR_000790"));
            //职业
            personHistory.put("career", result.get("EHR_000022_VALUE") == null? "" : result.get("EHR_000022_VALUE"));
            //嗜烟
            String smoke = "";
            if (!StringUtils.isEmpty(result.get("EHR_002114"))) {
                smoke = (String) result.get("EHR_002114");
            }
            if (StringUtils.isEmpty(smoke) && !StringUtils.isEmpty(result.get("EHR_004722"))) {
                smoke = (String) result.get("EHR_004722");
            }
            personHistory.put("smoke", smoke);
            //嗜酒
            String alcohol = "";
            if (!StringUtils.isEmpty(result.get("EHR_002117"))) {
                alcohol = (String) result.get("EHR_002117");
            }
            if (StringUtils.isEmpty(alcohol) && !StringUtils.isEmpty(result.get("EHR_004728"))) {
                alcohol = (String) result.get("EHR_004728");
            }
            personHistory.put("alcohol", alcohol);
            //疫水接触
            personHistory.put("epidemicWater contact", "");
            //疫区接触
            personHistory.put("infectedArea", "");
            //放射性物质接触
            personHistory.put("radioactiveMaterialContact", "");
        }
        return personHistory;
    }
    private String imgRemotePath(String idCardNo) {
        String sql = "SELECT img_remote_path FROM users WHERE id_card_no = :idCardNo";
        Session session = currentSession();
        Query query = session.createSQLQuery(sql);
        query.setString("idCardNo", idCardNo);
        query.setFlushMode(FlushMode.COMMIT);
        Object path = query.uniqueResult();
        if (path != null) {
            return (String) path;
        }
        return "";
    }
    private int compareAgeOfDisease(String AgeOfDisease1, String AgeOfDisease2){
        int year1 = 0;
        int month1 = 0;
        int year2 = 0;
        int month2 = 0;
        if (AgeOfDisease1.split("年|个月").length>1) {
            year1 = Integer.parseInt(AgeOfDisease1.split("年|个月")[0]);
            month1 = Integer.parseInt(AgeOfDisease1.split("年|个月")[1]);
        } else {
            month1 = Integer.parseInt(AgeOfDisease1.split("年|个月")[0]);
        }
        if (AgeOfDisease2.split("年|个月").length>1) {
            year2 = Integer.parseInt(AgeOfDisease2.split("年|个月")[0]);
            month2 = Integer.parseInt(AgeOfDisease2.split("年|个月")[1]);
        } else {
            month2 = Integer.parseInt(AgeOfDisease2.split("年|个月")[0]);
        }
        if (year1 * 12 + month1 <= year2 * 12 + month2) {
            return 1;
        } else {
            return 0;
        }
    }
}

+ 381 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileInspectionService.java

@ -0,0 +1,381 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.profile.model.InspectionInfo;
import com.yihu.ehr.profile.util.NumberValidationUtils;
import com.yihu.ehr.profile.util.SimpleSolrQueryUtil;
import com.yihu.ehr.util.rest.Envelop;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Created by progr1mmer on 2018/3/13.
 */
@Service
public class ProfileInspectionService extends ProfileBasicService {
    public List inspectionRecords(String demographicId, String filter, String date, String searchParam) throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String, String> typeMap = new HashMap<>();
        typeMap.put("HDSD00_79", "inspect");
        typeMap.put("HDSD00_77", "examine");
        Map<String, String> nameMap = new HashMap<>();
        nameMap.put("HDSD00_79", "EHR_002883"); //检查名称
        nameMap.put("HDSD00_77", "EHR_000352"); //检验项目
        Map<String, String> numMap = new HashMap<>();
        numMap.put("HDSD00_79", "EHR_000316"); //检查报告单号
        numMap.put("HDSD00_77", "EHR_000363"); //检验报告单号
        for (String dataset : typeMap.keySet()) {
            String query = "{\"q\":\"demographic_id:" + demographicId + "\"}";
            query = SimpleSolrQueryUtil.getQuery(filter, date, query);
            Envelop masterEnvelop = resource.getMasterData(query, 1, 1000, null);
            if (masterEnvelop.isSuccessFlg()) {
                List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
                //循环获取结果集
                for (Map<String, Object> temp : masterList) {
                    String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$" + dataset + "$*\"}";
                    Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                    List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                    subList.forEach(item -> {
                        Map<String, Object> resultMap = simpleEvent(temp, searchParam);
                        if (resultMap != null) {
                            String healthProblemName = (String) resultMap.get("healthProblemName");
                            String itemName = (String) item.get(nameMap.get(dataset));
                            if (itemName != null) {
                                resultMap.put("projectName", itemName);
                            } else {
                                if (dataset.equals("HDSD00_79")) {
                                    resultMap.put("projectName", "检查报告-" + healthProblemName);
                                } else {
                                    resultMap.put("projectName", "检验报告-" + healthProblemName);
                                }
                            }
                            resultMap.put("type", typeMap.get(dataset));
                            resultMap.put("mark", item.get(numMap.get(dataset)));
                            resultList.add(resultMap);
                        }
                    });
                }
            }
        }
        return resultList;
    }
    public List<InspectionInfo> inspectionStatistics(String demographicId, String table) throws Exception {
        String query = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        query = SimpleSolrQueryUtil.getQuery(null, null, query);
        Envelop masterEnvelop = resource.getMasterData(query, 1, 1000, null);
        Map<String, Integer> dataMap = new HashMap<>();
        Map<String, String> firstMap = new HashMap<>();
        Map<String, String> lastMap = new HashMap<>();
        Map<String, Integer> exMap = new HashMap<>();
        if (masterEnvelop.isSuccessFlg()) {
            List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
            //循环获取结果集
            for (Map<String, Object> temp : masterList) {
                String subQ = "{\"q\":\"rowkey:" + temp.get("rowkey") + "$" + table + "$*\"}";
                Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                for (int i = 0; i < subList.size(); i ++) {
                    Map<String, Object> item = subList.get(i);
                    if (!StringUtils.isEmpty(item.get("EHR_002883"))) {  //检查名称
                        String name = item.get("EHR_002883").toString();
                        String result = item.get("EHR_000347") == null ? "-" : item.get("EHR_000347").toString(); //影像结论
                        if (dataMap.containsKey(name)) {
                            Integer count = dataMap.get(name);
                            dataMap.put(name, count + 1);
                            lastMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + result);
                        } else {
                            dataMap.put(name, 1);
                            firstMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + result);
                        }
                        if (!StringUtils.isEmpty(item.get("EHR_000344"))) {
                            String ex = item.get("EHR_000344").toString();
                            if ("1".equals(ex)) {
                                if (exMap.containsKey(name)) {
                                    Integer count = exMap.get(name);
                                    exMap.put(name, count + 1);
                                } else {
                                    exMap.put(name, 1);
                                }
                            }
                        }
                    } else if (!StringUtils.isEmpty(item.get("EHR_000352"))) { //检验项目
                        String name = item.get("EHR_000352").toString();
                        if (dataMap.containsKey(name)) {
                            Integer count = dataMap.get(name);
                            dataMap.put(name, count + 1);
                            lastMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + "-");
                        } else {
                            dataMap.put(name, 1);
                            firstMap.put(name, temp.get(ResourceCells.EVENT_DATE) + "&" + temp.get(ResourceCells.ORG_NAME) + "&" + item.get(ResourceCells.ROWKEY) + "&" + "-");
                        }
                    }
                }
            }
        }
        Map<String, Integer> newDataMap = sortByValue(dataMap);
        List<InspectionInfo> inspectionInfos = new ArrayList<>();
        newDataMap.forEach((key, val) -> {
            InspectionInfo inspectionInfo = new InspectionInfo();
            inspectionInfo.setName(key);
            inspectionInfo.setCount(val);
            inspectionInfo.setFirstTime(firstMap.get(key).split("&")[0]);
            if (exMap.containsKey(key)) {
                inspectionInfo.setExCount(exMap.get(key));
            }
            if (lastMap.get(key) != null) {
                inspectionInfo.setLastTime(lastMap.get(key).split("&")[0]);
                inspectionInfo.setLastOrg(lastMap.get(key).split("&")[1]);
                inspectionInfo.setLastRecord(lastMap.get(key).split("&")[2]);
                inspectionInfo.setResult(lastMap.get(key).split("&")[3]);
            } else {
                inspectionInfo.setLastTime(firstMap.get(key).split("&")[0]);
                inspectionInfo.setLastOrg(firstMap.get(key).split("&")[1]);
                inspectionInfo.setLastRecord(firstMap.get(key).split("&")[2]);
                inspectionInfo.setResult(firstMap.get(key).split("&")[3]);
            }
            inspectionInfos.add(inspectionInfo);
        });
        return inspectionInfos;
    }
    public Map<String, String> inspectionStatisticsOneSub(String profileId) throws Exception {
        Map<String, String> dataMap = new HashMap<>();
        String subQ = "{\"q\":\"rowkey:" + profileId + "\"}";
        Envelop subData = resource.getSubData(subQ, 1, 1, null);
        List<Map<String, Object>> subList = subData.getDetailModelList();
        if (subList.size() > 0) {
            Map<String, Object> temp = subList.get(0);
            String reportNo = temp.get("EHR_000363").toString(); //检验报告单号
            subQ = "{\"q\":\"rowkey:" + profileId.split("\\$")[0] + "$HDSD00_75$*" + "\"}";
            subData = resource.getSubData(subQ, 1, 1000, null);
            List<Map<String, Object>> subItems = subData.getDetailModelList();
            subItems.forEach(item -> {
                if (reportNo.equals(item.get("EHR_006339"))) { //子项所属的报告单号
                    //结果值
                    if (item.get("EHR_000387") != null) {
                        String result = item.get("EHR_000387").toString(); //结果值
                        if (item.get("EHR_000391") != null && item.get("EHR_000390")!= null) {
                            String low = item.get("EHR_000391").toString(); //下限
                            String high = item.get("EHR_000390").toString(); //上限
                            if (NumberValidationUtils.isRealNumber(result) && NumberValidationUtils.isRealNumber(low) && NumberValidationUtils.isRealNumber(high)) {
                                Double _result = Double.parseDouble(result);
                                Double _row = Double.parseDouble(low);
                                Double _high = Double.parseDouble(high);
                                if (_result < _row) {
                                    dataMap.put(item.get("EHR_000394").toString(), "偏低");
                                } else if (_result > _high) {
                                    dataMap.put(item.get("EHR_000394").toString(), "偏高");
                                } else {
                                    dataMap.put(item.get("EHR_000394").toString(), "正常");
                                }
                            } else {
                                dataMap.put(item.get("EHR_000394").toString(), item.get("EHR_000387").toString());
                            }
                        } else {
                            dataMap.put(item.get("EHR_000394").toString(), item.get("EHR_000387").toString());
                        }
                    } else {
                        dataMap.put(item.get("EHR_000394").toString(), "");
                    }
                }
            });
        }
        return dataMap;
    }
    public Map<String, Map<String, Integer>> inspectionStatisticsAllSub(String demographicId, String name) throws Exception {
        String query = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        query = SimpleSolrQueryUtil.getQuery(null, null, query);
        Envelop masterEnvelop = resource.getMasterData(query, 1, 1000, null);
        List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
        //循环获取结果集
        Set<String> data = new HashSet<>();
        Map<String, Integer> lowMap = new HashMap<>();
        Map<String, Integer> highMap = new HashMap<>();
        Map<String, Integer> normalMap = new HashMap<>();
        Map<String, Integer> unknownMap = new HashMap<>();
        Map<String, Integer> positiveMap = new HashMap<>();
        Map<String, Integer> negativeMap = new HashMap<>();
        for (Map<String, Object> masterItem : masterList) {
            String subQ = "{\"q\":\"rowkey:" + masterItem.get("rowkey") + "$HDSD00_77$*\"}";
            Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
            List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
            for (Map<String, Object> subItem : subList) {
                if (name.equals(subItem.get("EHR_000352"))) { //检验项目
                    String reportNo = subItem.get("EHR_000363").toString(); //检验报告单号
                    subQ = "{\"q\":\"rowkey:" + masterItem.get(ResourceCells.ROWKEY) + "$HDSD00_75$*" + "\"}";
                    subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                    List<Map<String, Object>> subItems = subEnvelop.getDetailModelList();
                    subItems.forEach(item -> {
                        if (reportNo.equals(item.get("EHR_006339"))) { //子项所属的报告单号
                            String itemName = item.get("EHR_000394").toString(); //子项名称
                            data.add(itemName);
                            //结果值
                            if (item.get("EHR_000387") != null) { //结果值
                                String result = item.get("EHR_000387").toString();
                                if (item.get("EHR_000391") != null && item.get("EHR_000390")!= null) {
                                    String low = item.get("EHR_000391").toString(); //上限
                                    String high = item.get("EHR_000390").toString(); //下限
                                    if (NumberValidationUtils.isRealNumber(result) && NumberValidationUtils.isRealNumber(low) && NumberValidationUtils.isRealNumber(high)) {
                                        Double _result = Double.parseDouble(result);
                                        Double _row = Double.parseDouble(low);
                                        Double _high = Double.parseDouble(high);
                                        if (_result < _row) {
                                            if (lowMap.containsKey(itemName)) {
                                                lowMap.put(itemName, lowMap.get(itemName) + 1);
                                            } else {
                                                lowMap.put(itemName, 1);
                                            }
                                        } else if (_result > _high) {
                                            if (highMap.containsKey(itemName)) {
                                                highMap.put(itemName, highMap.get(itemName) + 1);
                                            } else {
                                                highMap.put(itemName, 1);
                                            }
                                        } else {
                                            if (normalMap.containsKey(itemName)) {
                                                normalMap.put(itemName, normalMap.get(itemName) + 1);
                                            } else {
                                                normalMap.put(itemName, 1);
                                            }
                                        }
                                    } else {
                                        if (unknownMap.containsKey(itemName)) {
                                            unknownMap.put(itemName, unknownMap.get(itemName) + 1);
                                        } else {
                                            unknownMap.put(itemName, 1);
                                        }
                                    }
                                } else if (item.get("EHR_000382") != null) { //参考值备注
                                    String range = item.get("EHR_000382").toString();
                                    if (range.split("-").length == 2) {
                                        String low = range.split("-")[0]; //上限
                                        String high = range.split("-")[1]; //下限
                                        if (NumberValidationUtils.isRealNumber(result) && NumberValidationUtils.isRealNumber(low) && NumberValidationUtils.isRealNumber(high)) {
                                            Double _result = Double.parseDouble(result);
                                            Double _row = Double.parseDouble(low);
                                            Double _high = Double.parseDouble(high);
                                            if (_result < _row) {
                                                if (lowMap.containsKey(itemName)) {
                                                    lowMap.put(itemName, lowMap.get(itemName) + 1);
                                                } else {
                                                    lowMap.put(itemName, 1);
                                                }
                                            } else if (_result > _high) {
                                                if (highMap.containsKey(itemName)) {
                                                    highMap.put(itemName, highMap.get(itemName) + 1);
                                                } else {
                                                    highMap.put(itemName, 1);
                                                }
                                            } else {
                                                if (normalMap.containsKey(itemName)) {
                                                    normalMap.put(itemName, normalMap.get(itemName) + 1);
                                                } else {
                                                    normalMap.put(itemName, 1);
                                                }
                                            }
                                        } else {
                                            if (unknownMap.containsKey(itemName)) {
                                                unknownMap.put(itemName, unknownMap.get(itemName) + 1);
                                            } else {
                                                unknownMap.put(itemName, 1);
                                            }
                                        }
                                    } else {
                                        if (unknownMap.containsKey(itemName)) {
                                            unknownMap.put(itemName, unknownMap.get(itemName) + 1);
                                        } else {
                                            unknownMap.put(itemName, 1);
                                        }
                                    }
                                } else  {
                                    if (result.equals("阳性")) {
                                        if (positiveMap.containsKey(itemName)) {
                                            positiveMap.put(itemName, positiveMap.get(itemName) + 1);
                                        } else {
                                            positiveMap.put(itemName, 1);
                                        }
                                    } else if (result.equals("阴性")) {
                                        if (negativeMap.containsKey(itemName)) {
                                            negativeMap.put(itemName, negativeMap.get(itemName) + 1);
                                        } else {
                                            negativeMap.put(itemName, 1);
                                        }
                                    } else {
                                        if (unknownMap.containsKey(itemName)) {
                                            unknownMap.put(itemName, unknownMap.get(itemName) + 1);
                                        } else {
                                            unknownMap.put(itemName, 1);
                                        }
                                    }
                                }
                            } else {
                                if (unknownMap.containsKey(itemName)) {
                                    unknownMap.put(itemName, unknownMap.get(itemName) + 1);
                                } else {
                                    unknownMap.put(itemName, 1);
                                }
                            }
                        }
                    });
                }
            }
        }
        Map<String, Map<String, Integer>> result = new HashMap<>();
        data.forEach(item -> {
            Map<String, Integer> details = new HashMap<>();
            if (lowMap.containsKey(item)) {
                details.put("偏低", lowMap.get(item));
            }
            if (highMap.containsKey(item)) {
                details.put("偏高", highMap.get(item));
            }
            if (normalMap.containsKey(item)) {
                details.put("正常", normalMap.get(item));
            }
            if (unknownMap.containsKey(item)) {
                details.put("未知", unknownMap.get(item));
            }
            if (positiveMap.containsKey(item)) {
                details.put("阳性", positiveMap.get(item));
            }
            if (negativeMap.containsKey(item)) {
                details.put("阴性", negativeMap.get(item));
            }
            result.put(item, details);
        });
        return result;
    }
    private Map<String, Integer> sortByValue(Map<String, Integer> sourceMap) {
        if (sourceMap == null || sourceMap.isEmpty()) {
            return sourceMap;
        }
        Map<String, Integer> sortedMap = new LinkedHashMap<>();
        List<Map.Entry<String, Integer>> entryList = new ArrayList<>(sourceMap.entrySet());
        Collections.sort(entryList, new MapValueComparator());
        Iterator<Map.Entry<String, Integer>> iterator = entryList.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Integer> tmpEntry = iterator.next();
            sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
        }
        return sortedMap;
    }
    class MapValueComparator implements Comparator<Map.Entry<String, Integer>> {
        @Override
        public int compare(Map.Entry<String, Integer> me1, Map.Entry<String, Integer> me2) {
            return - me1.getValue().compareTo(me2.getValue());
        }
    }
}

+ 298 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileMedicationService.java

@ -0,0 +1,298 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.profile.model.DrugInfo;
import com.yihu.ehr.profile.util.SimpleSolrQueryUtil;
import com.yihu.ehr.util.rest.Envelop;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.*;
/**
 * Created by progr1mmer on 2018/3/13.
 */
@Service
public class ProfileMedicationService extends ProfileBasicService {
    public Map<String, Integer> medicationRanking(String demographicId, String filter, String hpCode, String date) throws Exception {
        String masterQ;
        if (!StringUtils.isEmpty(hpCode)) {
            masterQ = "{\"q\":\"demographic_id:" + demographicId + " AND health_problem:*" +  hpCode + "*\"}";
        } else {
            masterQ = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        }
        masterQ = SimpleSolrQueryUtil.getQuery(filter, date, masterQ);
        Map<String, Integer> dataMap = new HashMap<>();
        Envelop masterEnvelop = resource.getMasterData(masterQ, 1, 500, null);
        if (masterEnvelop.isSuccessFlg()) {
            List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
            //循环获取结果集
            for (Map<String, Object> masterMap : masterList) {
                String rowKey = (String) masterMap.get(ResourceCells.ROWKEY);
                String subQ = "{\"q\":\"rowkey:" + rowKey + "$HDSD00_83$* OR rowkey:" + rowKey + "$HDSD00_84$*\"}";
                Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                if (subEnvelop.isSuccessFlg()) {
                    List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                    if (subList.size() > 0) {
                        for (Map<String, Object> subMap : subList) {
                            if (!StringUtils.isEmpty(subMap.get("EHR_000131"))) {
                                String drugName = (String) subMap.get("EHR_000131");
                                if (dataMap.containsKey(drugName)) {
                                    Integer count = dataMap.get(drugName);
                                    dataMap.put(drugName, count + 1);
                                } else {
                                    dataMap.put(drugName, 1);
                                }
                                continue;
                            }
                            if (!StringUtils.isEmpty(subMap.get("EHR_000100"))) {
                                String drugName = (String) subMap.get("EHR_000100");
                                if (dataMap.containsKey(drugName)) {
                                    Integer count = dataMap.get(drugName);
                                    dataMap.put(drugName, count + 1);
                                } else {
                                    dataMap.put(drugName, 1);
                                }
                                continue;
                            }
                        }
                    }
                }
            }
        }
        return sortByValue(dataMap);
    }
    public List<DrugInfo> medicationRankingWithTable(String demographicId, String filter, String hpCode, String date, String table) throws Exception {
        String masterQ;
        if (!StringUtils.isEmpty(hpCode)) {
            masterQ = "{\"q\":\"demographic_id:" + demographicId + " AND health_problem:*" +  hpCode + "*\"}";
        } else {
            masterQ = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        }
        masterQ = SimpleSolrQueryUtil.getQuery(filter, date, masterQ);
        Map<String, Integer> dataMap = new HashMap<>();
        Envelop masterEnvelop = resource.getMasterData(masterQ, 1, 500, null);
        if (masterEnvelop.isSuccessFlg()) {
            List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
            //循环获取结果集
            for (Map<String, Object> masterMap : masterList) {
                String rowKey = (String) masterMap.get(ResourceCells.ROWKEY);
                String subQ;
                if (StringUtils.isEmpty(table)) {
                    subQ = "{\"q\":\"rowkey:" + rowKey + "$HDSD00_83$* OR rowkey:" + rowKey + "$HDSD00_84$*\"}";
                } else {
                    subQ = "{\"q\":\"rowkey:" + rowKey + "$" + table + "$*\"}";
                }
                Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                if (subEnvelop.isSuccessFlg()) {
                    List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                    if (subList.size() > 0) {
                        for (Map<String, Object> subMap : subList) {
                            if (!StringUtils.isEmpty(subMap.get("EHR_000131"))) {
                                String drugName = subMap.get("EHR_000131") + "_01";  //中药名称
                                if (dataMap.containsKey(drugName)) {
                                    Integer count = dataMap.get(drugName);
                                    dataMap.put(drugName, count + 1);
                                } else {
                                    dataMap.put(drugName, 1);
                                }
                                continue;
                            }
                            if (!StringUtils.isEmpty(subMap.get("EHR_000100"))) {
                                String drugName = subMap.get("EHR_000100") + "_02"; //西药名称
                                if (dataMap.containsKey(drugName)) {
                                    Integer count = dataMap.get(drugName);
                                    dataMap.put(drugName, count + 1);
                                } else {
                                    dataMap.put(drugName, 1);
                                }
                                continue;
                            }
                        }
                    }
                }
            }
        }
        List<DrugInfo> drugInfos = new ArrayList<>();
        dataMap = sortByValue(dataMap);
        dataMap.forEach((key, val) -> {
            DrugInfo drugInfo = new DrugInfo();
            String [] info = key.split("_");
            drugInfo.setName(info[0]);
            drugInfo.setCount(val);
            if (info[1].endsWith("01")) {
                drugInfo.setLabel("中药");
            } else {
                drugInfo.setLabel("西药");
            }
            drugInfos.add(drugInfo);
        });
        return drugInfos;
    }
    public List<Map<String, Object>> medicationRecords(String demographicId, String filter, String date, String keyWord) throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<>();
        String masterQ = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        masterQ = SimpleSolrQueryUtil.getQuery(filter, date, masterQ);
        Envelop masterEnvelop = resource.getMasterData(masterQ, 1, 500, null);
        if (masterEnvelop.isSuccessFlg()) {
            List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
            //循环获取结果集
            for (Map<String, Object> masterMap : masterList) {
                String rowKey = (String) masterMap.get(ResourceCells.ROWKEY);
                String subQ = "{\"q\":\"rowkey:" + rowKey + "$HDSD00_83$* OR rowkey:" + rowKey + "$HDSD00_84$*\"}";
                Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
                if (subEnvelop.isSuccessFlg()) {
                    List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
                    if (subList.size() > 0) {
                        boolean match = false;
                        String typeMark = "00"; //中西药标识
                        for (Map<String, Object> subMap : subList) {
                            if (subMap.get("EHR_000131") != null) {
                                if (subMap.get(ResourceCells.ROWKEY).toString().contains("HDSD00_83")) {
                                    typeMark = "01"; //中药
                                } else {
                                    typeMark = "02"; //西药
                                }
                                if (keyWord != null) {
                                    if (subMap.get("EHR_000131").toString().contains(keyWord)) {
                                        match = true;
                                        break;
                                    }
                                } else {
                                    match = true;
                                    break;
                                }
                            }
                            if (subMap.get("EHR_000100") != null) {
                                if (subMap.get(ResourceCells.ROWKEY).toString().contains("HDSD00_83")) {
                                    typeMark = "01"; //中药
                                } else {
                                    typeMark = "02"; //西药
                                }
                                if (keyWord != null && subMap.get("EHR_000100") != null) {
                                    if (subMap.get("EHR_000100").toString().contains(keyWord)) {
                                        match = true;
                                        break;
                                    }
                                } else {
                                    match = true;
                                    break;
                                }
                            }
                        }
                        if (match) {
                            //时间轴基本字段
                            Map<String, Object> resultMap = simpleEvent(masterMap, null);
                            resultMap.put("mark", typeMark);
                            if (masterMap.get(ResourceCells.EVENT_TYPE).equals("0")) { //门诊信息
                                resultMap.put("department", masterMap.get("EHR_000082"));
                                resultMap.put("doctor", masterMap.get("EHR_000079"));
                            } else if (masterMap.get(ResourceCells.EVENT_TYPE).equals("1")) { //住院信息
                                resultMap.put("department", masterMap.get("EHR_000229"));
                                resultMap.put("doctor", masterMap.get("EHR_005072"));
                            }
                            resultList.add(resultMap);
                        }
                    }
                }
            }
        }
        return resultList;
    }
    public Envelop recentMedicationSub(String demographicId, String date, Integer page, Integer size) throws Exception {
        String masterQ = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        masterQ = SimpleSolrQueryUtil.getQuery(null, date, masterQ);
        Envelop masterEnvelop = resource.getMasterData(masterQ, 1, 500, null);
        List<Map<String, Object>> masterList = masterEnvelop.getDetailModelList();
        List<Map<String, Object>> dataList = new ArrayList<>();
        Object eventDate = "";
        for (Map<String, Object> event : masterList) {
            //详情
            String rowKey = (String) event.get(ResourceCells.ROWKEY);
            String subQ = "{\"q\":\"rowkey:" + rowKey + "$HDSD00_83$* OR rowkey:" + rowKey + "$HDSD00_84$*\"}";
            Envelop subEnvelop = resource.getSubData(subQ, 1, 1000, null);
            List<Map<String, Object>> subList = subEnvelop.getDetailModelList();
            if (subList.size() > 0) {
                for (Map<String, Object> subMap : subList) {
                    Map<String, Object> dataMap = new HashMap<>();
                    dataMap.put("prescriptionNumber", subMap.get("EHR_000086") == null ? "" : subMap.get("EHR_000086") ); //处方编号
                    dataMap.put("substancesForDrugUse", subMap.get("EHR_000101") == null ? "" : subMap.get("EHR_000101")); //药物使用次剂量
                    dataMap.put("prescriptionDrugGroupNumber", subMap.get("EHR_000127") == null ? "" : subMap.get("EHR_000127")); //处方药品组号
                    dataMap.put("drugSpecifications", subMap.get("EHR_000129") == null ? "" : subMap.get("EHR_000129")); //药物规格
                    dataMap.put("drugFormulationCode", subMap.get("EHR_000130") == null ? "" : subMap.get("EHR_000130")); //药物剂型代码
                    dataMap.put("drugFormulationValue", subMap.get("EHR_000130_VALUE") == null ? "" : subMap.get("EHR_000130_VALUE")); //药物剂型值
                    String drugName = "";
                    if (!StringUtils.isEmpty(subMap.get("EHR_000100"))) {
                        drugName = (String) subMap.get("EHR_000100");
                    } else if (!StringUtils.isEmpty(subMap.get("EHR_000131"))) {
                        drugName = (String) subMap.get("EHR_000131");
                    }
                    dataMap.put("drugName", drugName); //药物名称
                    dataMap.put("drugsUseDosageUnits", subMap.get("EHR_000133") == null ? "" :  subMap.get("EHR_000133")); //药物使用剂量单位
                    dataMap.put("drugUsageFrequencyCode", subMap.get("EHR_000134") == null ? "" : subMap.get("EHR_000134")); //药物使用频次代码
                    dataMap.put("drugUsageFrequencyValue", subMap.get("EHR_000134_VALUE") == null ? "" :  subMap.get("EHR_000134_VALUE")); //药物使用频次值
                    dataMap.put("totalDoseOfDrugUsed", subMap.get("EHR_000135") == null ? "" : subMap.get("EHR_000135")); //药物使用总剂量
                    dataMap.put("medicationRouteCode", subMap.get("EHR_000136") == null ? "" : subMap.get("EHR_000136")); //用药途径代码
                    dataMap.put("medicationRouteValue", subMap.get("EHR_000136_VALUE") == null ? "" : subMap.get("EHR_000136_VALUE")); //用药途径值
                    String dataSetCode = String.valueOf(subMap.get("rowkey")).split("\\$")[1];
                    if ("HDSD00_84".equals(dataSetCode)) { //西药
                        dataMap.put("drugUseTotalDoseUnit", subMap.get("EHR_001249") == null ? "" : subMap.get("EHR_001249")); //药物使用总剂量单位
                    } else { //中药
                        dataMap.put("drugUseTotalDoseUnit", subMap.get("EHR_001250") == null ? "" : subMap.get("EHR_001250")); //药物使用总剂量单位
                    }
                    dataList.add(dataMap);
                }
            }
            if (dataList.size() > 0) {
                eventDate = event.get(ResourceCells.EVENT_DATE);
                break;
            }
        }
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        envelop.setCurrPage(page);
        envelop.setPageSize(size);
        envelop.setTotalPage(dataList.size() % size > 0 ? dataList.size() / size + 1 : dataList.size() / size);
        envelop.setTotalCount(dataList.size());
        List result = new ArrayList();
        for (int i = (page - 1) * size; i < page * size; i ++) {
            if (i > dataList.size() - 1) {
                break;
            }
            result.add(dataList.get(i));
        }
        envelop.setDetailModelList(result);
        envelop.setObj(eventDate);
        return envelop;
    }
    private Map<String, Integer> sortByValue(Map<String, Integer> sourceMap) {
        if (sourceMap == null || sourceMap.isEmpty()) {
            return sourceMap;
        }
        Map<String, Integer> sortedMap = new LinkedHashMap<>();
        List<Map.Entry<String, Integer>> entryList = new ArrayList<>(sourceMap.entrySet());
        Collections.sort(entryList, new MapValueComparator());
        Iterator<Map.Entry<String, Integer>> iterator = entryList.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Integer> tmpEntry = iterator.next();
            sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
        }
        return sortedMap;
    }
    class MapValueComparator implements Comparator<Map.Entry<String, Integer>> {
        @Override
        public int compare(Map.Entry<String, Integer> me1, Map.Entry<String, Integer> me2) {
            return - me1.getValue().compareTo(me2.getValue());
        }
    }
}

+ 131 - 0
src/main/java/com/yihu/ehr/profile/service/ProfileMotherhoodService.java

@ -0,0 +1,131 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.profile.feign.ResourceClient;
import com.yihu.ehr.util.rest.Envelop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by progr1mmer on 2018/5/14.
 */
@Service
public class ProfileMotherhoodService {
    @Autowired
    private ResourceClient resourceClient;
    public Map<String, Object> overview(String demographicId, String version) {
        String masterQ = "{\"q\":\"demographic_id:" + demographicId + "\"}";
        Envelop envelop = resourceClient.getMasterData(masterQ, 1, 500, null);
        List<Map<String, Object>> list = envelop.getDetailModelList();
        Map<String, Object> patientMap = new HashMap<>();
        if (list != null && list.size() > 0) {
            Map<String, Object> result = new HashMap<>();
            if (list.size() == 1) {
                result = list.get(0);
            } else {
                //合并数据
                for (Map<String, Object> obj : list) {
                    for (String key : obj.keySet()) {
                        if (!result.containsKey(key) && obj.get(key) != null) {
                            result.put(key, obj.get(key));
                        }
                    }
                }
            }
            //初潮年龄
            if (result.get("EHR_001495") != null) {
                patientMap.put("menarcheAge", result.get("EHR_001495"));
            } else {
                patientMap.put("menarcheAge", "");
            }
            //月经周期
            if (result.get("EHR_001497") != null) {
                int week = (int)result.get("EHR_001497") / 7;
                patientMap.put("menstrualCycle", week);
            } else {
                patientMap.put("menstrualCycle", "");
            }
            //月经持续时间
            if (result.get("EHR_001496") != null) {
                patientMap.put("menstrualDuration", result.get("EHR_001496"));
            } else if (result.get("EHR_001760") != null) {
                patientMap.put("menstrualDuration", result.get("EHR_001760"));
            } else {
                patientMap.put("menstrualDuration", "");
            }
            //痛经标志
            if (result.get("EHR_001501") != null) {
                patientMap.put("dysmenorrheaSign", result.get("EHR_001501"));
            } else {
                patientMap.put("dysmenorrheaSign", "");
            }
            //孕次
            if (result.get("EHR_001491") != null) {
                patientMap.put("pregnancy", result.get("EHR_001491"));
            } else {
                patientMap.put("pregnancy", "");
            }
            //产次
            if (result.get("EHR_001492") != null) {
                patientMap.put("productionTimes", result.get("EHR_001492"));
            } else {
                patientMap.put("productionTimes", "");
            }
            //阴道分娩次数
            if (result.get("EHR_001493") != null) {
                patientMap.put("vaginalDelivery", result.get("EHR_001493"));
            } else {
                patientMap.put("vaginalDelivery", "");
            }
            //剖宫产次数
            if (result.get("EHR_001494") != null) {
                patientMap.put("caesareanSection", result.get("EHR_001494"));
            } else {
                patientMap.put("caesareanSection", "");
            }
            //流产总次数
            if (result.get("EHR_001513") != null) {
                patientMap.put("totalNumberOfAbortions", result.get("EHR_001513"));
            } else {
                patientMap.put("totalNumberOfAbortions", "");
            }
            //人工流产次数
            if (result.get("EHR_001514") != null) {
                patientMap.put("artificialAbortionTimes", result.get("EHR_001514"));
            } else {
                patientMap.put("artificialAbortionTimes", "");
            }
            //死产例数
            if (result.get("EHR_001515") != null) {
                patientMap.put("numberOfStillbirths", result.get("EHR_001515"));
            } else {
                patientMap.put("numberOfStillbirths", "");
            }
            //死胎例数
            if (result.get("EHR_001516") != null) {
                patientMap.put("_numberOfStillbirths", result.get("EHR_001516"));
            } else {
                patientMap.put("_numberOfStillbirths", "");
            }
            //妊娠并发症史
            if (result.get("EHR_001512") != null) {
                patientMap.put("complication", result.get("EHR_001512"));
            } else {
                patientMap.put("complication", "");
            }
            //妇科手术史
            if (result.get("EHR_001511") != null) {
                patientMap.put("gynecologicalSurgeryHistory", result.get("EHR_001511"));
            } else {
                patientMap.put("gynecologicalSurgeryHistory", "");
            }
        }
        return patientMap;
    }
}

+ 54 - 0
src/main/java/com/yihu/ehr/profile/service/RedisService.java

@ -0,0 +1,54 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.redis.schema.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Redis管理
 * @author hzp add at 20170425
 */
@Service
public class RedisService {
    @Autowired
    private HealthProblemDictKeySchema healthProblemDictKeySchema;
    @Autowired
    private Icd10KeySchema icd10KeySchema;
    /**
     * 获取健康问题redis
     *
     * @return
     */
    public String getHealthProblem(String key) {
        return healthProblemDictKeySchema.get(key);
    }
    /**
     *获取ICD10对应健康问题 redis
     */
    public String getHpCodeByIcd10(String key) {
        return icd10KeySchema.getHpCode(key);
    }
    /**
     * 获取ICD10名称 redis
     */
    public String getIcd10Name(String key) {
        return icd10KeySchema.get(key);
    }
    /**
     * 获取ICD10慢病信息
     * @param key
     * @return
     */
    public String getChronicInfo(String key) {
        return icd10KeySchema.getChronicInfo(key);
    }
}

+ 88 - 0
src/main/java/com/yihu/ehr/profile/service/ResourcesTransformService.java

@ -0,0 +1,88 @@
package com.yihu.ehr.profile.service;
import com.yihu.ehr.query.BaseJpaService;
import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by hzp on 2016/4/13.
 */
@Service
public class ResourcesTransformService extends BaseJpaService {
    public Map<String, Object> stdMerge (Map<String, Object> resource, String dataset, String version) {
        Map<String, Object> returnRs =  new HashMap<>();
        String sql = "SELECT\n" +
                "\tram.metadata_id,\n" +
                "\tram.src_metadata_code\n" +
                "FROM\n" +
                "\trs_adapter_metadata ram\n" +
                "LEFT JOIN rs_adapter_scheme ras ON ram.scheme_id = ras.id\n" +
                "WHERE\n" +
                "\tras.adapter_version = :version\n" +
                "AND ram.src_dataset_code = :dataset";
        Session session = currentSession();
        Query query = session.createSQLQuery(sql);
        query.setString("version", version);
        query.setString("dataset", dataset);
        query.setFlushMode(FlushMode.COMMIT);
        List<Object []> metadataList = query.list();
        metadataList.forEach(item -> {
            String metadataId = (String) item[0];
            if (resource.containsKey(metadataId)) {
                returnRs.put(metadataId, resource.get(metadataId));
            }
            //同时返回字典值
            if (resource.containsKey(metadataId + "_VALUE")) {
                returnRs.put(metadataId + "_VALUE", resource.get(metadataId + "_VALUE"));
            }
        });
        returnRs.put("org_area", resource.get("org_area"));
        returnRs.put("org_name", resource.get("org_name"));
        returnRs.put("event_date", resource.get("event_date"));
        return returnRs;
    }
    public Map<String, Object> stdTransform (Map<String, Object> resource, String dataset, String version) {
        Map<String, Object> returnRs =  new HashMap<>();
        String sql = "SELECT\n" +
                "\tram.metadata_id,\n" +
                "\tram.src_metadata_code\n" +
                "FROM\n" +
                "\trs_adapter_metadata ram\n" +
                "LEFT JOIN rs_adapter_scheme ras ON ram.scheme_id = ras.id\n" +
                "WHERE\n" +
                "\tras.adapter_version = :version\n" +
                "AND ram.src_dataset_code = :dataset";
        Session session = currentSession();
        Query query = session.createSQLQuery(sql);
        query.setString("version", version);
        query.setString("dataset", dataset);
        query.setFlushMode(FlushMode.COMMIT);
        List<Object []> metadataList = query.list();
        metadataList.forEach(item -> {
            String metadataId = (String) item[0];
            String srcMetadataCode = (String) item[1];
            if (resource.containsKey(metadataId)) {
                returnRs.put(srcMetadataCode, resource.get(metadataId));
            }
            //同时返回字典值
            if (resource.containsKey(metadataId + "_VALUE")) {
                returnRs.put(srcMetadataCode + "_VALUE", resource.get(metadataId + "_VALUE"));
            }
        });
        returnRs.put("org_area", resource.get("org_area"));
        returnRs.put("org_name", resource.get("org_name"));
        returnRs.put("event_date", resource.get("event_date"));
        return returnRs;
    }
}

+ 87 - 0
src/main/java/com/yihu/ehr/profile/service/old/MedicationStatService.java

@ -0,0 +1,87 @@
package com.yihu.ehr.profile.service.old;
import com.yihu.ehr.profile.dao.ArchiveTemplateDao;
import com.yihu.ehr.profile.model.MedicationStat;
import com.yihu.ehr.profile.model.ArchiveTemplate;
import com.yihu.ehr.query.BaseJpaService;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
 * @author hzp
 * @created 2016.07.02 13:49
 * 用药信息服务(待完善)
 */
//@Transactional
//@Service
public class MedicationStatService extends BaseJpaService<ArchiveTemplate, ArchiveTemplateDao> {
    /**
     * 获取用药清单(直接查mysql)
     */
    public List<MedicationStat> getMedicationStat(String demographicId,List<String> drugList) throws  Exception{
        String sql = "select m.*,d.code,d.unit,d.specifications \n" +
                "from (select drug_id,drug_name,\n" +
                "  sum(case  \n" +
                "      when medication_time > :3MonthTime then drug_num\n" +
                "      ELSE 0\n" +
                "      end) as month3,\n" +
                "  sum(case  \n" +
                "    when medication_time > :6MonthTime then drug_num\n" +
                "    ELSE 0\n" +
                "    end) as month6,\n" +
                "  max(medication_time) as last_time \n" +
                "  from RS_Medication_List\n" +
                "  where demographic_id=:demographicId\n" +
                "  group by drug_id,drug_name) m\n" +
                "left join drug_dict d on d.id = m.drug_id";
        if(drugList!=null && drugList.size()>0)
        {
            String drugListString = "";
            for(String drugString :drugList)
            {
                if(drugListString.length()>0)
                {
                    drugListString += ",'"+drugString+"'";
                }
                else {
                    drugListString = "'"+drugString+"'";
                }
            }
            sql = "select m.*,d.code,d.unit,d.specifications \n" +
                    "from (select drug_id,drug_name,\n" +
                    "  sum(case  \n" +
                    "      when medication_time > :3MonthTime then drug_num\n" +
                    "      ELSE 0\n" +
                    "      end) as month3,\n" +
                    "  sum(case  \n" +
                    "    when medication_time > :6MonthTime then drug_num\n" +
                    "    ELSE 0\n" +
                    "    end) as month6,\n" +
                    "  max(medication_time) as last_time \n" +
                    "  from RS_Medication_List\n" +
                    "  where demographic_id=:demographicId\n" +
                    "  and drug_name in ("+drugListString+")\n" +
                    "  group by drug_id,drug_name) m\n" +
                    "left join drug_dict d on d.id = m.drug_id";
        }
        Session session = currentSession();
        SQLQuery query = session.createSQLQuery(sql);
        query.setParameter("demographicId", demographicId);
        query.setParameter("3MonthTime", "2016-04-02 17:26:16");
        query.setParameter("6MonthTime", "2016-01-02 17:26:16");
        query.addEntity(MedicationStat.class);
        List<MedicationStat> list = query.list();
        return list;
    }
}

+ 313 - 0
src/main/java/com/yihu/ehr/profile/service/old/PatientInfoDetailService.java

@ -0,0 +1,313 @@
package com.yihu.ehr.profile.service.old;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.model.specialdict.MDrugDict;
import com.yihu.ehr.profile.family.ResourceCells;
import com.yihu.ehr.profile.feign.*;
import com.yihu.ehr.profile.model.MedicationStat;
import com.yihu.ehr.profile.service.template.ArchiveTemplateService;
import com.yihu.ehr.profile.util.BasicConstant;
import com.yihu.ehr.util.log.LogService;
import com.yihu.ehr.util.rest.Envelop;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.*;
/**
 * @author hzp 2016-05-26
 */
public class PatientInfoDetailService {
    @Autowired
    private ResourceClient resource;
    //字典信息服务
    @Autowired
    private DictClient dictService;
    @Autowired
    private MedicationStatService medicationStatService;
    @Autowired
    private ArchiveTemplateService templateService;
    //CDA服务
    @Autowired
    private CDADocumentClient cdaService;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private TransformClient transform;
    @Autowired
    private ThridPrescriptionService thridPrescriptionService;
    /**
     * fastDfs服务器地址
     */
    @Value("${fast-dfs.public-server}")
    private String fastDfsUrl;
    @Value("${spring.application.id}")
    private String appId;
    /**
     * 【机构权限控制】通过身份证获取相关rowkeys
     */
    private String getProfileIds(String demographicId,String saasOrg) throws Exception {
        String re = "";
        //获取相关门诊住院记录
        Envelop main = resource.getResources(BasicConstant.patientEvent, "*", "*", "{\"q\":\"demographic_id:" + demographicId + "\"}", null, null);
        if (main.getDetailModelList() != null && main.getDetailModelList().size() > 0) {
            //主表rowkey条件
            StringBuilder rowkeys = new StringBuilder();
            for (Map<String, Object> map : (List<Map<String, Object>>) main.getDetailModelList()) {
                if (rowkeys.length() > 0) {
                    rowkeys.append(" OR ");
                }
                rowkeys.append(ResourceCells.PROFILE_ID + ":" + map.get("rowkey").toString());
            }
            re = "(" + rowkeys.toString() + ")";
        } else {
            re = ResourceCells.PROFILE_ID + ":(NOT *)";
        }
        return re;
    }
    /******************************* 用药信息 ***********************************************************/
    /*
     * 【机构权限控制】患者常用药(根据处方中次数)
     */
    public List<Map<String, Object>> getMedicationUsed(String demographicId, String hpCode) throws Exception {
        List<Map<String, Object>> re = new ArrayList<>();
        String rowkeys = getProfileIds(demographicId,null);
        String xyQueryParams = "{\"q\":\"" + rowkeys + "\"}";
        String zyQueryParams = "{\"q\":\"" + rowkeys + "\"}";
        if (hpCode != null && hpCode.length() > 0) {
            List<MDrugDict> drugList = dictService.getDrugDictListByHpCode(hpCode);
            if (drugList != null && drugList.size() > 0) {
                String drugQuery = "";
                for (MDrugDict drug : drugList) {
                    //drug.getType()是否需要药品类型判断***************
                    if (drugQuery.length() == 0) {
                        drugQuery = "{key}:" + drug.getName();
                    } else {
                        drugQuery += " OR {key}:" + drug.getName();
                    }
                }
                xyQueryParams = "{\"q\":\"" + rowkeys + " AND (" + drugQuery.replace("{key}", BasicConstant.xymc) + ")\"}";
                zyQueryParams = "{\"q\":\"" + rowkeys + " AND (" + drugQuery.replace("{key}", BasicConstant.zymc) + ")\"}";
            }
        }
        //西药统计
        Envelop resultWestern = resource.getResources(BasicConstant.medicationWesternStat, "*", "*", xyQueryParams.replace(" ", "+"), null, null);
        if (resultWestern.getDetailModelList() != null && resultWestern.getDetailModelList().size() > 0) {
            List<Map<String, Object>> list = resultWestern.getDetailModelList();
            for (Map<String, Object> map : list) {
                Map<String, Object> item = new HashMap<>();
                item.put("name", map.get(BasicConstant.xymc));
                item.put("count", map.get("$count"));
                re.add(item);
            }
        }
        //中药统计
        Envelop resultChinese = resource.getResources(BasicConstant.medicationChineseStat, "*", "*", zyQueryParams.replace(" ", "+"), null, null);
        if (resultChinese.getDetailModelList() != null && resultChinese.getDetailModelList().size() > 0) {
            List<Map<String, Object>> list = resultChinese.getDetailModelList();
            for (Map<String, Object> map : list) {
                Map<String, Object> item = new HashMap<>();
                item.put("name", map.get(BasicConstant.zymc));
                item.put("count", map.get("$count"));
                re.add(item);
            }
        }
        //自定义排序规则,进行排序
        Collections.sort(re, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Integer d1 = (Integer) o1.get("count");
                Integer d2 = (Integer) o2.get("count");
                return d1.compareTo(d2);
            }
        });
        return re;
    }
    /*
     * 患者用药清单(根据数量,近三个月/近六个月)
     */
    public List<MedicationStat> getMedicationStat(String demographicId, String hpCode) throws Exception {
        List<MedicationStat> re = new ArrayList<>();
        List<String> drugList = new ArrayList<>();
        if (hpCode != null && hpCode.length() > 0) {
            List<MDrugDict> drugDictList = dictService.getDrugDictListByHpCode(hpCode);
            if (drugDictList != null && drugDictList.size() > 0) {
                String drugQuery = "";
                for (MDrugDict drug : drugDictList) {
                    drugList.add(drug.getName());
                }
            } else {
                return re;
            }
        }
        re = medicationStatService.getMedicationStat(demographicId, drugList);
        return re;
    }
    /*
     * 处方细表记录
     * 1.西药处方;2.中药处方
     */
    public List<Map<String, Object>> getMedicationDetail(String prescriptionNo, String type) throws Exception {
        List<Map<String, Object>> re = new ArrayList<>();
        String queryParams = BasicConstant.cfbh + ":" + prescriptionNo;
        String resourceCode = BasicConstant.medicationWestern;
        if (type != null && type.equals("2")) //默认西药
        {
            resourceCode = BasicConstant.medicationChinese;
        }
        Envelop result = resource.getResources(resourceCode, "*", "*","{\"q\":\"" + queryParams + "\"}", null, null);
        re = result.getDetailModelList();
        return re;
    }
    /*
     * 【机构权限控制】处方主表记录
     */
    public List<Map<String, Object>> getMedicationMaster(String demographicId, String profileId, String prescriptionNo,String saasOrg) throws Exception {
        String queryParams = "";
        if (prescriptionNo != null && prescriptionNo.length() > 0) {
            queryParams = BasicConstant.cfbh + ":" + prescriptionNo;
        } else {
            if (profileId != null && profileId.length() > 0) {
                queryParams = ResourceCells.PROFILE_ID + ":" + profileId;
            } else {
                queryParams = getProfileIds(demographicId,saasOrg);
            }
        }
        queryParams = "{\"q\":\"" + queryParams + "\"}";
        //获取数据
        Envelop result = resource.getResources(BasicConstant.medicationMaster, "*","*", queryParams.replace(" ", "+"), null, null);
        return result.getDetailModelList();
    }
    /**
     * 【机构权限控制】患者处方(可分页)
     * 1.西药处方;2.中药处方
     */
    public Envelop getMedicationList(String type, String demographicId, String hpCode, String startTime, String endTime, Integer page, Integer size,String saasOrg) throws Exception {
        String q = "";
        String date = BasicConstant.xysj;
        String name = BasicConstant.xymc;
        String resourceCode = BasicConstant.medicationWestern;
        if (type != null && type.equals("2")) //默认查询西药
        {
            date = BasicConstant.zysj;
            name = BasicConstant.zymc;
            resourceCode = BasicConstant.medicationChinese;
        }
        //时间范围
        if (startTime != null && startTime.length() > 0 && endTime != null && endTime.length() > 0) {
            q = date + ":[" + startTime + " TO " + endTime + "]";
        } else {
            if (startTime != null && startTime.length() > 0) {
                q = date + ":[" + startTime + " TO *]";
            } else if (endTime != null && endTime.length() > 0) {
                q = date + ":[* TO " + endTime + "]";
            }
        }
        //健康问题
        if (hpCode != null && hpCode.length() > 0) {
            //健康问题->药品代码
            List<MDrugDict> drugList = dictService.getDrugDictListByHpCode(hpCode);
            String ypQuery = "";
            if (drugList != null && drugList.size() > 0) {
                //遍历药品列表
                for (MDrugDict drug : drugList) {
                    String dictCode = drug.getCode();
                    if (ypQuery.length() > 0) {
                        ypQuery += " OR " + name + ":" + dictCode;
                    } else {
                        ypQuery = name + ":" + dictCode;
                    }
                }
            }
            if (ypQuery.length() > 0) {
                if (q.length() > 0) {
                    q += " AND (" + ypQuery + ")";
                } else {
                    q = "(" + ypQuery + ")";
                }
            }
        }
        //获取门诊住院记录
        String rowkeys = "";
        if (demographicId != null && demographicId != "")
            rowkeys = getProfileIds(demographicId,saasOrg);
        if (!("profile_id:(NOT *)").equals(rowkeys) && rowkeys != "") {
            if (q.length() > 0) {
                q += " AND (" + rowkeys.toString() + ")";
            } else {
                q = "(" + rowkeys.toString() + ")";
            }
        } else if (("profile_id:(NOT *)").equals(rowkeys) && demographicId != null) {
            Envelop envelop = new Envelop();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("找不到此人相关记录");
            return envelop;
        }
        if (q == "")
            q = "*:*";
        String queryParams = "{\"q\":\"" + q + "\"}";
        return resource.getResources(resourceCode, appId, null,queryParams.replace(" ", "+"), page, size);
    }
    /*************************  分页查细表数据,简单公用方法 *************************************************/
    /**
     * 【机构权限控制】处方主表、处方细表、处方笺
     * 门诊诊断、门诊症状、门诊费用汇总、门诊费用明细
     * 住院诊断、住院症状、住院费用汇总、住院费用明细、住院临时医嘱、住院长期医嘱、住院死亡记录
     * 检查报告单、检查报告单图片
     * 检验报告单、检验报告单项目
     * 手术记录
     */
    public Envelop getProfileSub(String resourceCode, String demographicId, String profileId, String eventNo, Integer page, Integer size,String saasOrg) throws Exception {
        if (demographicId == null && profileId == null && eventNo == null) {
            throw new Exception("非法传参!");
        }
        String queryParams = "";
        if (profileId != null) {
            queryParams = "profile_id:" + profileId;
        } else {
            if (eventNo != null) {
                //获取相关门诊住院记录
                Envelop main = resource.getResources(BasicConstant.patientEvent, "*","*", "{\"q\":\"event_no:" + eventNo + "\"}", 1, 1);
                if (main.getDetailModelList() != null && main.getDetailModelList().size() > 0) {
                    profileId = ((Map<String, String>) main.getDetailModelList().get(0)).get("rowkey");
                    queryParams = "profile_id:" + profileId;
                } else {
                    throw new Exception("不存在该档案信息!(event_no:" + eventNo + ")");
                }
            } else {
                queryParams = getProfileIds(demographicId,saasOrg);
            }
        }
        return resource.getResources(resourceCode, "*", "*", "{\"q\":\"" + queryParams.replace(' ', '+') + "\"}", page, size);
    }
}

+ 68 - 0
src/main/java/com/yihu/ehr/profile/service/old/ProfileDataSetSerializer.java

@ -0,0 +1,68 @@
package com.yihu.ehr.profile.service.old;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.yihu.ehr.model.profile.MDataSet;
import com.yihu.ehr.model.profile.MRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.Map;
/**
 * @author Sand
 * @version 1.0
 * @created 2016.04.13 9:38
 */
//@Component
public class ProfileDataSetSerializer extends JsonSerializer<MDataSet> {
    @Autowired
    private ObjectMapper objectMapper;
    @PostConstruct
    public void init(){
        SimpleModule module = new SimpleModule();
        module.addSerializer(MDataSet.class, this);
        objectMapper.registerModule(module);
        objectMapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false);
        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        objectMapper.configure(SerializationFeature.WRITE_DATES_WITH_ZONE_ID, true);
    }
    @Override
    public void serialize(MDataSet dataSet, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        jgen.writeStartObject();
        jgen.writeStringField("code", dataSet.getCode());
        jgen.writeStringField("name", dataSet.getName());
        jgen.writeObjectFieldStart("records");
        Map<String, MRecord> records = dataSet.getRecords();
        for (String key : records.keySet()){
            MRecord record = records.get(key);
            if (record != null && record.getCells() != null){
                jgen.writeObjectFieldStart(key);
                for (String cell : record.getCells().keySet()){
                    jgen.writeStringField(cell, record.getCells().get(cell));
                }
                jgen.writeEndObject();
            } else {
                jgen.writeStringField(key, null);
            }
        }
        jgen.writeEndObject();
        jgen.writeEndObject();
    }
}

+ 73 - 0
src/main/java/com/yihu/ehr/profile/service/old/SanofiService.java

@ -0,0 +1,73 @@
package com.yihu.ehr.profile.service.old;
import com.yihu.ehr.profile.feign.DictClient;
import com.yihu.ehr.profile.feign.GeographyClient;
import com.yihu.ehr.profile.feign.OrganizationClient;
import com.yihu.ehr.profile.feign.ResourceClient;
import com.yihu.ehr.profile.util.BasicConstant;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import com.yihu.ehr.util.rest.Envelop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author hzp 2016-05-26
 */
//@Service
public class SanofiService {
    @Autowired
    private ResourceClient resourceClient; //资源服务
    @Autowired
    private OrganizationClient organization; //机构信息服务
    @Autowired
    private DictClient dictClient;
    @Autowired
    private GeographyClient addressClient;
    @Value("${spring.application.id}")
    String appId;
    /**
     * @获取患者档案基本信息
     */
    public List<Map<String, Object>> findByDemographic(String demographicId,
                                                       String name,
                                                       String telephone,
                                                       String gender,
                                                       Date birthday) throws Exception {
        //时间排序
        String query = "{";
        if (!StringUtils.isEmpty(demographicId)) {
            query += "\"q\":\"demographic_id:" + demographicId;
        }
        if (!StringUtils.isEmpty(name)) {
            query += "+AND+EHR_000004:" + name;
            if (!StringUtils.isEmpty(telephone)) {
                query += "+AND+EHR_000003:" + telephone;
            } else if (!StringUtils.isEmpty(gender) && birthday != null) {
                query += "+AND+EHR_000019:" + gender +"+AND+EHR_000007:"+DateTimeUtil.simpleDateTimeFormat(birthday);
            }
        }
        query += "\"}";
        Envelop result = resourceClient.getResources(BasicConstant.patientInfo, appId,null, query, null, null);
        return result.getDetailModelList();
    }
    // 获取数据集
    public List<Map<String, Object>> getDataSet(String core, String query) throws Exception {
        Envelop result = resourceClient.getResources(core, appId, null,query, null, null);
        return result.getDetailModelList();
    }
}

+ 277 - 0
src/main/java/com/yihu/ehr/profile/service/old/ThridPrescriptionService.java

@ -0,0 +1,277 @@
package com.yihu.ehr.profile.service.old;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.fastdfs.config.FastDFSConfig;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.profile.dao.ArchiveTemplateDao;
import com.yihu.ehr.profile.model.ArchiveTemplate;
import com.yihu.ehr.profile.service.template.ArchiveTemplateService;
import com.yihu.ehr.profile.service.ProfileCDAService;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import com.yihu.ehr.util.log.LogService;
import freemarker.template.Configuration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.fit.cssbox.demo.ImageRenderer;
import org.springframework.beans.factory.annotation.Autowired;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;
/**
 * Created by Administrator on 2016/6/14.
 */
//@Service
public class ThridPrescriptionService extends BaseJpaService<ArchiveTemplate, ArchiveTemplateDao> {
    @Autowired
    private FastDFSUtil fastDFSUtil;
    @Autowired
    private ArchiveTemplateService tempService;
    @Autowired
    private ProfileCDAService profileCDAService;
    private Map<String, String> usageMap;
    public ThridPrescriptionService() {
        usageMap = new HashMap<>();
        usageMap.put("bid", "每日两次");
        usageMap.put("biw", "每周两次");
        usageMap.put("Hs", "临睡前");
        usageMap.put("q12 h", "每12小时一次");
        usageMap.put("q1 h", "每1小时一次");
        usageMap.put("q3 h", "每3小时一次");
        usageMap.put("q6 h", "每6小时一次");
        usageMap.put("q8 h", "每8小时一次");
        usageMap.put("qd", "每日一次");
        usageMap.put("qid", "每日四次");
        usageMap.put("qod", "每隔天一次");
        usageMap.put("qw", "每周一次");
        usageMap.put("St", "马上");
    }
    /**
     * 把html转图片存fastdfs上并且返回fdfs的路径
     *
     * @param eventNo
     * @param orgCode
     * @return
     * @throws Exception
     */
    public String prescriptioToImage(String eventNo, String orgCode, String cdaType, String version, int width, int height) throws Exception {
        String filePath = "";
        //查找处方笺判断处方签书是否存在 如果不存在查找处方签主表数据,新增处方签细表,存在的话判断处方签是否有图片
        //InputStream in = new FileInputStream(new File("E:/1.png"));
        //FastDFSUtil fdfs= FastDFSConfig.fastDFSUtil();
        //ObjectNode jsonResult = fdfs.upload(in, "png", "");
        //查找处方主表得到主表信息判断中药或者西药
        //根据主表信息调用中药或者西药
        //判断之前图片是否有生成 有的话直接返回路径
        // filePath=CDAToImage(eventNo,orgCode,cdaType,version,width,height);
        Map<String, Object> params = new HashMap<String, Object>();//ProfileDataSetSerializer
        params.put("status", "200");
        List<Map<String, Object>> lists = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < 5; i++) {
            Map<String, Object> paramss = new HashMap<String, Object>();//ProfileDataSetSerializer
            paramss.put("type", "png");
            paramss.put("photo", "http://172.19.103.54/group1/M00/00/25/rBFuWldjdF-ABzPUAADQ9Y6xFp8579.png");
            lists.add(paramss);
        }
        params.put("photos", lists);
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(params);
    }
    /**
     * 转换图片并保存到fastdfs
     *
     * @param profileId  rowkey
     * @param orgCode    机构代码
     * @param cdaVersion cda版本号
     * @param cdaCode    cda代码
     * @param width      宽度
     * @param height     高度
     * @return
     * @throws Exception
     */
    public String transformImage(String profileId, String orgCode, String cdaVersion, String cdaCode, String type, int width, int height) throws Exception {
        //获取CDA模板信息
        List<ArchiveTemplate> temp = tempService.findByCdaVersionAndAndCdaCode(cdaVersion, cdaCode);
        if (temp.isEmpty()) {
            LogService.getLogger("prescription").error("CDA template not existed");
            throw new Exception("找不到对应CDA模板信息");
        }
        //获取CDA数据
        Map<String, Object> model = profileCDAService.getCDAData(profileId, true, null, temp.get(0).getCdaDocumentId());
        return CDAToImage(model, type, width, height);
    }
    /**
     * 图片生成
     *
     * @return
     * @throws Exception
     */
    private String CDAToImage(Map<String, Object> model, String type, int width, int height) throws Exception {
        try {
            //返回文件路径
            String filePath = "";
            //模板路径
            String fileString = ThridPrescriptionService.class.getResource("/").getPath();
            if (type.equals("1")) {
                //模板路径
                fileString += "/templates/westerntemplate.ftl";
            } else {
                //模板路径
                fileString += "/templates/chinesetemplate.ftl";
            }
            if (model.containsKey("data_sets") && ((Map<String, Object>) model.get("data_sets")).containsKey("HDSC01_09")) {
                List list = (List) ((Map<String, Object>) model.get("data_sets")).get("HDSC01_09");
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> HDSC01_09 = (Map<String, Object>) list.get(i);
                    if (HDSC01_09.containsKey("HDSD00_04_006") && !StringUtils.isBlank(HDSC01_09.get("HDSD00_04_006").toString())) {
                        HDSC01_09.put("HDSD00_04_006", HDSC01_09.get("HDSD00_04_006").toString().substring(0, 10));
                    }
                }
            }
            if (model.containsKey("data_sets") && ((Map<String, Object>) model.get("data_sets")).containsKey("HDSA00_01")) {
                List list = (List) ((Map<String, Object>) model.get("data_sets")).get("HDSA00_01");
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> HDSA00_01 = (Map<String, Object>) list.get(i);
                    if (HDSA00_01.containsKey("HDSA00_01_017") && !StringUtils.isBlank(HDSA00_01.get("HDSA00_01_017").toString())) {
                        Date current = new Date();
                        String year = HDSA00_01.get("HDSA00_01_017").toString().substring(6, 10);
                        String month = HDSA00_01.get("HDSA00_01_017").toString().substring(10, 12);
                        String day = HDSA00_01.get("HDSA00_01_017").toString().substring(12, 14);
                        Date birth = DateTimeUtil.simpleDateParse(year + "-" + month + "-" + day);
                        int age = current.getYear() - birth.getYear();
                        if (current.getMonth() < birth.getMonth()) {
                            age--;
                        }
                        HDSA00_01.put("HDSA00_01_012", age);
                    }
                }
            }
            if (model.containsKey("data_sets") && ((Map<String, Object>) model.get("data_sets")).containsKey("HDSC01_04")) {
                List list = (List) ((Map<String, Object>) model.get("data_sets")).get("HDSC01_04");
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> HDSC01_04 = (Map<String, Object>) list.get(i);
                    if (HDSC01_04.containsKey("HDSD00_04_026_VALUE") && !StringUtils.isBlank(HDSC01_04.get("HDSD00_04_026_VALUE").toString())) {
                        if (!StringUtils.isBlank(usageMap.get(HDSC01_04.get("HDSD00_04_026_VALUE")))) {
                            HDSC01_04.put("HDSD00_04_026_VALUE", usageMap.get(HDSC01_04.get("HDSD00_04_026_VALUE")));
                        }
                    }
                }
            }
            //把数据和模板结合生成html
            String html = fillTemplate(fileString, model);
            //网页转图片 并且保存到fastdfs
            filePath = htmlToImage(html, width, height);
            return filePath;
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }
    /**
     * html转图片
     *
     * @return
     * @throws Exception
     */
    public String htmlToImage(String html, Integer width, Integer height) throws Exception {
        try {
            String rootPath = ThridPrescriptionService.class.getResource("/").getPath();
            rootPath = new File(new File(rootPath).getParent()).getParent();
            //把模板保存成文件
            String fileTempName = UUID.randomUUID().toString();
            String url = rootPath + fileTempName + ".html";
            File fileTmep = new File(url);//临时文件保存模板文件
            fileTmep.createNewFile();
            FileUtils.writeStringToFile(fileTmep, html);
            //随机生成图片名字ID
            String fileName = UUID.randomUUID().toString();
            File file = new File(rootPath + fileName + ".png");//临时文件保存图片
            file.createNewFile();
            FileUtils.writeStringToFile(file, html);
            ImageRenderer render = new ImageRenderer();
            FileOutputStream out = new FileOutputStream(file);
            if (width != 0 || height != 0) {
                Dimension d = new Dimension();
                d.setSize(width, height);//设置图片大小
                render.setWindowSize(d, false);//false 超出图片设置的大小是自适应
            }
            render.renderURL("file:///" + url, out, ImageRenderer.Type.PNG);
            //保存到fastdfs
            InputStream in = new FileInputStream(file);
            ObjectNode jsonResult = fastDFSUtil.upload(in, "png", "");
            String filePath = jsonResult.get("fid").textValue();
            out.close();
            in.close();
            //删除图片文件
            file.delete();
            //删除临时html文件
            fileTmep.delete();
            return filePath;
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }
    /**
     * 填充模板
     *
     * @param fileString
     * @param model
     * @return
     * @throws Exception
     */
    private String fillTemplate(String fileString, Object model) throws Exception {
        try {
            //模板文件
            File tempFile = new File(fileString);
            //模板加载配置
            Configuration cfg = new Configuration();
            //模板路径配置
            cfg.setDirectoryForTemplateLoading(new File(tempFile.getParent()));
            //加载模板文件
            freemarker.template.Template temp = cfg.getTemplate(tempFile.getName());
            //模板解析输出流
            Writer out = new StringWriter();
            //模板解析
            temp.process(model, out);
            //返回解析后HTML
            return out.toString();
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }
}

+ 69 - 0
src/main/java/com/yihu/ehr/profile/service/template/ArchiveTemplateService.java

@ -0,0 +1,69 @@
package com.yihu.ehr.profile.service.template;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.profile.dao.ArchiveTemplateDao;
import com.yihu.ehr.profile.feign.CDADocumentClient;
import com.yihu.ehr.profile.model.ArchiveTemplate;
import com.yihu.ehr.profile.model.MCDADocument;
import com.yihu.ehr.query.BaseJpaService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @author Sand
 * @version 1.0
 * @created 16-7月-2015 20:57:06
 */
@Service
@Transactional
public class ArchiveTemplateService extends BaseJpaService<ArchiveTemplate, ArchiveTemplateDao> {
    @Autowired
    private ArchiveTemplateDao templateDao;
    @Autowired
    private FastDFSUtil fastDFSUtil;
    public ArchiveTemplate getTemplate(Integer id) {
        ArchiveTemplate template = templateDao.findOne(id);
        return template;
    }
    public boolean isExistName(String version, String title) {
        return templateDao.findByTitleAndCdaVersion(version, title).size() > 0;
    }
    public List<ArchiveTemplate> findByCdaVersionAndAndCdaCode(String version, String code) {
        return templateDao.findByCdaVersionAndAndCdaCode(version, code);
    }
    public List<ArchiveTemplate> findByCdaDocumentId(List<String> docIds) {
        return templateDao.findByCdaDocumentId(docIds);
    }
    public void delete (Integer id) throws Exception {
        ArchiveTemplate archiveTemplate = retrieve(id);
        if (archiveTemplate != null) {
            if (StringUtils.isNotEmpty(archiveTemplate.getPcUrl())) {
                fastDFSUtil.delete(archiveTemplate.getPcUrl().split(ArchiveTemplate.UrlSeparator)[0], archiveTemplate.getPcUrl().split(ArchiveTemplate.UrlSeparator)[1]);
            }
            if (StringUtils.isNotEmpty(archiveTemplate.getMobileUrl())) {
                fastDFSUtil.delete(archiveTemplate.getMobileUrl().split(ArchiveTemplate.UrlSeparator)[0], archiveTemplate.getMobileUrl().split(ArchiveTemplate.UrlSeparator)[1]);
            }
            templateDao.delete(id);
        }
    }
}

+ 33 - 0
src/main/java/com/yihu/ehr/profile/util/BasicConstant.java

@ -0,0 +1,33 @@
package com.yihu.ehr.profile.util;
public class BasicConstant {
    /********** 资源代码 ******************/
    public static String patientInfo = "RS_PATIENT_INFO";//患者基本信息资源
    public static String patientEvent = "RS_PATIENT_EVENT";//患者门诊/住院事件资源
    public static String medicationMaster = "RS_MEDICATION_MASTER";//患者处方主表
    public static String medicationPrescription = "RS_MEDICATION_PRESCRIPTION";//处方笺
    public static String medicationChinese = "RS_MEDICATION_CHINESE";//患者用中药药历史记录资源
    public static String medicationWestern = "RS_MEDICATION_WESTERN";//患者用西药药历史记录资源
    public static String medicationWesternStat = "RS_MEDICATION_WESTERN_STAT";//患者西药用药统计资源
    public static String medicationChineseStat = "RS_MEDICATION_CHINESE_STAT";//患者中药用药统计资源
    public static String hospitalizedOrdersTemporary = "RS_HOSPITALIZED_ORDERS_TEMPORARY";	//住院临时医嘱
    public static String hospitalizedOrdersLongtime = "RS_HOSPITALIZED_ORDERS_LONGTIME";	//住院长期医嘱
    public static String laboratoryProject = "RS_LABORATORY_PROJECT";	//检验报告项目
    public static String cfbh = "EHR_000086";//处方编号
    public static String xysj = "EHR_000090";//西药处方时间
    public static String xymc = "EHR_000100";//西药名称
    public static String zysj = "EHR_000120";//中药处方时间
    public static String zymc = "EHR_000131";//中药名称
    //处方签模板标识
    public static String xycd = "HSDC01.04"; //西药CDA_CODE
    public static String zycd = "HSDC01.05"; //中药CDA_CODE
}

+ 48 - 0
src/main/java/com/yihu/ehr/profile/util/NumberValidationUtils.java

@ -0,0 +1,48 @@
package com.yihu.ehr.profile.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Created by progr1mmer on 2018/8/15.
 */
public class NumberValidationUtils {
    private static boolean isMatch(String regex, String orginal){
        if (orginal == null || orginal.trim().equals("")) {
            return false;
        }
        Pattern pattern = Pattern.compile(regex);
        Matcher isNum = pattern.matcher(orginal);
        return isNum.matches();
    }
    public static boolean isPositiveInteger(String orginal) {
        return isMatch("^\\+{0,1}[1-9]\\d*", orginal);
    }
    public static boolean isNegativeInteger(String orginal) {
        return isMatch("^-[1-9]\\d*", orginal);
    }
    public static boolean isWholeNumber(String orginal) {
        return isMatch("[+-]{0,1}0", orginal) || isPositiveInteger(orginal) || isNegativeInteger(orginal);
    }
    public static boolean isPositiveDecimal(String orginal){
        return isMatch("\\+{0,1}[0]\\.[1-9]*|\\+{0,1}[1-9]\\d*\\.\\d*", orginal);
    }
    public static boolean isNegativeDecimal(String orginal){
        return isMatch("^-[0]\\.[1-9]*|^-[1-9]\\d*\\.\\d*", orginal);
    }
    public static boolean isDecimal(String orginal){
        return isMatch("[-+]{0,1}\\d+\\.\\d*|[-+]{0,1}\\d*\\.\\d+", orginal);
    }
    public static boolean isRealNumber(String orginal){
        return isWholeNumber(orginal) || isDecimal(orginal);
    }
}

+ 70 - 0
src/main/java/com/yihu/ehr/profile/util/SimpleSolrQueryUtil.java

@ -0,0 +1,70 @@
package com.yihu.ehr.profile.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.util.StringUtils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
/**
 * Created by progr1mmer on 2018/3/26.
 */
public class SimpleSolrQueryUtil {
    private static ObjectMapper objectMapper = new ObjectMapper();
    /**
     *
     * @param filter 要追加的参数 org_code=49229004X 多个条件用;分隔
     * @param date 时间类型 {"start":"2018-01-01T00:00:00Z","end":"2018-02-01T00:00:00Z","month":"2018-03"}
     * @param q 基础参数 {"q":"*:*"}
     * @return
     * @throws Exception
     */
    public static String getQuery(String filter, String date, String q) throws Exception {
        Map<String, String> qMap = objectMapper.readValue(q, Map.class);
        String param = qMap.get("q");
        if (!StringUtils.isEmpty(filter)) {
            String [] conditions = filter.split(";");
            for (String condition : conditions) {
                if (condition.split("=").length == 2) {
                    String key = condition.split("=")[0];
                    String value = condition.split("=")[1];
                    param += " AND " + key + ":" + value;
                }
                if (condition.split("\\?").length == 2) {
                    String key = condition.split("\\?")[0];
                    String value = condition.split("\\?")[1];
                    param += " AND " + key + ":*" + value + "*";
                }
                continue;
            }
        }
        if (!StringUtils.isEmpty(date)) {
            Map<String, String> dateMap = objectMapper.readValue(date, Map.class);
            if (!StringUtils.isEmpty(dateMap.get("start"))) {
                param += " AND event_date:[" + dateMap.get("start") + " TO *]";
            }
            if (!StringUtils.isEmpty(dateMap.get("end"))) {
                param += " AND event_date:[* TO " + dateMap.get("end") + "]";
            }
            if (!StringUtils.isEmpty(dateMap.get("month"))) {
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
                Date date1 = dateFormat.parse(dateMap.get("month"));
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date1);
                String start = dateMap.get("month") + "-01T00:00:00Z";
                int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                String end = dateMap.get("month") + "-" + maxDay + "T00:00:00Z";
                param += " AND event_date:[" + start + " TO " + end + "]";
            }
        }
        String sort = "{\"event_date\":\"desc\"}";
        qMap.put("sort", sort);
        qMap.put("q", param);
        return objectMapper.writeValueAsString(qMap);
    }
}

+ 62 - 0
src/main/resources/application.yml

@ -0,0 +1,62 @@
server:
  port: ${svr-health-profile.server.port}
info:
  app:
    name: SVR-HEALTH-PROFILE
    description: EHR Platform Microservice.
    version: 1.0.0
spring:
  # REDIS
  redis:
    database: 0 # Database index used by the connection factory.
    timeout: 0 # Connection timeout in milliseconds.
    #sentinel:
    #  master: # Name of Redis server.
    #  nodes: # Comma-separated list of host:port pairs.
    pool:
      max-active: 8 # Max number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
      max-idle: 8 # Max number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
      max-wait: -1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
      min-idle: 1 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    max-active: 20
    max-idle: 8
    min-idle: 8
    validation-query: SELECT 1
    test-on-borrow: true
  application:
    id: JKZL
fast-dfs:
  connect-timeout: 10
  network-timeout: 60
  charset: ISO8859-1
  pool:
    init-size: 5
    max-size: 20
    wait-time: 500
  http:
    tracker-http-port: 80
    anti-steal-token: no
    secret-key: FastDFS1234567890
eip:
  tenant: jkzl
---
spring:
  profiles: dev
  datasource:
    url: jdbc:mysql://172.19.103.50:3306/healtharchive?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    username: chenweishan
    password: chenweishan
  redis:
    host: 172.19.103.47
    port: 6379
    password: redis!@456
fast-dfs:
  tracker-server: 172.19.103.13:22122
  public-server: http://172.19.103.52:80

+ 29 - 0
src/main/resources/banner.txt

@ -0,0 +1,29 @@
                                   _oo8oo_
                                  o8888888o
                                  88" . "88
                                  (| -_- |)
                                  0\  =  /0
                                ___/'==='\___
                              .' \\|     |// '.
                             / \\|||  :  |||// \
                            / _||||| -:- |||||_ \
                           |   | \\\  -  /// |   |
                           | \_|  ''\---/''  |_/ |
                           \  .-\__  '-'  __/-.  /
                         ___'. .'  /--.--\  '. .'___
                      ."" '<  '.___\_<|>_/___.'  >' "".
                     | | :  `- \`.:`\ _ /`:.`/ -`  : | |
                     \  \ `-.   \_ __\ /__ _/   .-` /  /
                 =====`-.____`.___ \_____/ ___.`____.-`=====
                                   `=---=`
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      佛祖保佑     永不宕机     永无Bug
 __   _      ___       _     ____   __    _    _____  _         ___   ___   ___   ____  _   _     ____
( (` \ \  / | |_)     | |_| | |_   / /\  | |    | |  | |_|     | |_) | |_) / / \ | |_  | | | |   | |_
_)_)  \_\/  |_| \     |_| | |_|__ /_/--\ |_|__  |_|  |_| |     |_|   |_| \ \_\_/ |_|   |_| |_|__ |_|__

+ 24 - 0
src/main/resources/bootstrap.yml

@ -0,0 +1,24 @@
spring:
  application:
    name: svr-health-profile
  cloud:
    config:
      username: user
      password: configuration
---
spring:
  profiles: dev
  cloud:
    config:
      uri: ${spring.config.uri:http://172.19.103.73:1221}
      label: ${spring.config.label:dev}
---
spring:
  profiles: prod
  cloud:
    config:
      uri: ${spring.config.uri}
      label: ${spring.config.label}

+ 153 - 0
src/main/resources/templates/chinesetemplate.ftl

@ -0,0 +1,153 @@
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    body{
	  width:800px;
	  margin:auto auto;
	  font-size:12px;
	  font-family:宋体;
    }
    .title{
	  text-align:center;
	  font-size:20px;
	  margin-top:20px;
	}
	.top-table,.bottom-table{
	  width:760px;
	  margin:20px;
	  table-layout:fixed;
	}
	.row{
	    height:33px;
		line-height: 33px;
	}
	.field{
	  width:33.33%;
	  white-space:nowrap;
	}
	.field-value{
	  display:inline-block;
      border-bottom:1px solid #232323;
	  height:18px;
	  line-height:18px;
	  margin-left:5px;
	  /*vertical-align:-5px;*/
      padding:0px;
	  overflow:hidden;
	}
	.middle-div{
	  border-top:3px solid #232323;
	  border-bottom:3px solid #232323;
	  min-height:400px;
	}
	.icon{
	  margin-left:70px;
	  margin-top:10px;
	  font-size:20px;
	  font-family:宋体;
	  font-weight:bold;
	}
	.list-table{
	  margin-left:90px;
	  margin-top:20px;
	  margin-bottom:10px;
	  width:620px;
	  table-layout:fixed;
	  border-collapse: collapse;
	}
	.list-tr{
	  height:28px;
	  line-height:28px;
	}
	.list-td{
	  white-space:nowrap;
	  overflow:hidden;
	  text-align:left;
	  padding:0px 20px 0px 10px;
		border-bottom:0px;
        border-top:0px;
	}
	.dashed-border{
	  border-right:1px dashed #232323;
	}
	.bottom-list-table{
	  margin-left:120px;
	  margin-top:20px;
	  margin-bottom:10px;
	  width:590px;
	  table-layout:fixed;
	}
  </style>
 </head>
 <body>
   <div class="title">处方笺</div>
   <div class="top-div">
     <table class="top-table">
	   <tr class="row">
	     <td class="field">门诊/住院号:<span class="field-value" style="width:167px">&nbsp;${(event_no)!}</span></td>
		 <td class="field">科室:<span class="field-value" style="width:208px">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_005)!}</span></td>
		 <td class="field">开方时间:<span class="field-value" style="width:190px">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_006)!}</span></td>
	   </tr>
	   <tr class="row">
	     <td class="field">姓名:<span class="field-value" style="width:207px">&nbsp;${(data_sets.HDSA00_01[0].HDSD00_01_002)!}</span></td>
		 <td class="field">性别:<span class="field-value" style="width:208px">&nbsp;${(data_sets.HDSA00_01[0].HDSA00_01_011_VALUE)!}</span></td>
		 <td class="field">年龄:<span class="field-value" style="width:214px">&nbsp;${(data_sets.HDSA00_01[0].HDSA00_01_012)!}</span></td>
	   </tr>
	   <tr class="row">
	     <td class="field">就诊类型:<span class="field-value" style="width:183px">&nbsp;初诊</span></td>
		 <td class="field" style="width:66.66%" colspan="2">地址/电话:<span class="field-value" style="width:439px">&nbsp;${(data_sets.HDSA00_01[0].JDSA00_01_000)!}/${(data_sets.HDSA00_01[0].HDSD00_01_008)!}</span></td>
	   </tr>
	   <tr class="row">
	     <td class="field" style="width:100%" colspan="3">临床诊断:<span class="field-value" style="width:696px">&nbsp;${(data_sets.HDSC01_03[0].HDSD00_01_549)!}</span></td>
	   </tr>
	 </table>
   </div>
   <div class="middle-div">
     <div class="icon-div"><div class="icon">RP.</div></div>
     <table class="list-table">
	 <#list data_sets.HDSC01_08 as item>
	 <#if item_index%3 == 0>
	   <tr class="list-tr">
	 </#if>
	     <td class="list-td" style="width:100px;">${(item.HDSD00_04_023)!}</td>
	 <#if (item_index+1)%3 == 0>
         <td class="list-td" style="width:50px;">${(item.HDSD00_04_024)!}${(item.HDSD00_04_025)!}</td>
	 <#else>
         <td class="list-td dashed-border" style="width:50px;">${(item.HDSD00_04_024)!}${(item.HDSD00_04_025)!}</td>
	 </#if>
	 <#if (item_index+1)%3== 0>
	 </tr>
	 </#if>
	 </#list>
     </table>
	 <table class="bottom-list-table" style="margin-top:40px;">
		 <#if data_sets.HDSC01_08?? && data_sets.HDSC01_08[0]??>
		   <tr class="list-tr">
			 <td class="list-td">${(data_sets.HDSC01_08[0].HDSD00_04_028)!}${(data_sets.HDSC01_08[0].JDSD00_83_001)!}<td>
			 <td class="list-td">每日${(data_sets.HDSC01_08[0].HDSD00_04_032)!}剂</td>
			 <td class="list-td">${(data_sets.HDSC01_08[0].HDSD00_04_033)!}</td>
			 <td class="list-td">${(data_sets.HDSC01_08[0].HDSD00_04_034)!}</td>
		   </tr>
		 </#if>
	 </table>
   </div>
   <div class="bottom-div">
     <table class="bottom-table">
	   <tr class="row">
	     <td style="width:100%">
		   <div style="float:left;white-space: nowrap">医师签名:<span class="field-value" style="width:180px;">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_007)!}</span></div>
		   <div style="float:right;white-space: nowrap">审核调配药师:<span class="field-value" style="width:200px;">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_009)!}</span></div>
		 </td>
	   </tr>
	   <tr class="row">
	     <td style="width:100%">
		   <div style="float:right;white-space: nowrap">复核发药药师:<span class="field-value" style="width:200px;">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_010)!}</span></div>
		 </td>
	   </tr>
	 </table>
   </div>
 </body>
</html>

+ 126 - 0
src/main/resources/templates/westerntemplate.ftl

@ -0,0 +1,126 @@
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    body{
	  width:800px;
	  margin:auto auto;
	  font-size:12px;
	  font-family:宋体;
    }
    .title{
	  text-align:center;
	  font-size:20px;
	  margin-top:20px;
	}
	.top-table,.bottom-table{
	  width:760px;
	  margin:20px;
	  table-layout:fixed;
	}
	.row{
	    height:33px;
		line-height: 33px;
	}
	.field{
	  width:33.33%;
	  white-space:nowrap;
	}
	.field-value{
	  display:inline-block;
      border-bottom:1px solid #232323;
	  height:18px;
	  line-height:18px;
	  margin-left:5px;
	  /*vertical-align:-5px;*/
      padding:0px;
	  overflow:hidden;
	}
	.middle-div{
	  border-top:3px solid #232323;
	  border-bottom:3px solid #232323;
	  min-height:400px;
	}
	.icon{
	  margin-left:50px;
	  margin-top:10px;
	  font-size:20px;
	  font-family:宋体;
	  font-weight:bold;
	}
	.list-table{
	  margin-left:65px;
	  margin-top:20px;
	  margin-bottom:10px;
	  width:620px;
	  table-layout:fixed;
	}
	.list-tr{
	  height:28px;
	  line-height:28px;
	}
	.list-td{
	  white-space:nowrap;
	  overflow:hidden;
	  text-align:left;
	  padding-right:10px;
	}
  </style>
 </head>
 <body>
   <div class="title">处方笺</div>
   <div class="top-div">
     <table class="top-table">
	   <tr class="row">
	     <td class="field">门诊/住院号:<span class="field-value" style="width:167px">&nbsp;${(event_no)!}</span></td>
		 <td class="field">科室:<span class="field-value" style="width:208px">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_005)!}</span></td>
		 <td class="field">开方时间:<span class="field-value" style="width:190px">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_006)!}</span></td>
	   </tr>
	   <tr class="row">
	     <td class="field">姓名:<span class="field-value" style="width:207px">&nbsp;${(data_sets.HDSA00_01[0].HDSD00_01_002)!}</span></td>
		 <td class="field">性别:<span class="field-value" style="width:208px">&nbsp;${(data_sets.HDSA00_01[0].HDSA00_01_011_VALUE)!}</span></td>
		 <td class="field">年龄:<span class="field-value" style="width:214px">&nbsp;${(data_sets.HDSA00_01[0].HDSA00_01_012)!}</span></td>
	   </tr>
	   <tr class="row">
	     <td class="field">就诊类型:<span class="field-value" style="width:183px">&nbsp;初诊</span></td>
		 <td class="field" style="width:66.66%" colspan="2">地址/电话:<span class="field-value" style="width:439px">&nbsp;${(data_sets.HDSA00_01[0].JDSA00_01_000)!}/${(data_sets.HDSA00_01[0].HDSD00_01_008)!}</span></td>
	   </tr>
	   <tr class="row">
	     <td class="field" style="width:100%" colspan="3">临床诊断:<span class="field-value" style="width:696px">&nbsp;${(data_sets.HDSC01_03[0].HDSD00_01_549)!}</span></td>
	   </tr>
	 </table>
   </div>
   <div class="middle-div">
     <div class="icon-div"><div class="icon">RP.</div></div>
     <table class="list-table">
		 <#list data_sets.HDSC01_04 as item>
		   <tr class="list-tr">
			 <td class="list-td" style="width:210px;">${item_index+1}、${(item.HDSD00_04_023)!}</td>
			 <td class="list-td" style="width:100px;">${(item.HDSD00_04_021)!}</td>
			 <td class="list-td" style="width:50px;">${(item.HDSD00_04_028)!}${(item.JDSD00_84_001)!}</td>
			 <td class="list-td" style="width:100px;">${(item.HDSD00_04_027_VALUE)!}</td>
			 <td class="list-td" style="width:70px;">每次${(item.HDSD00_04_024)!}${(item.HDSD00_04_025)!}</td>
			 <td class="list-td" style="width:70px;">${(item.HDSD00_04_026_VALUE)!}</td>
		   </tr>
		 </#list>
     </table>
   </div>
   <div class="bottom-div">
     <table class="bottom-table">
	   <tr class="row">
	     <td style="width:100%">
		   <div style="float:left;;white-space: nowrap">医师签名:<span class="field-value" style="width:180px;">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_007)!}</span></div>
		   <div style="float:right;;white-space: nowrap">审核调配药师:<span class="field-value" style="width:200px;">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_009)!}</span></div>
		 </td>
	   </tr>
	   <tr class="row">
	     <td style="width:100%">
		   <div style="float:right;;white-space: nowrap">复核发药药师:<span class="field-value" style="width:200px;">&nbsp;${(data_sets.HDSC01_09[0].HDSD00_04_010)!}</span></div>
		 </td>
	   </tr>
	 </table>
   </div>
 </body>
</html>

+ 24 - 0
src/test/java/com/yihu/ehr/DateTest.java

@ -0,0 +1,24 @@
package com.yihu.ehr;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * Created by progr1mmer on 2018/3/26.
 */
public class DateTest {
    public static void main (String [] args) throws Exception {
        String s = "wewe;ewew";
        System.out.println(s.split(";").length);
        String dateStr = "2018-02";
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        Date date = dateFormat.parse(dateStr);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    }
}

+ 53 - 0
src/test/java/com/yihu/ehr/MapSort.java

@ -0,0 +1,53 @@
package com.yihu.ehr;
import org.junit.Test;
import java.util.*;
/**
 * Created by progr1mmer on 2018/3/16.
 */
public class MapSort {
    @Test
    public void test() {
        Map<String, Integer> dataMap = new HashMap<String, Integer>();
        dataMap.put("name1", 5);
        dataMap.put("name2", 4);
        dataMap.put("name4", 2);
        dataMap.put("name5", 6);
        dataMap.put("name6", 1);
        Map<String, Integer> resultMap = sortByValue(dataMap);
        resultMap.forEach((k, v) -> System.out.println("key:" + k + "; " + "value:" + v));
    }
    private Map<String, Integer> sortByValue(Map<String, Integer> sourceMap) {
        if (sourceMap == null || sourceMap.isEmpty()) {
            return null;
        }
        Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
        List<Map.Entry<String, Integer>> entryList = new ArrayList<>(sourceMap.entrySet());
        Collections.sort(entryList, new MapValueComparator());
        Iterator<Map.Entry<String, Integer>> iterator = entryList.iterator();
        Map.Entry<String, Integer> tmpEntry = null;
        while (iterator.hasNext()) {
            tmpEntry = iterator.next();
            sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
        }
        return sortedMap;
    }
    class MapValueComparator implements Comparator<Map.Entry<String, Integer>> {
        @Override
        public int compare(Map.Entry<String, Integer> me1, Map.Entry<String, Integer> me2) {
            return - me1.getValue().compareTo(me2.getValue());
        }
    }
}