tab1.page.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { CloudUser } from './../lib/ncloud';
  2. import { FmodeChat, FmodeChatMessage, openChatPanelModal, ChatPanelOptions } from 'fmode-ng';
  3. import { Component } from '@angular/core';
  4. import { IonCardHeader, IonHeader, IonToolbar, IonTitle, IonContent, IonItem, IonList, IonCard, IonCardTitle, IonCardSubtitle, IonCardContent, IonThumbnail, IonFab, IonFabButton, } from '@ionic/angular/standalone';
  5. import { IonButton } from '@ionic/angular/standalone';
  6. import { IonIcon } from '@ionic/angular/standalone';
  7. import { Router } from '@angular/router';
  8. import { CommonModule } from '@angular/common';
  9. import { ModalController } from '@ionic/angular/standalone';
  10. import { HttpClient } from '@angular/common/http';
  11. import { addIcons } from 'ionicons';
  12. import { add } from 'ionicons/icons';
  13. import { documentText, chatbubbles, person, calendar, newspaper,
  14. medkit,clipboard, podium, videocam, people } from 'ionicons/icons';
  15. import { CloudObject, CloudQuery } from '../lib/ncloud';
  16. import { IonRefresher, IonRefresherContent } from '@ionic/angular/standalone';
  17. addIcons({ documentText, chatbubbles, person, calendar, newspaper,
  18. medkit,clipboard, podium, videocam, people
  19. });
  20. @Component({
  21. selector: 'app-tab1',
  22. templateUrl: 'tab1.page.html',
  23. styleUrls: ['tab1.page.scss'],
  24. standalone: true,
  25. imports: [
  26. IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
  27. IonIcon,IonItem,IonList,CommonModule,IonCard,IonCardHeader,IonCardTitle,IonCardSubtitle,
  28. IonCardContent, IonThumbnail, IonFab,IonFabButton,IonIcon,IonRefresher,IonRefresherContent
  29. ],
  30. })
  31. export class Tab1Page {
  32. handleRefresh(event:any) {
  33. setTimeout(() => {
  34. // Any calls to load data go here
  35. this.loadDoctorList()
  36. event.target.complete();
  37. }, 2000);
  38. }
  39. admin:string = 'nRDdxdEn2k'
  40. user : CloudUser
  41. doctorList1: Array<CloudObject> = []
  42. async loadAllagent(){
  43. let query = new CloudQuery("NovelCharacter")
  44. query.include("user")
  45. this.doctorList1=await query.find()
  46. console.log("doctor.get('user').username",this.doctorList1[0].get("username"))
  47. }
  48. constructor(
  49. private router: Router,
  50. private modalCtrl: ModalController,
  51. // private navCtrl: NavController,
  52. private http: HttpClient// 注入 HttpClient,
  53. ) {
  54. this.user = new CloudUser();
  55. this.loadAllagent();
  56. addIcons({ add });
  57. }
  58. navigateToPage() {
  59. this.router.navigate(['../agent-create']); // 替换为目标页面的路由
  60. }
  61. /**
  62. * Go to the ai page
  63. */
  64. // 导航到指定路由
  65. navigateTo(route: string) {
  66. this.router.navigate([route]);
  67. console.log("route: ",route)
  68. }
  69. ngOnInit() {
  70. this.loadDoctorList()
  71. }
  72. doctorList:Array<CloudObject> = []
  73. async loadDoctorList(){
  74. let user = new CloudUser();
  75. let query = new CloudQuery("NovelCharacter");
  76. query.equalTo("user",user?.id)
  77. console.log("user",user.id)
  78. this.doctorList = await query.find()
  79. }
  80. /** 示例:问诊根据doctor拼接提示词 */
  81. openInquiry(doctor:CloudObject){
  82. console.log("doctor",doctor)
  83. localStorage.setItem("company","E4KpGvTEto")
  84. let consult = new CloudObject("NovelCharacter")
  85. let now = new Date();
  86. let dateStr = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()}`
  87. consult.set({
  88. title:`${doctor.get('depart')?.name || ""}门诊记录${dateStr}-${doctor?.get("name")}`,
  89. doctor:doctor.toPointer(),
  90. depart:doctor.get("depart")
  91. })
  92. let options:ChatPanelOptions = {
  93. roleId:"2DXJkRsjXK",
  94. onChatInit:(chat:FmodeChat)=>{
  95. console.log("onChatInit");
  96. console.log("预设角色",chat.role);
  97. chat.role.set("name",doctor?.get("name"));
  98. chat.role.set("title",doctor?.get("title"));
  99. chat.role.set("desc",doctor?.get("desc"));
  100. chat.role.set("tags",doctor?.get("qualifications"));
  101. chat.role.set("avatar",doctor?.get("avatar") || "../../assets/image/doctor5.png")
  102. chat.role.set("prompt",`
  103. # 角色设定
  104. 您是${doctor?.get("desc")},${doctor?.get("name")},年龄${doctor?.get("age")}岁,需要完成一次完整的门诊服务。
  105. # 对话环节
  106. 0.导诊(根据用户基本情况,引导挂号合适的科室)
  107. 1.预设的问询方式(根据不同症状来问询具体的情况)
  108. - 打招呼,以用户自述为主
  109. - 当信息充足时候,确认用户症状对应的科室,并进入下一个环节
  110. 2.拓展的问询细节
  111. 例如:用户反映呼吸不畅,拓展出:是否咳嗽;是否感觉痛或者痒等其他需要的问题。
  112. - 当问询细节补充完成后进入下一个环节
  113. 3.初步的诊断结果,并且同时列出检查检验项目
  114. 初步诊断:确定需要有哪些进一步检查
  115. 检查检验:获取医学客观数据
  116. - 等待用户提交客观数据,进入下一阶段
  117. 4.给出诊断方案并给出处方
  118. - 完成处方时,请在消息结尾附带: [处方完成]
  119. # 开始话语
  120. 当您准备好了,可以以一个医生的身份,向来访的用户打招呼。`);
  121. },
  122. onMessage:(chat:FmodeChat,message:FmodeChatMessage)=>{
  123. console.log("onMessage",message)
  124. let content:any = message?.content
  125. if(typeof content == "string"){
  126. if(content?.indexOf("[处方完成]")>-1){
  127. console.log("门诊已完成")
  128. consult.set({
  129. content:content // 处方内容
  130. })
  131. consult.save();
  132. }
  133. }
  134. },
  135. onChatSaved:(chat:FmodeChat)=>{
  136. // chat?.chatSession?.id 本次会话的 chatId
  137. console.log("onChatSaved",chat,chat?.chatSession,chat?.chatSession?.id)
  138. }
  139. }
  140. openChatPanelModal(this.modalCtrl,options)
  141. }
  142. deleteAgent(agent:CloudObject){
  143. console.log("删除了",agent);
  144. agent.destroy();
  145. this.loadDoctorList()
  146. }
  147. }