add get_ward.py
This commit is contained in:
parent
c1acd3de87
commit
db0abd883b
6 changed files with 180 additions and 3 deletions
|
@ -1,8 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. /home/ntuh/d18env/bin/activate
|
PATH=$PATH:/usr/local/bin
|
||||||
|
|
||||||
|
. /opt/conda/etc/profile.d/conda.sh
|
||||||
|
conda activate 2023
|
||||||
|
|
||||||
locale
|
locale
|
||||||
|
|
||||||
cd $(dirname $0)
|
cd $(dirname $0)
|
||||||
python getop.py
|
python get_ward.py
|
||||||
|
|
||||||
|
# #!/bin/bash
|
||||||
|
|
||||||
|
# . /home/ntuh/d18env/bin/activate
|
||||||
|
|
||||||
|
# locale
|
||||||
|
|
||||||
|
# cd $(dirname $0)
|
||||||
|
# python getop.py
|
||||||
|
|
96
ntuh/get_ward.py
Executable file
96
ntuh/get_ward.py
Executable file
|
@ -0,0 +1,96 @@
|
||||||
|
#!/usr/bin/xvfb-run python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'ntuh.settings'
|
||||||
|
|
||||||
|
import django
|
||||||
|
django.setup()
|
||||||
|
|
||||||
|
|
||||||
|
from dateutil.relativedelta import *
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
|
||||||
|
from django.db.models import *
|
||||||
|
|
||||||
|
from ntuhgov.portal_selenium import Login, QueryInPatientByWard
|
||||||
|
from registry.models import *
|
||||||
|
|
||||||
|
import logging
|
||||||
|
FORMAT = '%(asctime)s %(levelname)s %(message)s'
|
||||||
|
logging.basicConfig(format=FORMAT, level=logging.INFO)
|
||||||
|
|
||||||
|
def ScanWard(ward='08D'):
|
||||||
|
logging.info('Scan %s' % (ward))
|
||||||
|
list = QueryInPatientByWard(ward)
|
||||||
|
TIME = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||||
|
|
||||||
|
for Pat in list:
|
||||||
|
# logging.warning(json.dumps(Pat, indent=1))
|
||||||
|
|
||||||
|
BedID = '%s-%s-%s' % (Pat['WardLabel'], Pat['RoomLabel'], Pat['BedLabel'])
|
||||||
|
BedTime = '%s_%s' % (BedID, TIME)
|
||||||
|
# logging.info('%s %s'%(BedTime,Pat['PatChartNo']))
|
||||||
|
# lat = InpatientLog.objects.filter(BedID=BedID).latest('Created')
|
||||||
|
# print(lat.ChartNo)
|
||||||
|
|
||||||
|
try:
|
||||||
|
lat = InpatientLog.objects.filter(BedID=BedID).latest('Created')
|
||||||
|
except:
|
||||||
|
lat = None
|
||||||
|
|
||||||
|
if lat is None or lat.ChartNo != Pat['PatChartNo']:
|
||||||
|
logging.info('create %s %s'%(BedTime,Pat['PatChartNo']))
|
||||||
|
# print(len(BedTime))
|
||||||
|
p = InpatientLog.objects.create(BedTime = BedTime)
|
||||||
|
p.Ward = Pat['WardLabel']
|
||||||
|
p.Room = Pat['RoomLabel']
|
||||||
|
p.Bed = Pat['BedLabel']
|
||||||
|
p.Name = Pat['LinkPatientName']
|
||||||
|
p.ChartNo = Pat['PatChartNo']
|
||||||
|
p.Sex = Pat['PatientSex']
|
||||||
|
if 'PatientAgeTitle' in Pat: # 'PatientAge': '待確認'
|
||||||
|
p.Birthday = Pat['PatientAgeTitle'][-10:].replace('_', '-')
|
||||||
|
p.Age = Pat['PatientAge']
|
||||||
|
p.HospitalDays = Pat[u'住院總天數'][:-1]
|
||||||
|
p.Enter = Pat[u'入'].replace('/', '-')
|
||||||
|
|
||||||
|
p.BedID = BedID
|
||||||
|
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
else:
|
||||||
|
logging.info('skip %s %s'%(BedTime,Pat['PatChartNo']))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
continue
|
||||||
|
# print json.dumps(Pat, ensure_ascii=False, indent=1)
|
||||||
|
# logging.info(Pat)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
p, created = Inpatient.objects.get_or_create(ChartNo = Pat['PatChartNo'])
|
||||||
|
p.Ward = Pat['WardLabel']
|
||||||
|
p.Room = Pat['RoomLabel']
|
||||||
|
p.Bed = Pat['BedLabel']
|
||||||
|
p.Name = Pat['LinkPatientName']
|
||||||
|
# p.ChartNo = Pat['ChartNo']
|
||||||
|
p.Sex = Pat['PatientSex']
|
||||||
|
if 'PatientAgeTitle' in Pat: # 'PatientAge': '待確認'
|
||||||
|
p.Birthday = Pat['PatientAgeTitle'][-10:].replace('_', '-')
|
||||||
|
p.Age = Pat['PatientAge']
|
||||||
|
p.HospitalDays = Pat[u'住院總天數'][:-1]
|
||||||
|
p.Enter = Pat[u'入'].replace('/', '-')
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ScanWard()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main() # 或是任何你想執行的函式
|
32
ntuh/registry/migrations/0004_inpatientlog.py
Normal file
32
ntuh/registry/migrations/0004_inpatientlog.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# Generated by Django 4.1 on 2024-12-12 13:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('registry', '0003_auto_20240529_1440'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='InpatientLog',
|
||||||
|
fields=[
|
||||||
|
('Ward', models.CharField(max_length=10, null=True)),
|
||||||
|
('Room', models.CharField(max_length=10, null=True)),
|
||||||
|
('Bed', models.CharField(max_length=10, null=True)),
|
||||||
|
('Name', models.CharField(max_length=50, null=True)),
|
||||||
|
('ChartNo', models.CharField(max_length=10)),
|
||||||
|
('Sex', models.CharField(max_length=10, null=True)),
|
||||||
|
('Birthday', models.DateField(null=True)),
|
||||||
|
('Age', models.CharField(max_length=10, null=True)),
|
||||||
|
('HospitalDays', models.IntegerField(null=True)),
|
||||||
|
('Enter', models.DateField(null=True)),
|
||||||
|
('BedID', models.CharField(max_length=10, null=True)),
|
||||||
|
('BedTime', models.CharField(max_length=10, primary_key=True, serialize=False)),
|
||||||
|
('Created', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('Saved', models.DateTimeField(auto_now=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
18
ntuh/registry/migrations/0005_alter_inpatientlog_bedtime.py
Normal file
18
ntuh/registry/migrations/0005_alter_inpatientlog_bedtime.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.1 on 2024-12-12 13:31
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('registry', '0004_inpatientlog'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='inpatientlog',
|
||||||
|
name='BedTime',
|
||||||
|
field=models.CharField(max_length=30, primary_key=True, serialize=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -64,6 +64,25 @@ class Inpatient(models.Model):
|
||||||
Created = models.DateTimeField(auto_now_add = True)
|
Created = models.DateTimeField(auto_now_add = True)
|
||||||
Saved = models.DateTimeField(auto_now = True)
|
Saved = models.DateTimeField(auto_now = True)
|
||||||
|
|
||||||
|
class InpatientLog(models.Model):
|
||||||
|
Ward = models.CharField(max_length=10, null=True)
|
||||||
|
Room = models.CharField(max_length=10, null=True)
|
||||||
|
Bed = models.CharField(max_length=10, null=True)
|
||||||
|
Name = models.CharField(max_length=50, null=True)
|
||||||
|
ChartNo = models.CharField(max_length=10)
|
||||||
|
Sex = models.CharField(max_length=10, null=True)
|
||||||
|
Birthday = models.DateField(null=True)
|
||||||
|
Age = models.CharField(max_length=10, null=True)
|
||||||
|
HospitalDays = models.IntegerField(null=True)
|
||||||
|
Enter = models.DateField(null=True)
|
||||||
|
|
||||||
|
BedID = models.CharField(max_length=10, null=True)
|
||||||
|
BedTime = models.CharField(max_length=30, primary_key=True)
|
||||||
|
|
||||||
|
Created = models.DateTimeField(auto_now_add = True)
|
||||||
|
Saved = models.DateTimeField(auto_now = True)
|
||||||
|
|
||||||
|
|
||||||
class Physician(models.Model):
|
class Physician(models.Model):
|
||||||
Name = models.CharField(max_length=10)
|
Name = models.CharField(max_length=10)
|
||||||
EmployeeID = models.CharField(max_length=10, primary_key=True)
|
EmployeeID = models.CharField(max_length=10, primary_key=True)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 979423478440452fc1b7b5ffc1b5b80bc98a7f3b
|
Subproject commit d7c69765c6df0fd63312cb5b7a52b74f2f337272
|
Loading…
Reference in a new issue