matching hdcase
							parent
							
								
									6897215ab2
								
							
						
					
					
						commit
						7a979d17bd
					
				| 
						 | 
					@ -1,9 +1,7 @@
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
from calendar import monthrange
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from netforce.model import Model, fields, get_model
 | 
					from netforce.model import Model, fields, get_model
 | 
				
			||||||
from netforce.utils import get_file_path
 | 
					from netforce.utils import get_file_path
 | 
				
			||||||
from . import utils
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MatchingHDCase(Model):
 | 
					class MatchingHDCase(Model):
 | 
				
			||||||
    _name="clinic.matching.hdcase"
 | 
					    _name="clinic.matching.hdcase"
 | 
				
			||||||
| 
						 | 
					@ -57,10 +55,11 @@ class MatchingHDCase(Model):
 | 
				
			||||||
        return rows
 | 
					        return rows
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_report_data(self,ids,context={}):
 | 
					    def get_report_data(self,ids,context={}):
 | 
				
			||||||
        lines=[]
 | 
					 | 
				
			||||||
        hdcases={}
 | 
					        hdcases={}
 | 
				
			||||||
 | 
					        date=time.strftime("%Y-%m-%d")
 | 
				
			||||||
        if ids:
 | 
					        if ids:
 | 
				
			||||||
            obj=self.browse(ids)[0]
 | 
					            obj=self.browse(ids)[0]
 | 
				
			||||||
 | 
					            date=obj.date
 | 
				
			||||||
            if obj.file:
 | 
					            if obj.file:
 | 
				
			||||||
                fpath=get_file_path(obj.file)
 | 
					                fpath=get_file_path(obj.file)
 | 
				
			||||||
                rows=self.get_rows(fpath)
 | 
					                rows=self.get_rows(fpath)
 | 
				
			||||||
