Browse Source

精麻处方

zengfanwei 1 week ago
parent
commit
9fd84c2e57
1 changed files with 220 additions and 77 deletions
  1. 220 77
      src/components/print-poisonous-hemp/PrintPoisonousHempTemplate.vue

+ 220 - 77
src/components/print-poisonous-hemp/PrintPoisonousHempTemplate.vue

@@ -8,10 +8,8 @@ import { useVuePrint } from "@/utils/cy-use/useVuePrint";
 import dayjs from "dayjs";
 import { stringIsBlank } from "@/utils/blank-utils";
 import { xcMessage } from "@/utils/xiaochan-element-plus";
-import { getDate } from "@/utils/date"
-import {
-  selectOrderFrequency,
-} from "@/api/orderZdMaintain";
+import { getDate } from "@/utils/date";
+import { selectOrderFrequency } from "@/api/orderZdMaintain";
 
 const props = defineProps<{
   data: PrintOrderVo;
@@ -77,7 +75,7 @@ const [PrintTemplate, printFunc] = useVuePrint({
 });
 
 const getTitle = (item: DrugData) => {
-  console.log(item, 'item')
+  console.log(item, "item");
   let title = "";
   if (item.drugFlag === "1") {
     title = "毒";
@@ -88,8 +86,8 @@ const getTitle = (item: DrugData) => {
   } else if (item.drugFlag === "4") {
     title = "精二";
   }
-  return title
-}
+  return title;
+};
 
 function printPrescription(red: boolean): any[] {
   const tmp = [];
@@ -125,34 +123,102 @@ function printPrescription(red: boolean): any[] {
   return tmp;
 }
 
-let orderFrequency = []
-
-const getFrequencyCount = (frequCode) => {
-  console.log(frequCode, 'frequCode')
-  let count = 0
-  let target = orderFrequency.find(item=> item.code === frequCode)
-  let nextDayKey = ['day030','day100','day130','day200',
-  'day230','day300','day330','day400','day430','day500','day530','day2400',]
-  // 遍历对象的所有键
+let orderFrequency = [];
+const getFrequencyCount = frequCode => {
+  console.log(frequCode, "frequCode");
+  if (!frequCode) return;
+  let count = 0;
+  let target = orderFrequency.find(item => item.code === frequCode);
+  console.log(target, "target");
+  let tempKey = ["ONCE", "ONCE1", "ONCE2"];
+  if (tempKey.includes(target.code)) return 1;
   Object.keys(target).forEach(key => {
     // 判断键是否以'day'开头(区分大小写)
-    if (key.startsWith('day')) {
-      if(target[key]) console.log(target[key], 'key')
-      if(!nextDayKey.includes(key) && target[key] == 1) count++
+    if (key.startsWith("day")) {
+      if (target[key]) console.log(target[key], "key");
+      if (target[key] == 1) count++;
     }
   });
-  console.log(count, 'count')
+  // let nextDayKey = [
+  //   "day030",
+  //   "day100",
+  //   "day130",
+  //   "day200",
+  //   "day230",
+  //   "day300",
+  //   "day330",
+  //   "day400",
+  //   "day430",
+  //   "day500",
+  //   "day530",
+  //   "day2400",
+  // ];
+  // // 遍历对象的所有键
+  // Object.keys(target).forEach(key => {
+  //   // 判断键是否以'day'开头(区分大小写)
+  //   if (key.startsWith("day")) {
+  //     if (target[key]) console.log(target[key], "key");
+  //     if (!nextDayKey.includes(key) && target[key] == 1) count++;
+  //   }
+  // });
+  console.log(count, "count");
   // console.log(target, 'target')
-  return count
-}
+  return count;
+};
+
+const calculateAge = birthDateStr => {
+  // birthDateStr = "2025-04-19";
+  // 解析出生日期
+  const birthDate = new Date(birthDateStr);
+  const today = new Date();
+
+  // 检查日期是否有效
+  if (isNaN(birthDate.getTime())) {
+    return "无效的日期格式";
+  }
+
+  // 计算年份差
+  let age = today.getFullYear() - birthDate.getFullYear();
+  const monthDiff = today.getMonth() - birthDate.getMonth();
+
+  // 调整年龄:如果还没过生日,年龄减1
+  if (
+    monthDiff < 0 ||
+    (monthDiff === 0 && today.getDate() < birthDate.getDate())
+  ) {
+    age--;
+  }
+
+  // 如果年龄小于1,计算月份
+  if (age <= 0) {
+    let months = monthDiff;
+    if (today.getDate() < birthDate.getDate()) {
+      months--;
+    }
+
+    // 确保月份为正数
+    if (months < 0) {
+      months += 12;
+    }
+
+    // 处理出生当月的情况
+    if (months === 0) {
+      return "不到1个月";
+    }
+
+    return `${months}个月`;
+  }
+
+  return `${age}岁`;
+};
 
 onMounted(() => {
   state.data = props.data;
-
-  selectOrderFrequency().then(res=>{
+  console.log("state.data", state.data);
+  selectOrderFrequency().then(res => {
     // console.log(res, 'selectOrderFrequency')
-    orderFrequency = res
-  })
+    orderFrequency = res;
+  });
 
   if (printPrescription(true).length === 0) {
     printPrescription(false);
@@ -168,9 +234,16 @@ defineExpose({
   <div class="layout_container layout-horizontal print-poisonous-hemp">
     <aside style="width: 220px">
       <el-collapse v-model="state.collapses">
-        <el-collapse-item v-for="item in drugFlag" :title="item.name" :name="`print-poisonous-hemp-${item.code}`">
-          <div class="print-poisonous-hemp__tag" v-for="drugItem in state.data?.data?.['drug' + item.code]?.data ||
-            []">
+        <el-collapse-item
+          v-for="item in drugFlag"
+          :title="item.name"
+          :name="`print-poisonous-hemp-${item.code}`"
+        >
+          <div
+            class="print-poisonous-hemp__tag"
+            v-for="drugItem in state.data?.data?.['drug' + item.code]?.data ||
+            []"
+          >
             {{ drugItem.orderName }}
           </div>
         </el-collapse-item>
@@ -191,7 +264,8 @@ defineExpose({
                 printFunc();
               }
             }
-        ">打印
+          "
+          >打印
         </el-button>
         <span style="color: red">
           请注意,如果有余液请在 【余液丢弃】
@@ -201,16 +275,20 @@ defineExpose({
       <div class="layout_main">
         <PrintTemplate>
           <template v-for="(item, index) in state.currentDrugData">
-            <div style="
+            <div
+              style="
                 display: flex;
                 flex-direction: column;
                 height: 210mm;
                 width: 148mm;
                 padding: 10pt;
                 overflow: hidden;
-              ">
+              "
+            >
               <div style="text-align: right">
-                <span style="border: 0.75pt solid red; color: red; padding: 3px">
+                <span
+                  style="border: 0.75pt solid red; color: red; padding: 3px"
+                >
                   {{ item.printName }}
                 </span>
               </div>
@@ -229,7 +307,9 @@ defineExpose({
                   </div> -->
                 </div>
               </div>
-              <div style="text-align: center">{{ getTitle(item) }} 药品专用处方笺</div>
+              <div style="text-align: center">
+                {{ getTitle(item) }} 药品专用处方笺
+              </div>
               <!-- <div style="
                   display: flex;
                   justify-content: space-between;
@@ -283,7 +363,10 @@ defineExpose({
                   <div style="display: inline-block; width: 90pt" class="print-poisonous-hemp__tag--underline"></div>
                 </div>
               </div> -->
-              <div style="height: 5pt" class="print-poisonous-hemp__tag--underline"></div>
+              <div
+                style="height: 5pt"
+                class="print-poisonous-hemp__tag--underline"
+              ></div>
               <div class="print-poisonous-hemp__header-table">
                 <table style="table-layout: fixed">
                   <tbody>
@@ -291,25 +374,34 @@ defineExpose({
                       <td class="print-poisonous-hemp__tag--text-right">
                         姓名
                       </td>
-                      <td class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
+                      <td
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      >
                         {{ state.data.name }}
                       </td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         性别
                       </td>
-                      <td class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
+                      <td
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      >
                         {{ cptSex(state.data.gender) }}
                       </td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         年龄
                       </td>
-                      <td class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
-                        {{ state.data.age }}
+                      <td
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      >
+                        {{ calculateAge(state.data.birthDate) }}
                       </td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         身份证号
                       </td>
-                      <td colspan="3" class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
+                      <td
+                        colspan="3"
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      >
                         {{ state.data.socialNo }}
                       </td>
                     </tr>
@@ -317,41 +409,54 @@ defineExpose({
                       <td class="print-poisonous-hemp__tag--text-right">
                         代办人
                       </td>
-                      <td class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
-                      </td>
+                      <td
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      ></td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         性别
                       </td>
-                      <td class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
-                      </td>
+                      <td
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      ></td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         年龄
                       </td>
-                      <td class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
-                      </td>
+                      <td
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      ></td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         身份证号
                       </td>
-                      <td colspan="3" class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
-                      </td>
+                      <td
+                        colspan="3"
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      ></td>
                     </tr>
                     <tr>
                       <td class="print-poisonous-hemp__tag--text-right">
                         住院号
                       </td>
-                      <td colspan="3" class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
+                      <td
+                        colspan="3"
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      >
                         {{ state.data.inpatientNo }}
                       </td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         科别
                       </td>
-                      <td class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline">
+                      <td
+                        class="print-poisonous-hemp__tag--text-left print-poisonous-hemp__tag--underline"
+                      >
                         {{ state.data.wardName }}
                       </td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         开具时间
                       </td>
-                      <td colspan="3" class="print-poisonous-hemp__tag--underline">
+                      <td
+                        colspan="3"
+                        class="print-poisonous-hemp__tag--underline"
+                      >
                         {{ item.startTime }}
                       </td>
                     </tr>
@@ -359,13 +464,19 @@ defineExpose({
                       <td class="print-poisonous-hemp__tag--text-right">
                         住址
                       </td>
-                      <td colspan="3" class="print-poisonous-hemp__tag--underline">
+                      <td
+                        colspan="3"
+                        class="print-poisonous-hemp__tag--underline"
+                      >
                         {{ state.data.homeStreet }}
                       </td>
                       <td class="print-poisonous-hemp__tag--text-right">
                         电话
                       </td>
-                      <td colspan="5" class="print-poisonous-hemp__tag--underline">
+                      <td
+                        colspan="5"
+                        class="print-poisonous-hemp__tag--underline"
+                      >
                         {{ state.data.homeTel }}
                       </td>
                     </tr>
@@ -373,21 +484,26 @@ defineExpose({
                       <td class="print-poisonous-hemp__tag--text-right">
                         临床诊断
                       </td>
-                      <td colspan="9" class="print-poisonous-hemp__tag--underline">
+                      <td
+                        colspan="9"
+                        class="print-poisonous-hemp__tag--underline"
+                      >
                         {{ state.data.diagnose }}
                       </td>
                     </tr>
                   </tbody>
                 </table>
               </div>
-              <div style="
+              <div
+                style="
                   flex: 1;
                   height: 0;
                   display: flex;
                   flex-direction: column;
                   border-top: 0.75pt solid #000;
                   margin-top: 2pt;
-                ">
+                "
+              >
                 <div style="padding-top: 6pt">
                   <img :src="Pr" />
                 </div>
@@ -395,9 +511,7 @@ defineExpose({
                   <table>
                     <tbody>
                       <tr>
-                        <td colspan="2">
-                          药品名称
-                        </td>
+                        <td colspan="2">药品名称</td>
                         <!-- <td
                           style="width: 33%"
                           class="print-poisonous-hemp__tag--text-right"
@@ -422,11 +536,12 @@ defineExpose({
                           {{ item.drugSpecification }}
                         </td>
                         <td>
-                          {{ Number(item.drugQuan) * getFrequencyCount(item.frequCode) }}{{ item.packUnitName }}
-                        </td>
-                        <td>
-                          {{ item.dose }}{{ item.doseUnitName }}
+                          {{
+                            Number(item.drugQuan) *
+                            getFrequencyCount(item.frequCode)
+                          }}{{ item.packUnitName }}
                         </td>
+                        <td>{{ item.dose }}{{ item.doseUnitName }}</td>
                         <td>{{ item.frequName }}</td>
                         <td>{{ item.supplyName }}</td>
                       </tr>
@@ -441,10 +556,14 @@ defineExpose({
                             />mg 按医疗垃圾处理&nbsp;&nbsp;&nbsp;
                           </span>
                           <span :class="item.dropAmt ? '' : 'print-none'">
-                            双人签名:<span style="width: 90pt; display: inline-block"
-                              class="print-poisonous-hemp__tag--underline"></span>&nbsp;&nbsp;<span
+                            双人签名:<span
                               style="width: 90pt; display: inline-block"
-                              class="print-poisonous-hemp__tag--underline"></span>
+                              class="print-poisonous-hemp__tag--underline"
+                            ></span
+                            >&nbsp;&nbsp;<span
+                              style="width: 90pt; display: inline-block"
+                              class="print-poisonous-hemp__tag--underline"
+                            ></span>
                           </span>
                         </td>
                       </tr>
@@ -458,29 +577,53 @@ defineExpose({
               <div style="height: 15pt; border-top: 0.75pt solid #000"></div>
               <div style="display: flex">
                 <div>医师</div>
-                <div class="print-poisonous-hemp__tag--underline" style="width: 21%;padding-left: 5px;">
+                <div
+                  class="print-poisonous-hemp__tag--underline"
+                  style="width: 21%; padding-left: 5px"
+                >
                   {{ item.enterOperName }}
                 </div>
                 <div>核对</div>
-                <div class="print-poisonous-hemp__tag--underline" style="width: 21%"></div>
+                <div
+                  class="print-poisonous-hemp__tag--underline"
+                  style="width: 21%"
+                ></div>
                 <div>发药</div>
-                <div class="print-poisonous-hemp__tag--underline" style="width: 20%"></div>
+                <div
+                  class="print-poisonous-hemp__tag--underline"
+                  style="width: 20%"
+                ></div>
                 <div>调配</div>
-                <div class="print-poisonous-hemp__tag--underline" style="width: 20%"></div>
+                <div
+                  class="print-poisonous-hemp__tag--underline"
+                  style="width: 20%"
+                ></div>
               </div>
               <div style="height: 4pt"></div>
               <div style="display: flex">
                 <div>审核</div>
-                <div class="print-poisonous-hemp__tag--underline" style="width: 21%;padding-left: 5px;">
-                </div>
+                <div
+                  class="print-poisonous-hemp__tag--underline"
+                  style="width: 21%; padding-left: 5px"
+                ></div>
                 <div>药费</div>
-                <div class="print-poisonous-hemp__tag--underline" style="width: 21%;padding-left: 5px;">
-                  {{ item.packRetprice ? 
-                    Number(item.packRetprice) * Number(item.drugQuan)  * getFrequencyCount(item.frequCode) 
-                    : 0 }}
+                <div
+                  class="print-poisonous-hemp__tag--underline"
+                  style="width: 21%; padding-left: 5px"
+                >
+                  {{
+                    item.packRetprice
+                      ? Number(item.packRetprice) *
+                        Number(item.drugQuan) *
+                        getFrequencyCount(item.frequCode)
+                      : 0
+                  }}
                 </div>
                 <div>发出药品批号</div>
-                <div class="print-poisonous-hemp__tag--underline" style="width: 35%"></div>
+                <div
+                  class="print-poisonous-hemp__tag--underline"
+                  style="width: 35%"
+                ></div>
               </div>
               <div style="height: 4pt"></div>
               <div style="margin: 5pt 0; border-top: 0.75pt solid #000"></div>