Skip to content

Instantly share code, notes, and snippets.

@jacksmith15
jacksmith15 / django-update.md
Last active January 9, 2019 14:12
Developer report for Django Migration

Django Update Summary

PR-343 Migrates a large part of the Genomic Record codebase to use [Django] and [Django REST Framework]. Both of these frameworks are well-documented, and it is recommended that developers take some time to familiarise themselves.

This migration also changes the directory structure of the project, and it is recommended that developers take a fresh git clone the respository.

The project continues to use the SQLAlchemy ORM, and so a few helpers have been implemented to simplify the integration between [Django Rest Framework] and SQLAlchemy ORM.

app.base.views.BaseAlchemyViewSet

BaseAlchemyViewSet is a subclass of rest_framework.viewsets.ViewSet, designed to provide sensible default behaviour for SQLAlchemy models as resources.

NDMS-1460

Background

Logical model

  • Each referral may have one responsible_clinician
  • Each referral may have many additional_clinicians

API structure

Questions

What to do if a JWT is not supplied:

  • Kong currently enforces JWTs in higher environments
  • In lower environments we rely on the ability to send requests without JWTs for integration testing.
    • This applies to latest and release2.
    • It would be a non-trivial amount of work to overhaul this system (but not out of the question).
  • In all environments we rely on the ability to send requests between services without JWTS.
    • Currently this only includes GET requests (i.e. not editing a referral).
  • In future it may be required that LIMS systems will send requests to edit a referral via this method, but not for beta.

Referral Status API

Handle status transition logic as state in GET

GET /referral/{id}/status

{
    "data": {
        "id": "2b074729-376b-4dfa-963c-39ddbc6a2a2c",
        "code": "draft",
        "display": "Draft",

Clinician change summary

Summary of changes to DDF payload triggered by data model change

Before

  • Clinicians are found as an array of referral_clinicians, under an attribute with the same name.
  • Each referral_clinician contains:
    • a clinician (see below)
    • an organisation_uid reference
    • a referral_clinician_role_uid reference (always null)
  • a referral_uid reference (always the same as the outer referral)

Unique NHS Number

  • How to enforce at the data model layer whilst being compatible with cohorts?
    1. Currently sits in generic identifier table - this is hard to constrain at the model layer.
    2. Could be an attribute on the table - easier to constrain but NHS-specific. Would need to split NHS specific fields using inheritance.
  • How to enforce at the API layer?
    • If (1) above then would need to do an explicit lookup in the serializer to check uniqueness.
    • If (2) above then can use standard handling.
  • How to communicate correct error to UI?
    • This should be a 400 - will need an extra message or code to distinguish.

Overview

This document provides some JSON examples to aid with re-integration of consumers to breaking API changes for patient records brought about by NDMS-1984.

Included are happy path before/after examples for common cases:

  • With and without NHS Number
  • Read and write payloads
  • With and without explicit reason for missing NHS Number

as well as some canonical invalid payloads.

from collections import namedtuple
class ImmutableNamespaceMeta(type):
def __new__(cls, name, bases, dct):
x = super().__new__(cls, name, bases, dct)
public = {key: value for key, value in dct.items() if not key.startswith("_")}
typ_ = namedtuple(name + "Type", public.keys())
return typ_(**public)

Patient Status: Key Actions

Deactivating a patient

  1. Display the available reason concepts for the user to select GET /codes-search/patient_deactivation_reason
{
  "total": 2,
  "limit": 10,
  "offset": 0,

Patient

Request

POST /sample-message/patient

{
  "query": {
    "human_readable_id": [
      "p10001400859"