| 
						 | 
					@ -89,11 +88,12 @@ class MatchingHDCase(Model):
 | 
				
			||||||
                 #20: ' U '}
 | 
					                 #20: ' U '}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                patients={}
 | 
					                patients={}
 | 
				
			||||||
                for pt in get_model("clinic.patient").search_read([],['name','hn_no']):
 | 
					                for pt in get_model("clinic.patient").search_read([],['name','hn_no','type_id']):
 | 
				
			||||||
                    hn=pt['hn_no']
 | 
					                    hn=pt['hn_no']
 | 
				
			||||||
                    patients[hn]={
 | 
					                    patients[hn]={
 | 
				
			||||||
                        'id': pt['id'],
 | 
					                        'id': pt['id'],
 | 
				
			||||||
                        'name': pt['name'] or '',
 | 
					                        'name': pt['name'] or '',
 | 
				
			||||||
 | 
					                        'type': pt['type_id'][1],
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                products={}
 | 
					                products={}
 | 
				
			||||||
                for prod in get_model("product").search_read([],['name']):
 | 
					                for prod in get_model("product").search_read([],['name']):
 | 
				
			||||||
| 
						 | 
					@ -105,28 +105,40 @@ class MatchingHDCase(Model):
 | 
				
			||||||
                dom.append(['date',"<=",obj.date])
 | 
					                dom.append(['date',"<=",obj.date])
 | 
				
			||||||
                dom.append(['state','!=','cancelled'])
 | 
					                dom.append(['state','!=','cancelled'])
 | 
				
			||||||
                hdcases={}
 | 
					                hdcases={}
 | 
				
			||||||
 | 
					                hdcases2={}
 | 
				
			||||||
                for hdcase in get_model("clinic.hd.case").search_browse(dom):
 | 
					                for hdcase in get_model("clinic.hd.case").search_browse(dom):
 | 
				
			||||||
                    date=hdcase.date
 | 
					                    date=hdcase.date
 | 
				
			||||||
                    hn=hdcase.patient_id.hn_no or 0
 | 
					                    hn=hdcase.patient_id.hn_no or 0
 | 
				
			||||||
                    fee_amt=0
 | 
					                    fee_amt=0
 | 
				
			||||||
 | 
					                    hct=hdcase.hct or "0"
 | 
				
			||||||
 | 
					                    hct=round(float(hct),2)
 | 
				
			||||||
 | 
					                    prod_line=[]
 | 
				
			||||||
                    for line in hdcase.lines:
 | 
					                    for line in hdcase.lines:
 | 
				
			||||||
                        prod=line.product_id 
 | 
					                        prod=line.product_id 
 | 
				
			||||||
                        categ=prod.categ_id
 | 
					                        categ=prod.categ_id
 | 
				
			||||||
                        prod_line=[]
 | 
					                        if categ and line.reimbursable=='yes':
 | 
				
			||||||
                        if categ:
 | 
					 | 
				
			||||||
                            if categ.code=='EPO':
 | 
					                            if categ.code=='EPO':
 | 
				
			||||||
                                prod_line.append(prod.name)
 | 
					                                prod_line.append((prod.name or "").upper())
 | 
				
			||||||
                            elif categ.code=='FEE':
 | 
					                            elif categ.code=='FEE':
 | 
				
			||||||
                                fee_amt=line.amount or 0
 | 
					                                fee_amt=line.amount or 0
 | 
				
			||||||
                    prod_name=','.join(prod_line)
 | 
					                    prod_name=','.join(prod_line)
 | 
				
			||||||
                    key='%s-%s-%s-%s'%(date,hn,prod_name,fee_amt)
 | 
					                    key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name,fee_amt)
 | 
				
			||||||
                    hdcases[key]={
 | 
					                    hdcases[key1]={
 | 
				
			||||||
                        'id': hdcase.id,
 | 
					                        'id': hdcase.id,
 | 
				
			||||||
                        'number': hdcase.number or ''
 | 
					                        'number': hdcase.number or '',
 | 
				
			||||||
 | 
					                        'note': '',
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    key2='%s-%s'%(date,hn)
 | 
				
			||||||
 | 
					                    hdcases2[key2]={
 | 
				
			||||||
 | 
					                        'id': hdcase.id,
 | 
				
			||||||
 | 
					                        'number': hdcase.number or '',
 | 
				
			||||||
 | 
					                        'note': '%s, %s, %s, %s, %s'%(date,hn,hct,prod_name,fee_amt),
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                lines=[]
 | 
				
			||||||
                for row in rows:
 | 
					                for row in rows:
 | 
				
			||||||
                    vals=list(row.values())
 | 
					                    vals=list(row.values())
 | 
				
			||||||
                    date,time=(vals[5] or "").split()
 | 
					                    date,_time=(vals[5] or "").split()
 | 
				
			||||||
                    if len(date)<3:
 | 
					                    if len(date)<3:
 | 
				
			||||||
                        raise Exception("Wrong format date")
 | 
					                        raise Exception("Wrong format date")
 | 
				
			||||||
                    d,m,y=date.split("/")
 | 
					                    d,m,y=date.split("/")
 | 
				
			||||||
| 
						 | 
					@ -135,39 +147,47 @@ class MatchingHDCase(Model):
 | 
				
			||||||
                    hn=vals[3]
 | 
					                    hn=vals[3]
 | 
				
			||||||
                    hn=''.join(x for x in (hn or "") if x.isdigit())
 | 
					                    hn=''.join(x for x in (hn or "") if x.isdigit())
 | 
				
			||||||
                    pt=patients.get(hn)
 | 
					                    pt=patients.get(hn)
 | 
				
			||||||
 | 
					                    pt_type=''
 | 
				
			||||||
                    pt_name=''
 | 
					                    pt_name=''
 | 
				
			||||||
                    pt_id=None
 | 
					                    pt_id=None
 | 
				
			||||||
                    if pt:
 | 
					                    if pt:
 | 
				
			||||||
                        pt_name=pt['name']
 | 
					                        pt_name=pt['name']
 | 
				
			||||||
                        pt_id=pt['id']
 | 
					                        pt_id=pt['id']
 | 
				
			||||||
                    hct=vals[12] or 0
 | 
					                        pt_type=pt['type']
 | 
				
			||||||
 | 
					                    hct=float(vals[12] or "0")
 | 
				
			||||||
 | 
					                    hct=round(hct,2)
 | 
				
			||||||
                    fee_amt=float(vals[15] or "0")
 | 
					                    fee_amt=float(vals[15] or "0")
 | 
				
			||||||
 | 
					                    fee_amt=round(fee_amt,2)
 | 
				
			||||||
                    prod_name=vals[10] or ''
 | 
					                    prod_name=vals[10] or ''
 | 
				
			||||||
                    prod_name=prod_name.replace(" ", "")
 | 
					                    prod_name=prod_name.replace(" ", "")
 | 
				
			||||||
                    prod_id=products.get(prod_name.upper(),None)
 | 
					                    prod_id=products.get(prod_name.upper(),None)
 | 
				
			||||||
                    hd_case_id=None
 | 
					                    key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name.upper(),fee_amt)
 | 
				
			||||||
                    hd_case_number=""
 | 
					                    hdcase=hdcases.get(key1)
 | 
				
			||||||
                    key='%s-%s-%s-%s'%(date,hn,prod_name,fee_amt)
 | 
					                    line_vals={
 | 
				
			||||||
                    if hn=='10073353':
 | 
					 | 
				
			||||||
                        print('key ', key)
 | 
					 | 
				
			||||||
                        #import pdb; pdb.set_trace()
 | 
					 | 
				
			||||||
                    hdcase=hdcases.get(key)
 | 
					 | 
				
			||||||
                    if hdcase:
 | 
					 | 
				
			||||||
                        hd_case_id=hdcase['id']
 | 
					 | 
				
			||||||
                        hd_case_number=hdcase['number']
 | 
					 | 
				
			||||||
                    vals={
 | 
					 | 
				
			||||||
                        'hn': hn,
 | 
					                        'hn': hn,
 | 
				
			||||||
                        'date': date,
 | 
					                        'date': date,
 | 
				
			||||||
                        'patient_name': pt_name,
 | 
					                        'patient_name': pt_name,
 | 
				
			||||||
                        'patient_id': pt_id,
 | 
					                        'patient_id': pt_id,
 | 
				
			||||||
 | 
					                        'patient_type': pt_type,
 | 
				
			||||||
                        'hct': hct,
 | 
					                        'hct': hct,
 | 
				
			||||||
                        'prod_name': prod_name, 
 | 
					                        'prod_name': prod_name, 
 | 
				
			||||||
                        'prod_id': prod_id,
 | 
					                        'prod_id': prod_id,
 | 
				
			||||||
                        'fee_amt': fee_amt,
 | 
					                        'fee_amt': fee_amt,
 | 
				
			||||||
                        'hd_case_id': hd_case_id,
 | 
					                        'note': '',
 | 
				
			||||||
                        'hd_case_number': hd_case_number,
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    lines.append(vals)
 | 
					                    if hdcase:
 | 
				
			||||||
 | 
					                        line_vals['is_match']=True
 | 
				
			||||||
 | 
					                        line_vals['hd_case_id']=hdcase['id']
 | 
				
			||||||
 | 
					                        line_vals['hd_case_number']=hdcase['number']
 | 
				
			||||||
 | 
					                    else:
 | 
				
			||||||
 | 
					                        key2='%s-%s'%(date,hn)
 | 
				
			||||||
 | 
					                        hdcase2=hdcases2.get(key2)
 | 
				
			||||||
 | 
					                        if hdcase2:
 | 
				
			||||||
 | 
					                            line_vals['is_match']=False
 | 
				
			||||||
 | 
					                            line_vals['hd_case_id']=hdcase2['id']
 | 
				
			||||||
 | 
					                            line_vals['hd_case_number']=hdcase2['number']
 | 
				
			||||||
 | 
					                            line_vals['note']=hdcase2['note']
 | 
				
			||||||
 | 
					                    lines.append(line_vals)
 | 
				
			||||||
        no=1
 | 
					        no=1
 | 
				
			||||||
        lines2=[]
 | 
					        lines2=[]
 | 
				
			||||||
        for line in sorted(lines,key=lambda x: x['hn']):
 | 
					        for line in sorted(lines,key=lambda x: x['hn']):
 | 
				
			||||||
| 
						 | 
					@ -177,6 +197,7 @@ class MatchingHDCase(Model):
 | 
				
			||||||
        lines=lines2
 | 
					        lines=lines2
 | 
				
			||||||
        data={
 | 
					        data={
 | 
				
			||||||
            'lines': lines,
 | 
					            'lines': lines,
 | 
				
			||||||
 | 
					            'date': date,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return data
 | 
					        return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -4,10 +4,12 @@
 | 
				
			||||||
        <th>Date</th>
 | 
					        <th>Date</th>
 | 
				
			||||||
        <th>HN</th>
 | 
					        <th>HN</th>
 | 
				
			||||||
        <th>Patient</th>
 | 
					        <th>Patient</th>
 | 
				
			||||||
 | 
					        <th>Type</th>
 | 
				
			||||||
        <th>HCT</th>
 | 
					        <th>HCT</th>
 | 
				
			||||||
        <th>Product</th>
 | 
					        <th>EPO</th>
 | 
				
			||||||
        <th>Fee Amount</th>
 | 
					        <th>Fee Amount</th>
 | 
				
			||||||
        <th>HD Case</th>
 | 
					        <th>HD Case</th>
 | 
				
			||||||
 | 
					        <th>Note (fmt: date,hn,hct,epo,fee)</th>
 | 
				
			||||||
    </thead>
 | 
					    </thead>
 | 
				
			||||||
    <tbody>
 | 
					    <tbody>
 | 
				
			||||||
        {{#each lines }}
 | 
					        {{#each lines }}
 | 
				
			||||||
| 
						 | 
					@ -15,19 +17,29 @@
 | 
				
			||||||
                    <td>{{no}}</td>
 | 
					                    <td>{{no}}</td>
 | 
				
			||||||
                    <td>{{date}}</td>
 | 
					                    <td>{{date}}</td>
 | 
				
			||||||
                    <td>{{hn}}</td>
 | 
					                    <td>{{hn}}</td>
 | 
				
			||||||
                    <td>{{patient_name}}</td>
 | 
					                    {{#if patient_id}}
 | 
				
			||||||
 | 
					                        <td style="width:15%;">{{view "link" string=patient_name action="clinic_patient" action_options="mode=form" active_id=patient_id}}</td>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <td style="width: 15%">{{patient_name}}</td>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
 | 
					                    <td>{{patient_type}}</td>
 | 
				
			||||||
                    <td>{{hct}}</td>
 | 
					                    <td>{{hct}}</td>
 | 
				
			||||||
                    {{#if prod_id}}
 | 
					                    {{#if prod_id}}
 | 
				
			||||||
                        <td>{{view "link" string=prod_name action="product" action_options="mode=form" active_id=prod_id}}</td>
 | 
					                        <td>{{view "link" string=prod_name action="product" action_options="mode=form" active_id=prod_id}}</td>
 | 
				
			||||||
                    {{else}}
 | 
					                    {{else}}
 | 
				
			||||||
                        <td>{{prod_name}}</td>
 | 
					                        <td>{{prod_name}}</td>
 | 
				
			||||||
                    {{/if}}
 | 
					                    {{/if}}
 | 
				
			||||||
                    <td>{{fee_amt}}</td>
 | 
					                    <td>{{currency fee_amt zero=""}}</td>
 | 
				
			||||||
                    {{#if hd_case_id}}
 | 
					                    {{#if is_match}}
 | 
				
			||||||
                        <td style="background-color;#4daa35;color:white">{{view "link" string=hd_case_number action="clinic_hd_case" action_options="mode=form" active_id=hd_case_id}}</td>
 | 
					                        <td style="background-color:#4daa35;width:8%;">
 | 
				
			||||||
 | 
					                            <a style="color:white" href="/ui#name=clinic_hd_case&mode=form&active_id={{hd_case_id}}">{{hd_case_number}}</a>
 | 
				
			||||||
 | 
					                        </td>
 | 
				
			||||||
                    {{else}}
 | 
					                    {{else}}
 | 
				
			||||||
                        <td>{{hd_case_number}}</td>
 | 
					                        <td style="background-color:#b9b9b7;width:8%;">
 | 
				
			||||||
 | 
					                            <a style="color:white" href="/ui#name=clinic_hd_case&mode=form&active_id={{hd_case_id}}">{{hd_case_number}}</a>
 | 
				
			||||||
 | 
					                        </td>
 | 
				
			||||||
                    {{/if}}
 | 
					                    {{/if}}
 | 
				
			||||||
 | 
					                    <td>{{note}}</td>
 | 
				
			||||||
                </tr>
 | 
					                </tr>
 | 
				
			||||||
        {{/each}}
 | 
					        {{/each}}
 | 
				
			||||||
    </tbody>
 | 
					    </tbody>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue