comparison src/kaigo/Nk/nk.go @ 42:c58172a59534

bug fix.
author pyon@macmini
date Tue, 10 Mar 2020 21:12:29 +0900
parents 34a474fb83c3
children 17e042fc8a33
comparison
equal deleted inserted replaced
41:34a474fb83c3 42:c58172a59534
1 /* 1 /*
2 nk.go: Nintei Kekka 2 nk.go: Nintei Kekka
3 3
4 Last Change: 2020-01-24 金 09:18:04. 4 Last Change: 2020-03-10 火 16:38:20.
5 */ 5 */
6 6
7 package main 7 package main
8 8
9 /* 9 /*
100 XDW_CloseDocumentHandle(h, NULL); 100 XDW_CloseDocumentHandle(h, NULL);
101 101
102 return (api_result >= 0); 102 return (api_result >= 0);
103 } 103 }
104 104
105 int xdwaddatn(const char* file, char* atnlist) { 105 int xdwhbaddatn(const char* file, char* atnlist) {
106 char in_path[_MAX_PATH]; 106 char in_path[_MAX_PATH];
107 _fullpath(in_path, file, _MAX_PATH); 107 _fullpath(in_path, file, _MAX_PATH);
108 108
109 XDW_DOCUMENT_HANDLE h = NULL; 109 XDW_DOCUMENT_HANDLE h = NULL;
110 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE}; 110 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE};
271 271
272 free(blk_path); 272 free(blk_path);
273 free(blk_path_addr); 273 free(blk_path_addr);
274 274
275 return 0; 275 return 0;
276 }
277
278 int xdwerase(const char* in_file, const char* ktxt, const char* htxt) {
279 int x = 20000;
280 int y = 3685;
281 int sz = 480;
282
283 char in_path[_MAX_PATH];
284 _fullpath(in_path, in_file, _MAX_PATH);
285
286 XDW_DOCUMENT_HANDLE h = NULL;
287 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE};
288
289 int api_result = XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode);
290 if (api_result < 0) return api_result;
291
292 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0};
293 XDW_GetDocumentInformation(h, &info);
294
295 XDW_FOUND_HANDLE pFoundHandle = NULL;
296 for (int i = 0; i < info.nPages; i++) {
297 api_result = XDW_FindTextInPage(h, i + 1, htxt, NULL, &pFoundHandle, NULL);
298 if (pFoundHandle == NULL) continue;
299
300 api_result = XDW_FindTextInPage(h, i + 1, ktxt, NULL, &pFoundHandle, NULL);
301 if (pFoundHandle == NULL) continue;
302
303 XDW_ANNOTATION_HANDLE annoation;
304 int api_result = XDW_AddAnnotation(h, XDW_AID_TEXT, i + 1, x, y, NULL, &annoation, NULL);
305 if (api_result < 0) return api_result;
306
307 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_Text, XDW_ATYPE_STRING, " ", 0, NULL);
308 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_FontSize, XDW_ATYPE_INT, (char*)&sz, 0, NULL);
309 }
310
311 XDW_SaveDocument(h, NULL);
312 XDW_CloseDocumentHandle(h, NULL);
313
314 return 0;
276 } 315 }
277 316
278 int xdw2pdf(const char* xdwfile, const char* pdffile) { 317 int xdw2pdf(const char* xdwfile, const char* pdffile) {
279 char in_path[_MAX_PATH], out_path[_MAX_PATH]; 318 char in_path[_MAX_PATH], out_path[_MAX_PATH];
280 _fullpath(in_path, xdwfile, _MAX_PATH); 319 _fullpath(in_path, xdwfile, _MAX_PATH);
344 "golang.org/x/text/encoding/japanese" 383 "golang.org/x/text/encoding/japanese"
345 "golang.org/x/text/transform" 384 "golang.org/x/text/transform"
346 ) 385 )
347 386
348 var ( 387 var (
349 ver = "0.1" 388 ver = "0.2"
350 389
351 flg_hb int 390 flg_hb int
352 flg_time bool 391 flg_time bool
353 flg_log bool 392 flg_log bool
354 flg_debug bool 393 flg_debug bool
366 start time.Time 405 start time.Time
367 406
368 hb string // 発番 407 hb string // 発番
369 fw, hs, kt = "", "", "kttemp.xdw" // 負担割合証, 被保険者証, 結果通知 408 fw, hs, kt = "", "", "kttemp.xdw" // 負担割合証, 被保険者証, 結果通知
370 409
371 step, totalstep = 1, 13 410 step, totalstep = 1, 14
372 ) 411 )
373 412
374 type Annotation struct { 413 type Annotation struct {
375 X, Y int 414 X, Y int
376 Sz int 415 Sz int
570 step_start = print_time(step_start) 609 step_start = print_time(step_start)
571 610
572 /* MAKE SORT-TABEL */ 611 /* MAKE SORT-TABEL */
573 print_step("並び順の決定") 612 print_step("並び順の決定")
574 613
575 re_hhs := regexp.MustCompile(`05((2126)|(2159)|(4346))0[1238]\d{8}`) 614 re_hhs := regexp.MustCompile(`0[1238]\d{8}`)
576 re_kaigo := regexp.MustCompile(`要((介護)|(支援)).`) 615 re_kaigo := regexp.MustCompile(`要((介護)|(支援)).`)
577 616
578 hash_fw := make(map[string]int) // 負担割合証発行者のハッシュ 617 hash_fw := make(map[string]int) // 負担割合証発行者のハッシュ
579 for _, t := range xdw2txt(fw) { 618 for _, t := range xdw2txt(fw) {
580 hash_fw[re_hhs.FindString(t)]++ 619 hash_fw[re_hhs.FindString(t)]++
605 644
606 /* DO SORT */ 645 /* DO SORT */
607 order := "" 646 order := ""
608 for _, s := range sorttable { 647 for _, s := range sorttable {
609 t := strings.Split(s, "#") 648 t := strings.Split(s, "#")
610 order += ":" + t[len(t)-1][6:] 649 order += ":" + t[len(t)-1]
611 } 650 }
612 order = strings.Replace(order, ":", "", 1) 651 order = strings.Replace(order, ":", "", 1)
613 652
614 print_step("被保険者証並び替え") 653 print_step("被保険者証並び替え")
615 hs_sorted := filepath.Join(tmpdir, "hs.xdw") 654 hs_sorted := filepath.Join(tmpdir, "hs.xdw")
624 print_step("結果通知並び替え") 663 print_step("結果通知並び替え")
625 kt_sorted := filepath.Join(tmpdir, "kt.xdw") 664 kt_sorted := filepath.Join(tmpdir, "kt.xdw")
626 C.xdwsort(C.CString(kt), C.CString(kt_sorted), C.CString(order), C.CString(tmpdir), C.CString("kt")) 665 C.xdwsort(C.CString(kt), C.CString(kt_sorted), C.CString(order), C.CString(tmpdir), C.CString("kt"))
627 step_start = print_time(step_start) 666 step_start = print_time(step_start)
628 667
629 /* ADD ANNOTATION */ 668 /* ADD HATSUBAN */
630 print_step("発番印字") 669 print_step("発番印字")
631 al := strings.Join(conf.AnnotationList(), ":") 670 al := strings.Join(conf.AnnotationList(), ":")
632 al, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), al) 671 al, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), al)
633 C.xdwaddatn(C.CString(kt_sorted), C.CString(al)) 672 C.xdwhbaddatn(C.CString(kt_sorted), C.CString(al))
673 step_start = print_time(step_start)
674
675 /* ERASE HOUKATSU */
676 print_step("包括除去")
677 ktxt, _, _ := transform.String(japanese.ShiftJIS.NewEncoder(), "要介護")
678 htxt, _, _ := transform.String(japanese.ShiftJIS.NewEncoder(), "包括支援センター")
679 C.xdwerase(C.CString(hs_sorted), C.CString(ktxt), C.CString(htxt))
634 step_start = print_time(step_start) 680 step_start = print_time(step_start)
635 681
636 /* OPTIMIZE OUTPUT-FILE */ 682 /* OPTIMIZE OUTPUT-FILE */
637 print_step("最適化") 683 print_step("最適化")
638 hs_opt := filepath.Join(outputdir, "hs.xdw") 684 hs_opt := filepath.Join(outputdir, "hs.xdw")
652 } 698 }
653 for i, s := range sorttable { 699 for i, s := range sorttable {
654 t := strings.Split(s, "#") 700 t := strings.Split(s, "#")
655 u := strings.ReplaceAll(t[1], ":", ",") 701 u := strings.ReplaceAll(t[1], ":", ",")
656 u, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), u) 702 u, _, _ = transform.String(japanese.ShiftJIS.NewEncoder(), u)
657 c := t[2][0:6] 703 h := t[2]
658 h := t[2][6:16]
659 n, _, _ := transform.String(japanese.ShiftJIS.NewEncoder(), hash_hhs[h]) 704 n, _, _ := transform.String(japanese.ShiftJIS.NewEncoder(), hash_hhs[h])
660 // seq, city, hno, name, kaigo, fw, kyotaku 705 // seq, hno, name, kaigo, fw, kyotaku
661 fmt.Fprintf(fcsv, "%04d,%s,%s,%s,%s\n", i + 1, c, h, n, u) 706 fmt.Fprintf(fcsv, "%04d,%s,%s,%s\n", i + 1, h, n, u)
662 } 707 }
663 if err := fcsv.Close(); err != nil { 708 if err := fcsv.Close(); err != nil {
664 log.Fatal(err) 709 log.Fatal(err)
665 } 710 }
666 step_start = print_time(step_start) 711 step_start = print_time(step_start)