@@ -25,6 +25,7 @@ public function navigation()
2525 'Dashboard ' => 'manage ' ,
2626 'Master CP ' => 'master ' ,
2727 'Template Harian ' => 'template ' ,
28+ 'Template CPPT ' => 'cppttemplate ' ,
2829 'Mapping ICD ' => 'mapping ' ,
2930 'Evidence Engine ' => 'evidence ' ,
3031 'Generator CP ' => 'generator ' ,
@@ -142,6 +143,42 @@ public function getDeleteactivity($id)
142143 redirect (url ([ADMIN , 'clinical_pathway ' , 'template ' ]) . '&cp_id= ' . $ cpId );
143144 }
144145
146+ public function anyCppttemplate ()
147+ {
148+ $ this ->_addHeaderFiles ();
149+
150+ $ selectedId = (int ) ($ _GET ['id ' ] ?? 0 );
151+ $ selected = $ selectedId ? $ this ->getCpptTemplateRow ($ selectedId ) : [];
152+
153+ return $ this ->draw ('cppt.template.html ' , [
154+ 'selected ' => htmlspecialchars_array ($ selected ),
155+ 'rows ' => htmlspecialchars_array ($ this ->getCpptTemplateList ()),
156+ 'ppra_options ' => $ this ->getCpptPpraOptions ($ selected ['ppra ' ] ?? '' )
157+ ]);
158+ }
159+
160+ public function postSavecppttemplate ()
161+ {
162+ $ result = $ this ->saveCpptTemplate ($ _POST );
163+
164+ $ this ->notify ($ result ['status ' ] ? 'success ' : 'failure ' , $ result ['message ' ]);
165+ redirect (url ([ADMIN , 'clinical_pathway ' , 'cppttemplate ' ]));
166+ }
167+
168+ public function getDeletecppttemplate ($ id )
169+ {
170+ $ row = $ this ->db ('mlite_clinical_pathway_cppt_template ' )->oneArray ('id ' , (int ) $ id );
171+
172+ if ($ row ) {
173+ $ this ->db ('mlite_clinical_pathway_cppt_template ' )->delete ((int ) $ id );
174+ $ this ->notify ('success ' , 'Template CPPT berhasil dihapus. ' );
175+ } else {
176+ $ this ->notify ('failure ' , 'Template CPPT tidak ditemukan. ' );
177+ }
178+
179+ redirect (url ([ADMIN , 'clinical_pathway ' , 'cppttemplate ' ]));
180+ }
181+
145182 public function anyMapping ()
146183 {
147184 $ this ->_addHeaderFiles ();
@@ -562,6 +599,117 @@ protected function getCpOptions()
562599 return $ this ->db ('mlite_clinical_pathway ' )->asc ('nama_cp ' )->toArray ();
563600 }
564601
602+ protected function getCpptTemplateList ()
603+ {
604+ $ sql = "SELECT t.*, py.nm_penyakit
605+ FROM mlite_clinical_pathway_cppt_template t
606+ LEFT JOIN penyakit py ON py.kd_penyakit = t.kd_penyakit
607+ ORDER BY t.aktif DESC, t.ppra ASC, t.kd_penyakit ASC " ;
608+
609+ return $ this ->pdo ()->query ($ sql )->fetchAll (PDO ::FETCH_ASSOC );
610+ }
611+
612+ protected function getCpptPpraOptions ($ selected = '' )
613+ {
614+ $ options = [
615+ 'PPRA ' ,
616+ 'Medis ' ,
617+ 'Keperawatan ' ,
618+ 'Farmasi Klinis ' ,
619+ 'Gizi ' ,
620+ 'Rehab Medik ' ,
621+ 'Edukasi '
622+ ];
623+
624+ $ selected = trim ((string ) $ selected );
625+ if ($ selected !== '' && !in_array ($ selected , $ options , true )) {
626+ $ options [] = $ selected ;
627+ }
628+
629+ sort ($ options );
630+
631+ return $ options ;
632+ }
633+
634+ protected function getCpptTemplateRow ($ id )
635+ {
636+ $ sql = "SELECT t.*, py.nm_penyakit
637+ FROM mlite_clinical_pathway_cppt_template t
638+ LEFT JOIN penyakit py ON py.kd_penyakit = t.kd_penyakit
639+ WHERE t.id = ?
640+ LIMIT 1 " ;
641+
642+ $ stmt = $ this ->pdo ()->prepare ($ sql );
643+ $ stmt ->execute ([(int ) $ id ]);
644+
645+ return $ stmt ->fetch (PDO ::FETCH_ASSOC ) ?: [];
646+ }
647+
648+ protected function saveCpptTemplate ($ data )
649+ {
650+ $ now = date ('Y-m-d H:i:s ' );
651+ $ kdPenyakit = strtoupper (trim ((string ) ($ data ['kd_penyakit ' ] ?? '' )));
652+ $ subjective = trim ((string ) ($ data ['subjective ' ] ?? '' ));
653+ $ objective = trim ((string ) ($ data ['objective ' ] ?? '' ));
654+ $ assessment = trim ((string ) ($ data ['assessment ' ] ?? '' ));
655+ $ plan = trim ((string ) ($ data ['plan ' ] ?? '' ));
656+ $ ppra = trim ((string ) ($ data ['ppra ' ] ?? '' ));
657+ $ aktif = ($ data ['aktif ' ] ?? 'Ya ' ) === 'Tidak ' ? 'Tidak ' : 'Ya ' ;
658+
659+ if ($ kdPenyakit === '' || $ ppra === '' || $ subjective === '' || $ objective === '' || $ assessment === '' || $ plan === '' ) {
660+ return ['status ' => false , 'message ' => 'Kode ICD, kategori PPRA, S, O, A, dan P wajib diisi. ' ];
661+ }
662+
663+ if (!in_array ($ ppra , $ this ->getCpptPpraOptions ($ ppra ), true )) {
664+ return ['status ' => false , 'message ' => 'Kategori PPRA tidak valid. ' ];
665+ }
666+
667+ $ diagnosis = $ this ->db ('penyakit ' )->oneArray ('kd_penyakit ' , $ kdPenyakit );
668+ if (!$ diagnosis ) {
669+ return ['status ' => false , 'message ' => 'Kode ICD tidak ditemukan pada master penyakit. ' ];
670+ }
671+
672+ $ payload = [
673+ 'kd_penyakit ' => $ kdPenyakit ,
674+ 'ppra ' => $ ppra ,
675+ 'subjective ' => $ subjective ,
676+ 'objective ' => $ objective ,
677+ 'assessment ' => $ assessment ,
678+ 'plan ' => $ plan ,
679+ 'aktif ' => $ aktif ,
680+ 'updated_at ' => $ now
681+ ];
682+
683+ $ duplicate = $ this ->db ('mlite_clinical_pathway_cppt_template ' )
684+ ->where ('kd_penyakit ' , $ kdPenyakit )
685+ ->oneArray ();
686+
687+ if (!empty ($ data ['id ' ])) {
688+ $ id = (int ) $ data ['id ' ];
689+ if ($ duplicate && (int ) $ duplicate ['id ' ] !== $ id ) {
690+ return ['status ' => false , 'message ' => 'Template CPPT untuk ICD ini sudah ada. ' ];
691+ }
692+
693+ $ saved = $ this ->db ('mlite_clinical_pathway_cppt_template ' )->where ('id ' , $ id )->save ($ payload );
694+ return [
695+ 'status ' => (bool ) $ saved ,
696+ 'message ' => $ saved ? 'Template CPPT berhasil diperbarui. ' : 'Template CPPT gagal diperbarui. '
697+ ];
698+ }
699+
700+ if ($ duplicate ) {
701+ return ['status ' => false , 'message ' => 'Template CPPT untuk ICD ini sudah ada. ' ];
702+ }
703+
704+ $ payload ['created_at ' ] = $ now ;
705+ $ saved = $ this ->db ('mlite_clinical_pathway_cppt_template ' )->save ($ payload );
706+
707+ return [
708+ 'status ' => (bool ) $ saved ,
709+ 'message ' => $ saved ? 'Template CPPT berhasil disimpan. ' : 'Template CPPT gagal disimpan. '
710+ ];
711+ }
712+
565713 protected function saveMaster ($ data )
566714 {
567715 $ now = date ('Y-m-d H:i:s ' );
@@ -2354,12 +2502,15 @@ protected function getPrintableCpByNoRawat($noRawat)
23542502 return [];
23552503 }
23562504
2505+ $ diagnoses = $ this ->getPatientDiagnoses ($ noRawat , $ header ['status_lanjut ' ]);
2506+
23572507 return [
23582508 'header ' => $ header ,
23592509 'hospital ' => $ this ->getHospitalProfile (),
23602510 'tariffs ' => $ this ->getHospitalTariffSummary ($ noRawat , $ header ['status_lanjut ' ]),
23612511 'care_team ' => $ this ->getCareTeamByNoRawat ($ noRawat , $ header ['status_lanjut ' ], $ header ['tgl_registrasi ' ], $ header ['kd_dokter ' ] ?? null ),
2362- 'diagnoses ' => $ this ->getPatientDiagnoses ($ noRawat , $ header ['status_lanjut ' ]),
2512+ 'diagnoses ' => $ diagnoses ,
2513+ 'cppt_template ' => $ this ->getPrintableCpptTemplate ($ diagnoses , $ header ['kd_penyakit ' ] ?? '' ),
23632514 'days ' => $ this ->getPrintableExecutionDays ((int ) $ header ['clinical_pathway_patient_id ' ], (int ) $ header ['target_los ' ]),
23642515 'matrix ' => $ this ->getPrintableMatrixRows ((int ) $ header ['clinical_pathway_patient_id ' ], (int ) $ header ['target_los ' ]),
23652516 'variances ' => $ this ->getPrintableVariances ((int ) $ header ['clinical_pathway_patient_id ' ]),
@@ -2368,6 +2519,50 @@ protected function getPrintableCpByNoRawat($noRawat)
23682519 ];
23692520 }
23702521
2522+ protected function getPrintableCpptTemplate (array $ diagnoses , $ fallbackCode = '' )
2523+ {
2524+ $ codes = [];
2525+ foreach ($ diagnoses as $ diagnosis ) {
2526+ $ code = strtoupper (trim ((string ) ($ diagnosis ['kd_penyakit ' ] ?? '' )));
2527+ if ($ code !== '' && !in_array ($ code , $ codes , true )) {
2528+ $ codes [] = $ code ;
2529+ }
2530+ }
2531+
2532+ $ fallbackCode = strtoupper (trim ((string ) $ fallbackCode ));
2533+ if ($ fallbackCode !== '' && !in_array ($ fallbackCode , $ codes , true )) {
2534+ $ codes [] = $ fallbackCode ;
2535+ }
2536+
2537+ if (!$ codes ) {
2538+ return [];
2539+ }
2540+
2541+ foreach ($ codes as $ code ) {
2542+ $ row = $ this ->getCpptTemplateByDiagnosisCode ($ code );
2543+ if ($ row ) {
2544+ return $ row ;
2545+ }
2546+ }
2547+
2548+ return [];
2549+ }
2550+
2551+ protected function getCpptTemplateByDiagnosisCode ($ kdPenyakit )
2552+ {
2553+ $ sql = "SELECT t.*, py.nm_penyakit
2554+ FROM mlite_clinical_pathway_cppt_template t
2555+ LEFT JOIN penyakit py ON py.kd_penyakit = t.kd_penyakit
2556+ WHERE t.kd_penyakit = ?
2557+ AND t.aktif = 'Ya'
2558+ LIMIT 1 " ;
2559+
2560+ $ stmt = $ this ->pdo ()->prepare ($ sql );
2561+ $ stmt ->execute ([strtoupper (trim ((string ) $ kdPenyakit ))]);
2562+
2563+ return $ stmt ->fetch (PDO ::FETCH_ASSOC ) ?: [];
2564+ }
2565+
23712566 protected function getHospitalProfile ()
23722567 {
23732568 $ logo = trim ((string ) $ this ->settings ('settings.logo ' ));
0 commit comments