Skip to content

Instantly share code, notes, and snippets.

@fredkingham
fredkingham / load_transfer_histories.py
Created October 17, 2022 10:25
load transfer histories
import datetime
from django.utils import timezone
from django.db import transaction
from intrahospital_api.apis.prod_api import ProdApi as ProdAPI
from elcid.models import Demographics
from plugins.admissions import loader
import csv, os
from plugins.admissions.models import TransferHistory
from elcid.episode_categories import InfectionService
from intrahospital_api.loader import create_rfh_patient_from_hospital_number
import csv
import datetime
from opal.core import subrecords
from django.db.models import Count, Max
from opal.models import Patient
def subrecords_to_extract(subrecords):
result = []
for subrecord in subrecords:
@fredkingham
fredkingham / parse_ipc_page.py
Last active September 29, 2021 16:46
requires pyquery
from pyquery import PyQuery as pq
import json
import io
FILE_NAME = "IPC_GT_5_Years.htm"
def process():
with io.open("IPC_GT_5_Years.htm", mode="r", encoding="utf-8", errors='ignore') as f:
contents = f.read()
import datetime
from odonto.episode_categories import FP17OEpisode, FP17Episode
SEND_ALL_AFTER_DATE = datetime.date(2020, 4, 1)
def get_rejections():
rejected_fp17s = FP17Episode.get_rejected_episodes()
rejected_fp17s = [
i for i in rejected_fp17s if i.category.get_sign_off_date() > SEND_ALL_AFTER_DATE
import datetime
from plugins.labtests.models import LabTest
from opal.models import Patient
from elcid.utils import timing
from intrahospital_api.apis.prod_api import ProdApi as ProdAPI
from django.utils import timezone
from plugins.appointments.models import Appointment
from plugins.tb import episode_categories, constants
from plugins.tb.models import PatientConsultation
import datetime
import time
from django.utils import timezone
from opal.models import Episode
from odonto import episode_categories
from odonto.odonto_submissions.models import Submission
def delete_and_resend():
episodes = Episode.objects.filter(
@fredkingham
fredkingham / search_rule.py
Created October 22, 2020 12:43
Proposal for a new search rule system
# The problem is that...
# 1. We cannot search models such as Lab tests or appointments
# 2. We cannot remove models such as Episode that are in opal models
#
# This solution mostly solves 1, however I think we should implement a discoverable remove method
# and then the solution includes the other.
#
# This method moves the query logic onto a search rule class, patient summary generation etc would be
# elsewhere by the query backend.
#
class Fp17ClinicalDataSetSerializer(TreatmentSerializer):
model = models.Fp17ClinicalDataSet
TREATMENT_MAPPINGS = OrderedDict(
[
("examination", t.EXAMINATION),
("scale_and_polish", t.SCALE_AND_POLISH),
("fluoride_varnish", t.FLUORIDE_VARNISH),
("fissure_sealants", t.FISSURE_SEALANTS),
("radiographs_taken", t.RADIOGRAPHS),
@fredkingham
fredkingham / fire_blood_book.py
Created September 3, 2020 14:52
FIRE Blood book
class RBHLMetaTestFields(object):
method = CharField()
exposures = CharField()
antigen_type = CharField()
# what the blood book is using as a hospital number
reference_number = CharField()
@fredkingham
fredkingham / test_api_end_points.py
Created August 16, 2020 16:41
A quick script to check the api end points for the last 100 patients
import time
from django.test.client import RequestFactory
from rest_framework.test import force_authenticate
from django.contrib.auth.models import User
from rest_framework.reverse import reverse
from opal.models import Patient
from elcid.api import InfectionServiceTestSummaryApi, LabTestResultsView
from plugins.covid.api import CovidServiceTestSummaryAPI