diff --git a/netforce_clinic/actions/clinic_hd_case_dlz.xml b/netforce_clinic/actions/clinic_hd_case_dlz.xml index 1791768..fe4482f 100644 --- a/netforce_clinic/actions/clinic_hd_case_dlz.xml +++ b/netforce_clinic/actions/clinic_hd_case_dlz.xml @@ -2,5 +2,6 @@ New Dialyzer form_popup clinic.hd.case.popup.dlz + 800 _popup diff --git a/netforce_clinic/models/:w b/netforce_clinic/models/:w new file mode 100644 index 0000000..19677df --- /dev/null +++ b/netforce_clinic/models/:w @@ -0,0 +1,78 @@ +from netforce.model import Model, fields, get_model + +class HDCasePopupDlz(Model): + _name="clinic.hd.case.popup.dlz" + _transient=True + + _fields={ + "hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"), + 'product_id': fields.Many2One("product", "Product",required=True), + "dialyzer_type": fields.Selection([("low","low flux"),("high","high flux"),("dbl","dbl hifulx")],"Dialyzer Type"), + "max_use_time": fields.Integer("Max Use Time"), + "exp_date": fields.Date("Expiry Date"), + "note": fields.Text("Note"), + "membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"), + } + + def __get_hd_case_id(self,context={}): + hd_case_id=context.get("refer_id") + print("clinic.hd.case.popup.dlz default") + if not hd_case_id: + return None + return int(hd_case_id) + + def default_get(self,field_names=None,context={},**kw): + defaults=context.get("defaults",{}) + hdcase_id=defaults.get('hd_case_id') + dialyzer_type=defaults.get('dialyzer_type') + if not hdcase_id: + hdcase_id=context.get("refer_id") + if hdcase_id: + hdcase=get_model('clinic.hd.case').browse(hdcase_id) + dom=[] + for dlz in get_model('clinic.dialyzer').search_browse(dom): + dialyzer_type=dlz.dialyzer_type or "low" + pass + res={ + 'hd_case_id': hdcase_id, + 'dialyzer_type': 'low', + 'max_use_time': 10, + } + print('res', res) + return res + + def new_dlz(self,ids,context={}): + obj=self.browse(ids)[0] + hd_case=obj.hd_case_id + res={} + if hd_case: + context['is_wiz']=True + context['pop_id']=obj.id + res=hd_case.new_dialyzer(context=context) + print('res ', res) + return res + + def onchange_product(self,context={}): + data=context['data'] + hdcase_id=data['hd_case_id'] + patient=None + if hdcase_id: + hdcase=get_model('clinic.hd.case').browse(hdcase_id) + patient=hdcase.patient_id + product_id=data['product_id'] + data['membrane_type']=None + data['dialyzer_type']=None + data['max_use_time']=10 + dom=[] + if patient: + dom.append(['patient_id','=',patient.id]) + for dlz in get_model("clinic.dialyzer").search_browse(dom): + prod=dlz.product_id + if prod.id==product_id: + data['membrane_type']=dlz.membrane_type + data['dialyzer_type']=dlz.dialyzer_type or "low" + data['max_use_time']=dlz.max_use_time or 10 + break + return data + +HDCasePopupDlz.register() diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 1db6984..69ecfcf 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -133,3 +133,6 @@ from . import report_shop from . import account_tax_component from . import report_thai_wht_certif from . import num2word +from . import province +#from . import district +#from . import subdistrict diff --git a/netforce_clinic/models/district.py b/netforce_clinic/models/district.py new file mode 100644 index 0000000..be9380d --- /dev/null +++ b/netforce_clinic/models/district.py @@ -0,0 +1,21 @@ +from netforce.model import Model, fields + +class District(Model): + _inherit="district" + + def _get_sort_name(self,ids,context={}): + res={} + for obj in self.browse(ids): + sname='' + if obj.name: + sname=obj.name[0:1] + res[obj.id]=sname + return res + + _fields={ + "name": fields.Char("Name",required=True,search=True,translate=True), + "sort_name": fields.Char("Sort Name",function="_get_sort_name",store=True), + } + _order="sort_name asc" + +District.register() diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 18c942d..eb0fad4 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -868,8 +868,8 @@ class HDCase(Model): for obj in self.browse(ids): is_decrease=context.get('is_decrease') for dlz_line in obj.dialyzers: - membrane_type=dlz_line.membrane_type or '' - dialyzer_type=dlz_line.dialyzer_type or '' + membrane_type=dlz_line.membrane_type or 'unsub' + dialyzer_type=dlz_line.dialyzer_type or 'low' use_time=dlz_line.use_time or 0 max_use_time=dlz_line.max_use_time or 0 desc=dlz_line.description or '' diff --git a/netforce_clinic/models/hd_case_popup_dlz.py b/netforce_clinic/models/hd_case_popup_dlz.py index 35afccc..74765c5 100644 --- a/netforce_clinic/models/hd_case_popup_dlz.py +++ b/netforce_clinic/models/hd_case_popup_dlz.py @@ -14,18 +14,40 @@ class HDCasePopupDlz(Model): "membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"), } - def _get_hd_case_id(self,context={}): + def __get_hd_case_id(self,context={}): hd_case_id=context.get("refer_id") print("clinic.hd.case.popup.dlz default") if not hd_case_id: return None return int(hd_case_id) - - _defaults={ - 'hd_case_id': _get_hd_case_id, - 'dialyzer_type': 'low', - 'max_use_time': 10, - } + + def default_get(self,field_names=None,context={},**kw): + defaults=context.get("defaults",{}) + hdcase_id=defaults.get('hd_case_id') + dialyzer_type=defaults.get('dialyzer_type', "low") + membrane_type=defaults.get('membrane_type', "unsub") + product_id=defaults.get('product_id', None) + max_use_time=defaults.get('max_use_time', 10) + if not hdcase_id: + hdcase_id=context.get("refer_id") + if hdcase_id: + hdcase_id=int(hdcase_id) + hdcase=get_model('clinic.hd.case').browse(hdcase_id) + for line in hdcase.dialyzers: + dlz=line.dialyzer_id + product_id=dlz.product_id.id + dialyzer_type=dlz.dialyzer_type or "low" + membrane_type=dlz.membrane_type or "unsub" + max_use_time=dlz.max_use_time or 10 + res={ + 'hd_case_id': hdcase_id, + 'dialyzer_type': dialyzer_type, + 'membrane_type': membrane_type, + 'max_use_time': max_use_time, + 'product_id': product_id, + } + print('res', res) + return res def new_dlz(self,ids,context={}): obj=self.browse(ids)[0] @@ -40,17 +62,37 @@ class HDCasePopupDlz(Model): def onchange_product(self,context={}): data=context['data'] + hdcase_id=data['hd_case_id'] + patient=None + if hdcase_id: + hdcase=get_model('clinic.hd.case').browse(hdcase_id) + patient=hdcase.patient_id product_id=data['product_id'] data['membrane_type']=None data['dialyzer_type']=None - #data['max_use_time']=None - for dlz in get_model("clinic.dialyzer").search_browse([]): + data['max_use_time']=10 + dom=[] + if patient: + dom.append(['patient_id','=',patient.id]) + count=0 + for dlz in get_model("clinic.dialyzer").search_browse(dom): prod=dlz.product_id if prod.id==product_id: + count+=1 data['membrane_type']=dlz.membrane_type data['dialyzer_type']=dlz.dialyzer_type or "low" - data['max_use_time']=dlz.max_use_time or 0 + data['max_use_time']=dlz.max_use_time or 10 break + # search from another patient + if not count: + dom=[] + for dlz in get_model("clinic.dialyzer").search_browse(dom): + prod=dlz.product_id + if prod.id==product_id: + data['membrane_type']=dlz.membrane_type + data['dialyzer_type']=dlz.dialyzer_type or "low" + data['max_use_time']=dlz.max_use_time or 10 + break return data HDCasePopupDlz.register() diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index d94aeee..0b7c708 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -328,6 +328,24 @@ class Patient(Model): super().delete(ids) def write(self,ids,vals,**kw): + if 'cycles' in vals.keys(): + index=0 + for cvals in vals['cycles']: + mode=cvals[0] + if mode=='delete': + continue + elif mode=='create': + cycle_vals=cvals[1] + elif mode=='write': + continue + cycle_vals=cvals[2] + cdom=[] + for f, v in cycle_vals.items(): + cdom.append([f,'=',v]) + print('cdom ', cdom) + for c in get_model('clinic.patient.cycle').search_browse(cdom): + c.delete() + index+=1 if 'type_id' in vals.keys(): #update patient in hd case which state is condition below for obj in self.browse(ids): diff --git a/netforce_clinic/models/province.py b/netforce_clinic/models/province.py new file mode 100644 index 0000000..a55cbf4 --- /dev/null +++ b/netforce_clinic/models/province.py @@ -0,0 +1,20 @@ +from netforce.model import Model, fields + +class Province(Model): + _inherit="province" + def _get_sort_name(self,ids,context={}): + res={} + for obj in self.browse(ids): + sname='' + if obj.name: + sname=obj.name[0:1] + res[obj.id]=sname + return res + + _fields={ + "name": fields.Char("Name",required=True,search=True,translate=True), + "sort_name": fields.Char("Sort Name",function="_get_sort_name",store=True), + } + _order="sort_name asc" + +Province.register() diff --git a/netforce_clinic/models/report_cycle_item.py b/netforce_clinic/models/report_cycle_item.py index b0326fd..2ca5ba9 100644 --- a/netforce_clinic/models/report_cycle_item.py +++ b/netforce_clinic/models/report_cycle_item.py @@ -97,7 +97,10 @@ class ReportCycleItem(Model): cycles[cycle.id]=[] for line in citem.lines: nurse=line.nurse_id - cycles[cycle.id].append(nurse.name) + cycles[cycle.id].append({ + 'name': nurse.name, + 'first_name': nurse.first_name or "", + }) for hdcase in citem.hd_cases: patient=hdcase.patient_id vascular=patient.vascular_acc @@ -116,11 +119,14 @@ class ReportCycleItem(Model): dlz_use="%sทิ้ง"%dlz_use dlz_drop=True cancel=False + row_color='' if hdcase.state=='cancelled': cancel=True + row_color='#b6b6b6' lines.append({ 'dlz_drop': dlz_drop, 'cancel': cancel, + 'row_color': row_color, 'pname': patient.name or '', 'pid': patient.id or '', 'hn': patient.hn_no, @@ -154,13 +160,38 @@ class ReportCycleItem(Model): elif branch_id: branch=get_model("clinic.branch").browse(branch_id) company_name+=" ("+branch.name+")" - no=1 nlines=[] index=0 old=[] total_fee=0 total_mdc=0 + dates={} + no=0 + count=0 + sub_fee=0 + sub_mdc=0 + pt=0 for line in sorted(lines,key=lambda x:(x['date'],x['cseq'])): + pt+=1 + date=line['date'] or '' + key='%s-%s'%(date,line['cseq']) + if key not in dates.keys(): + no=1 + count=0 + sub_fee=0 + sub_mdc=0 + for x in lines: + if x['cseq']==line['cseq'] and x['date']==date: + sub_fee+=x['fee'] or 0 + sub_mdc+=x['mdc'] or 0 + count+=1 + line['date_txt']=line['date'] + line['cseq_txt']=line['cseq'] + dates[key]=0 + else: + no+=1 + dates[key]+=1 + line['no']=no total_fee+=line.get("fee",0) total_mdc+=line.get("mdc",0) cid=line['cid'] @@ -172,10 +203,17 @@ class ReportCycleItem(Model): cres=cycles[cid] line['nurse']='' if index < len(cres): - line['nurse']=cres[index] - line['no']=no + line['nurse']=cres[index]['name'] + line['nfirst_name']=cres[index]['first_name'] nlines.append(line) - no+=1 + if no==count: + nlines.append({ + 'sub': 'show', + 'row_color': '#dfdfdf', + 'no': count, + 'fee': sub_fee, + 'mdc': sub_mdc, + }) vscl_lines=[] for k,v in vasculars.items(): vscl_lines.append({ @@ -198,6 +236,7 @@ class ReportCycleItem(Model): 'month': month_str, 'date_from': date_from, 'date_to': date_to, + 'total_pt': pt, 'total_fee': total_fee, 'total_mdc': total_mdc, 'total_pt': total_pt, diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py index d150b92..72b71d7 100644 --- a/netforce_clinic/models/setting.py +++ b/netforce_clinic/models/setting.py @@ -161,15 +161,21 @@ class ClinicSetting(Model): if user_id !=1: print("Only admin!!") return - for sline in get_model("clinic.hd.case.staff").search_browse([]): - hdcase=sline.hd_case_id - sline.write({ - 'date': hdcase.date, + for pv in get_model("province").search_browse([]): + name=(pv.name or "")[0:1] + pv.write({ + 'sort_name': name, }) - print('update ', sline.id, hdcase.date) - #obj=self.browse(ids)[0] - #obj.del_duplicate_staff() - #obj.merge_staff() + #for dt in get_model("district").search_browse([]): + #name=(dt.name or "")[0:1] + #dt.write({ + #'sort_name': name, + #}) + #for sdt in get_model("subdistrict").search_browse([]): + #name=(sdt.name or "")[0:1] + #sdt.write({ + #'sort_name': name, + #}) print("Done!") def merge_staff(self,ids,context={}): diff --git a/netforce_clinic/models/subdistrict.py b/netforce_clinic/models/subdistrict.py new file mode 100644 index 0000000..20d963e --- /dev/null +++ b/netforce_clinic/models/subdistrict.py @@ -0,0 +1,21 @@ +from netforce.model import Model, fields + +class SubDistrict(Model): + _inherit="subdistrict" + + def _get_sort_name(self,ids,context={}): + res={} + for obj in self.browse(ids): + sname='' + if obj.name: + sname=obj.name[0:1] + res[obj.id]=sname + return res + + _fields={ + "name": fields.Char("Name",required=True,search=True,translate=True), + "sort_name": fields.Char("Sort Name",function="_get_sort_name",store=True), + } + _order="sort_name asc" + +SubDistrict.register() diff --git a/netforce_clinic/reports/report_cycle_item.xlsx b/netforce_clinic/reports/report_cycle_item.xlsx index fc924f8..58b5d3f 100644 Binary files a/netforce_clinic/reports/report_cycle_item.xlsx and b/netforce_clinic/reports/report_cycle_item.xlsx differ diff --git a/netforce_clinic/reports/report_cycle_item.xlsx.old b/netforce_clinic/reports/report_cycle_item.xlsx.old new file mode 100644 index 0000000..097a62c Binary files /dev/null and b/netforce_clinic/reports/report_cycle_item.xlsx.old differ diff --git a/netforce_clinic/templates/report_cycle_item.hbs b/netforce_clinic/templates/report_cycle_item.hbs index 00a119e..c8fffd2 100644 --- a/netforce_clinic/templates/report_cycle_item.hbs +++ b/netforce_clinic/templates/report_cycle_item.hbs @@ -4,16 +4,16 @@ ระหว่างวันที่ {{date_from}} ถึง {{date_to}} - +
- + - + @@ -22,39 +22,70 @@ {{#each lines }} {{#if cancel}} - + {{else}} {{/if}} - - - + {{#ifeq sub "show"}} + + {{/ifeq}} + {{#if cseq_txt}} + + + - - + + - - - + + {{else}} + {{#ifeq sub "show"}} + + {{else}} + + {{/ifeq}} + + + + + + + + + + + {{/if}} + {{/each}} - - - - - - - - - - - + + + + + + + + + + +
# วันที่ รอบNo ชื่อ-สกุล แพทย์ สิทธ์ จ.น.เงินยาฉีดยาฉีด DZ N/U พยาบาล
{{no}}{{date}}{{cname}}
{{date_txt}}{{cseq_txt}}{{no}} {{pname}} {{dname}} {{tname}}{{fee}}{{mdc}}{{currency fee zero=""}}{{currency mdc zero=""}} {{dlz_name}} {{dlz_use}}View
{{nfirst_name}}รวม{{no}}{{pname}}{{dname}}{{tname}}{{currency fee zero=""}}{{currency mdc}}{{dlz_name}}{{dlz_use}}{{nfirst_name}}
{{currency total_fee zero=""}}{{currency total_mdc}}รวมทั้งหมด{{total_pt}}{{currency total_fee zero=""}}{{currency total_mdc}}
+ + + + {{#each vscl_lines}} + + + {{/each}} + + +
{{description}} = {{qty}}
+