vital-software/scala-redox

View on GitHub
src/test/scala/com/github/vitalsoftware/scalaredox/OrderTest.scala

Summary

Maintainability
B
5 hrs
Test Coverage
package com.github.vitalsoftware.scalaredox

import com.github.vitalsoftware.scalaredox.client.EmptyResponse
import com.github.vitalsoftware.scalaredox.models.OrderMessage
import org.specs2.mutable.Specification

/**
 * Created by apatzer on 3/23/17.
 */
class OrderTest extends Specification with RedoxTest {
  "alter Orders" should {
    "post a new Order" in {
      val json =
        """
          |{
          |   "Meta": {
          |      "DataModel": "Order",
          |      "EventType": "New",
          |      "EventDateTime": "2017-10-10T15:07:21.362Z",
          |      "Test": true,
          |      "Source": {
          |         "ID": "7ce6f387-c33c-417d-8682-81e83628cbd9",
          |         "Name": "Redox Dev Tools"
          |      },
          |      "Destinations": [
          |         {
          |            "ID": "af394f14-b34a-464f-8d24-895f370af4c9",
          |            "Name": "Redox EMR"
          |         }
          |      ],
          |      "Message": {
          |         "ID": 5565
          |      },
          |      "Transmission": {
          |         "ID": 12414
          |      },
          |      "FacilityCode": null
          |   },
          |   "Patient": {
          |      "Identifiers": [
          |         {
          |            "ID": "0000000001",
          |            "IDType": "MR"
          |         },
          |         {
          |            "ID": "e167267c-16c9-4fe3-96ae-9cff5703e90a",
          |            "IDType": "EHRID"
          |         },
          |         {
          |            "ID": "a1d4ee8aba494ca",
          |            "IDType": "NIST"
          |         }
          |      ],
          |      "Demographics": {
          |         "FirstName": "Timothy",
          |         "MiddleName": "Paul",
          |         "LastName": "Bixby",
          |         "DOB": "2008-01-06",
          |         "SSN": "101-01-0001",
          |         "Sex": "Male",
          |         "Race": "Asian",
          |         "IsHispanic": null,
          |         "MaritalStatus": "Single",
          |         "IsDeceased": null,
          |         "DeathDateTime": null,
          |         "PhoneNumber": {
          |            "Home": "+18088675301",
          |            "Office": null,
          |            "Mobile": null
          |         },
          |         "EmailAddresses": [],
          |         "Language": "en",
          |         "Citizenship": [],
          |         "Address": {
          |            "StreetAddress": "4762 Hickory Street",
          |            "City": "Monroe",
          |            "State": "WI",
          |            "ZIP": "53566",
          |            "County": "Green",
          |            "Country": "US"
          |         }
          |      },
          |      "Notes": []
          |   },
          |   "Visit": {
          |      "VisitNumber": "1234",
          |      "AttendingProvider": {
          |         "ID": "4356789876",
          |         "IDType": "NPI",
          |         "FirstName": "Pat",
          |         "LastName": "Granite",
          |         "Credentials": [
          |            "MD"
          |         ],
          |         "Address": {
          |            "StreetAddress": "123 Main St.",
          |            "City": "Madison",
          |            "State": "WI",
          |            "ZIP": "53703",
          |            "County": "Dane",
          |            "Country": "USA"
          |         },
          |         "Location": {
          |            "Type": null,
          |            "Facility": null,
          |            "Department": null,
          |            "Room": null
          |         },
          |         "PhoneNumber": {
          |            "Office": "+16085551234"
          |         }
          |      },
          |      "ConsultingProvider": {
          |         "ID": "2434534567",
          |         "IDType": "NPI",
          |         "FirstName": "Sharon",
          |         "LastName": "Chalk",
          |         "Credentials": [
          |            "MD",
          |            "PhD"
          |         ],
          |         "Address": {
          |            "StreetAddress": "312 Maple Dr. Suite 400",
          |            "City": "Verona",
          |            "State": "WI",
          |            "ZIP": "53593",
          |            "County": "Dane",
          |            "Country": "USA"
          |         },
          |         "Location": {
          |            "Type": null,
          |            "Facility": null,
          |            "Department": null,
          |            "Room": null
          |         },
          |         "PhoneNumber": {
          |            "Office": "+16085559999"
          |         }
          |      },
          |      "ReferringProvider": {
          |         "ID": "4236464757",
          |         "IDType": "NPI",
          |         "FirstName": "John",
          |         "LastName": "Slate",
          |         "Credentials": [
          |            "DO"
          |         ],
          |         "Address": {
          |            "StreetAddress": "500 First St.",
          |            "City": "Clayton",
          |            "State": "MO",
          |            "ZIP": "63105",
          |            "County": "Saint Louis",
          |            "Country": "USA"
          |         },
          |         "Location": {
          |            "Type": null,
          |            "Facility": null,
          |            "Department": null,
          |            "Room": null
          |         },
          |         "PhoneNumber": {
          |            "Office": "+13145554321"
          |         }
          |      },
          |      "Guarantor": {
          |         "Number": "10001910",
          |         "FirstName": "Kent",
          |         "LastName": "Bixby",
          |         "DOB": null,
          |         "Sex": null,
          |         "Spouse": {
          |            "FirstName": "Barbara",
          |            "LastName": "Bixby"
          |         },
          |         "Address": {
          |            "StreetAddress": "4762 Hickory Street",
          |            "City": "Monroe",
          |            "State": "WI",
          |            "ZIP": "53566",
          |            "County": "Green",
          |            "Country": "USA"
          |         },
          |         "PhoneNumber": {
          |            "Home": null,
          |            "Business": null
          |         },
          |         "Type": null,
          |         "RelationToPatient": "Father",
          |         "Employer": {
          |            "Name": "Accelerator Labs",
          |            "Address": {
          |               "StreetAddress": "1456 Old Sauk Road",
          |               "City": "Madison",
          |               "State": "WI",
          |               "ZIP": "53719",
          |               "County": "Dane",
          |               "Country": "USA"
          |            },
          |            "PhoneNumber": "+18083451121"
          |         }
          |      },
          |      "Insurances": [
          |         {
          |            "Plan": {
          |               "ID": "31572",
          |               "IDType": "Payor ID",
          |               "Name": "HMO Deductable Plan",
          |               "Type": null
          |            },
          |            "MemberNumber": null,
          |            "Company": {
          |               "ID": "60054",
          |               "IDType": null,
          |               "Name": "aetna (60054 0131)",
          |               "Address": {
          |                  "StreetAddress": "PO Box 14080",
          |                  "City": "Lexington",
          |                  "State": "KY",
          |                  "ZIP": "40512-4079",
          |                  "County": "Fayette",
          |                  "Country": "US"
          |               },
          |               "PhoneNumber": "+18089541123"
          |            },
          |            "GroupNumber": "847025-024-0009",
          |            "GroupName": "Accelerator Labs",
          |            "EffectiveDate": "2015-01-01",
          |            "ExpirationDate": "2020-12-31",
          |            "PolicyNumber": "9140860055",
          |            "AgreementType": null,
          |            "CoverageType": null,
          |            "Insured": {
          |               "LastName": null,
          |               "FirstName": null,
          |               "Relationship": null,
          |               "DOB": null,
          |               "Address": {
          |                  "StreetAddress": null,
          |                  "City": null,
          |                  "State": null,
          |                  "ZIP": null,
          |                  "County": null,
          |                  "Country": null
          |               }
          |            }
          |         }
          |      ],
          |      "Location": {
          |         "Type": "Inpatient",
          |         "Facility": "RES General Hospital",
          |         "Department": "3N",
          |         "Room": "136"
          |      }
          |   },
          |   "Order": {
          |      "ID": "157968300",
          |      "TransactionDateTime": "2015-05-06T06:00:58.872Z",
          |      "CollectionDateTime": "2015-05-06T06:00:58.872Z",
          |      "Specimen": {
          |         "Source": null,
          |         "BodySite": null,
          |         "ID": null
          |      },
          |      "Procedure": {
          |         "Code": "49086-2",
          |         "Codeset": null,
          |         "Description": "First trimester maternal screen with nuchal translucency panel"
          |      },
          |      "Provider": {
          |         "NPI": "4356789876",
          |         "FirstName": "Pat",
          |         "LastName": "Granite",
          |         "Credentials": [
          |            "MD"
          |         ],
          |         "Address": {
          |            "StreetAddress": "123 Main St.",
          |            "City": "Madison",
          |            "State": "WI",
          |            "ZIP": "53703",
          |            "County": "Dane",
          |            "Country": "USA"
          |         },
          |         "Location": {
          |            "Type": null,
          |            "Facility": null,
          |            "Department": null,
          |            "Room": null
          |         },
          |         "PhoneNumber": {
          |            "Office": "+16085551234"
          |         }
          |      },
          |      "OrderingFacility": {
          |         "Name": null,
          |         "Address": {
          |            "StreetAddress": null,
          |            "City": null,
          |            "State": null,
          |            "ZIP": null,
          |            "County": null,
          |            "Country": null
          |         },
          |         "PhoneNumber": null
          |      },
          |      "Priority": "Stat",
          |      "Expiration": null,
          |      "Comments": null,
          |      "Notes": [],
          |      "Diagnoses": [
          |         {
          |            "Code": "Z31.41",
          |            "Codeset": "ICD-10",
          |            "Name": "Encounter for fertility testing",
          |            "Type": null
          |         }
          |      ],
          |      "ClinicalInfo": [
          |         {
          |            "Code": "QUESTION001",
          |            "Codeset": null,
          |            "Description": "Estimated Due Date",
          |            "Value": "2015-10-05",
          |            "Units": null,
          |            "Abbreviation": null,
          |            "Notes": []
          |         },
          |         {
          |            "Code": "QUESTION002",
          |            "Codeset": null,
          |            "Description": "Ethnicity",
          |            "Value": "White",
          |            "Units": null,
          |            "Abbreviation": "W",
          |            "Notes": []
          |         },
          |         {
          |            "Code": "QUESTION010",
          |            "Codeset": null,
          |            "Description": "Is this a twin pregnancy?",
          |            "Value": "Singleton",
          |            "Units": null,
          |            "Abbreviation": "sng",
          |            "Notes": []
          |         },
          |         {
          |            "Code": "QUESTION011",
          |            "Codeset": null,
          |            "Description": "Dating Method",
          |            "Value": "LMP",
          |            "Units": null,
          |            "Abbreviation": "lmp",
          |            "Notes": []
          |         }
          |      ]
          |   }
          |}
        """.stripMargin

      val data = validateJsonInput[OrderMessage](json)

      // Validate our data marshalling
      data.Visit must beSome
      val visit = data.Visit.get
      visit.AttendingProvider must beSome
      visit.ConsultingProvider must beSome
      visit.ReferringProvider must beSome
      visit.Guarantor must beSome
      visit.Guarantor.get.Employer must beSome
      visit.Insurances must not be empty
      visit.Location must beSome

      data.Order.Procedure must beSome
      data.Order.Provider must beSome
      data.Order.Diagnoses must not be empty
      data.Order.ClinicalInfo must not be empty

      val fut = client.post[OrderMessage, EmptyResponse](data)
      val maybe = handleResponse(fut)
      maybe must beSome
    }
  }
}