60 lines
2.5 KiB
PHP
Executable File
60 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\common\service;
|
|
|
|
/** Single entry point for references attached to clinical model requests. */
|
|
final class ClinicalKnowledgeReference
|
|
{
|
|
/** Only a server-selected live task may use this short, source-bound contract. */
|
|
public static function augmentLiveConsultationQuery(string $query, string $analysisScope = 'authorized_case'): string
|
|
{
|
|
$prefix = TcmClinicalResponsePolicy::liveConsultationReference($analysisScope) . "\n\n";
|
|
return str_starts_with($query, $prefix) ? $query : $prefix . $query;
|
|
}
|
|
|
|
/** Case reports retain response rules without importing textbook patient-like findings. */
|
|
public static function augmentCaseQuery(string $query, bool $consultation = false): string
|
|
{
|
|
$boundary = '[TCM_CASE_SOURCE_BOUNDARY:v1]' . "\n"
|
|
. '本例事实和方药依据只能来自给定患者资料,保留否定、程度、日期与未知状态;'
|
|
. '不得用教材或古籍的常见方证补写本例症状或阴性体征。历史方药保留原时点与状态,仅作原始记录。';
|
|
$prefix = ($consultation ? TcmClinicalResponsePolicy::consultationReference()
|
|
: TcmClinicalResponsePolicy::reference()) . "\n\n" . $boundary . "\n\n";
|
|
return str_starts_with($query, $prefix) ? $query : $prefix . $query;
|
|
}
|
|
|
|
public static function augmentQuery(string $query): string
|
|
{
|
|
return TcmClinicalResponsePolicy::augmentQuery(
|
|
TcmAncientBooksReference::augmentQuery(NihaixiaClinicalSkill::augmentQuery($query))
|
|
);
|
|
}
|
|
|
|
/** @param list<array<string,mixed>> $ancientBookSources */
|
|
public static function augmentQueryWithAncientBookSources(string $query, array $ancientBookSources): string
|
|
{
|
|
return TcmClinicalResponsePolicy::augmentQuery(TcmAncientBooksReference::augmentQueryWithSources(
|
|
NihaixiaClinicalSkill::augmentQuery($query),
|
|
$ancientBookSources
|
|
));
|
|
}
|
|
|
|
/** @param array<int,array<string,mixed>> $messages
|
|
* @return array<int,array<string,mixed>>
|
|
*/
|
|
public static function augmentMessages(array $messages): array
|
|
{
|
|
return TcmClinicalResponsePolicy::augmentMessages(
|
|
TcmAncientBooksReference::augmentMessages(NihaixiaClinicalSkill::augmentMessages($messages))
|
|
);
|
|
}
|
|
|
|
/** @return list<array<string,mixed>> */
|
|
public static function ancientBookSources(string $query): array
|
|
{
|
|
return TcmAncientBooksReference::sourcesForText($query);
|
|
}
|
|
}
|