Openemr fhir observations for vitals and smoking status (#4460)
commite7c8a0b953262f9d5b2c369f029e65e7124dc840
authorStephen Nielson <stephen@nielson.org>
Thu, 1 Jul 2021 07:18:14 +0000 (1 03:18 -0400)
committerGitHub <noreply@github.com>
Thu, 1 Jul 2021 07:18:14 +0000 (1 00:18 -0700)
treeccf77259714ed76036d5da9aa5ca1e3d9b9bed6d
parente4a32e7c06c3f2b7147423fcf496dd6fc336a651
Openemr fhir observations for vitals and smoking status (#4460)

* FHIR Vitals Observations.

Added a uuid to the form_vitals.  Got the form vitals to populate in the
uuid_mapping table.  Also added a resourcePath that lets us map a FHIR
resource observation to a particular search path.

Got 90% of the vital observations for ONC working.  Missing the
pediatric observation stuff which we need from Jerry Padgett's form
codes.

Handle the data absent reason for Observations.  Put in preliminary work
to handle social history and the lab observations.

* Fix style fixes and vitals unit tests.

* Added Pediatric FHIR elements, FHIR Vitals.

Implemented more of the missing FHIR resources per #4205.

Added the pediatric bmi, head-length, & head circumference percentile
fields for both the vitals_form and for the FHIR resources.  vital_forms
pediatric fields only show if user's age is 20 or younger.  Fixed all
of the implementations for FHIR vitals to pass ONC certifiation.

* Implemented ONC Smoking Status.

Implemented the ONC smoking status stuff.  Added uuids to history_data.

* Fix code review issues and redundant comments

* Beginning work on Observation Lab Procedures.

* Fix user/*.read permissions on observations

Had issues where patients were the patient search was being ignored in a
user context.  Fix a bunch of null value issues and some other
prepartory work coming down the pipe.

* Improve logging.

* Fix category change bugs.

Broke the observations where the category wasn't working.

* Fix user permissions and oauth2 fhirUser

The fhirUser for ONC certification needs to be a practitioner.  Made it
so that if a user with an NPI number logs in via the oauth2 interface
that their fhirUser returned in the JWT id_token is a Practitioner.  If
its a OpenEMR user that does not have an NPI number they are returned as
a Person.

Also added the missing scope permissions for the user/* context.

* Improve observation logging.

* Refactored clinical notes, vitals to support FHIR

Added an auto incrementing primary key for form_clinical_notes.
Refactored the current id column to be its more accurately described form_id.  Changed the deletion
logic to actually set the activity status to be 0 like the regular forms table operates
(similar to procedures).  This fixes the ONC FHIR requirements that resources should not be deleted
and instead have their status property set to inactive or entered-in-error.

Refactored the form_clinical_notes form code to generate a uuid on save and creation. Moved a lot of
the sql logic into the ClinicalNotesService.  Also cleaned up some of the view code.

Made a minor fix in the vitals form table.sql file to have the table columns in.

* Fix styles

* DocumentReference,Clinical Notes,DiagnosticReport

Fixed consultation_note LOINC code being incorrect
Implemented DocumentReference implementation for Clinical Notes and Patient Documents.  (#4205)
Patient Document access still has a number of issues such as LOINC categorization and UUID implementation.
Added search capability to base DocumentService.
Put in a stubbed implementation of DiagnosticReport (#4307)
Added the base fhir url to the FhirServiceBase so we can make FQDN urls for our Document Reference class.

* Fix DocumentReference ONC tests

Using the drive_uuid is a temporary measure to get the ONC test cases to
pass.  We will want to change this to be a full document uuid.

* Fix style issues, database bugs.

* That darn header line...

Not sure why openemr-cmd pf doesn't detect this issue but the CI engine
does, but oh well.

* Remove unused uuid4 import

* Add uuid to Document for FHIR DocumentReference

Added the uuid to the document reference.  Also fixed a bug where
history_data was setting the uuid to be a unique key which doesn't work
for the table since it follows the historical data SQL pattern and the
uuid is duplicated for the same entity.

* Fix missing uuid on base table installation.

* Added Category to Clinical Notes.

We needed to provide a category field for clinical notes in order to
support DiagnosticReports.  So far we only support 3 broad categories of
Radiology, Cardiology, and Pathology.  Other fields can be supported as
people need them.

* Fixed issues facility uuid.

* Implemented Diagnostic Reports for Clinical Notes

Implemented the Diagnostic Reports and got ONC to pass at the resource
level.  Need to see if embeddeding the presented form is going to work
or if we will still need to figure out a URL scheme to make this work
for the cross DiagnosticReport/DocumentReference requirements.

* Add unique keys to uuids, populate uuids

Per @brady.miller's suggestions I've gone and added unique keys to the
uuids and populated the uuids.

* Fix uuids, loinc code replacement.

* Fix form vitals table uuid

* Fix import statement.

* Fix uuid with vertical table

* history_data uuid vertical column fixes.

Clinical Decision Rules (CDR) treat social history as an independent
observation.  Each save of the history is a new record.  In order to
handle that use case we treat the patient id and the date as a new uuid
for the record.

* Fix unique key on history_data

Now that we are using date and pid as the unique values that identify
the history_data we can add the unique key constraint.  Every record
should be unique unless a history_data is created at the exact same
timestamp for the same patient.  That shouldn't happen so we should be
good for this.

* Style fixes

* Fix code types bug as pointed out by @sjpadgett

* Cleanup null statement in vitals table

* Add uuid to clinical_notes table

* Make history_data the same as all other uuids

Since history_data is an independent observation for clinical decision
rules (CDR) we treat it like all the other uuid tables and remove the
vertical_table constraints we had previously.

* Add clinical notes category to lists

* Remove after clause to avoid upgrade breaks.

Per @brady.miller's suggestion I've removed the after clause to avoid
breaking future upgrade scripts.

* Remove unique constraint on uuid_mapping
74 files changed:
_rest_routes.inc.php
custom/code_types.inc.php
interface/forms/clinical_notes/new.php
interface/forms/clinical_notes/report.php
interface/forms/clinical_notes/save.php
interface/forms/clinical_notes/table.sql
interface/forms/vitals/C_FormVitals.class.php
interface/forms/vitals/FormVitals.class.php
interface/forms/vitals/report.php
interface/forms/vitals/table.sql
interface/forms/vitals/templates/vitals/general_new.html
library/classes/Document.class.php
library/patient.inc
sql/6_0_0-to-6_1_0_upgrade.sql
sql/database.sql
src/Common/Auth/OpenIDConnect/Entities/UserEntity.php
src/Common/Auth/OpenIDConnect/Repositories/ScopeRepository.php
src/Common/Uuid/UuidMapping.php
src/Common/Uuid/UuidRegistry.php
src/RestControllers/FHIR/FhirDiagnosticReportRestController.php
src/RestControllers/FHIR/FhirDocumentReferenceRestController.php
src/RestControllers/RestControllerHelper.php
src/Services/ClinicalNotesService.php [new file with mode: 0644]
src/Services/DocumentService.php
src/Services/FHIR/DiagnosticReport/FhirDiagnosticReportClinicalNotesService.php [new file with mode: 0644]
src/Services/FHIR/DocumentReference/FhirClinicalNotesService.php [new file with mode: 0644]
src/Services/FHIR/DocumentReference/FhirPatientDocumentReferenceService.php [new file with mode: 0644]
src/Services/FHIR/FhirAllergyIntoleranceService.php
src/Services/FHIR/FhirCarePlanService.php
src/Services/FHIR/FhirCareTeamService.php
src/Services/FHIR/FhirCodeSystemUris.php
src/Services/FHIR/FhirConditionService.php
src/Services/FHIR/FhirCoverageService.php
src/Services/FHIR/FhirDeviceService.php
src/Services/FHIR/FhirDiagnosticReportService.php [new file with mode: 0644]
src/Services/FHIR/FhirDocumentReferenceService.php [new file with mode: 0644]
src/Services/FHIR/FhirEncounterService.php
src/Services/FHIR/FhirGoalService.php
src/Services/FHIR/FhirImmunizationService.php
src/Services/FHIR/FhirLaboratoryObservation.php [new file with mode: 0644]
src/Services/FHIR/FhirLocationService.php
src/Services/FHIR/FhirMedicationRequestService.php
src/Services/FHIR/FhirMedicationService.php
src/Services/FHIR/FhirObservationService.php
src/Services/FHIR/FhirOrganizationService.php
src/Services/FHIR/FhirPatientService.php
src/Services/FHIR/FhirPersonService.php
src/Services/FHIR/FhirPractitionerRoleService.php
src/Services/FHIR/FhirPractitionerService.php
src/Services/FHIR/FhirProcedureService.php
src/Services/FHIR/FhirProvenanceService.php
src/Services/FHIR/FhirServiceBase.php
src/Services/FHIR/FhirSocialHistoryService.php [new file with mode: 0644]
src/Services/FHIR/FhirVitalsService.php [new file with mode: 0644]
src/Services/FHIR/IResourceSearchableService.php [new file with mode: 0644]
src/Services/FHIR/Traits/FhirServiceBaseEmptyTrait.php [new file with mode: 0644]
src/Services/FHIR/Traits/MappedServiceTrait.php [new file with mode: 0644]
src/Services/FHIR/Traits/PatientSearchTrait.php [new file with mode: 0644]
src/Services/FHIR/UtilsService.php
src/Services/FacilityService.php
src/Services/ObservationLabService.php
src/Services/OrganizationService.php
src/Services/PractitionerService.php
src/Services/Search/DateSearchField.php
src/Services/Search/SearchFieldStatementResolver.php
src/Services/Search/SearchModifier.php
src/Services/Search/StringSearchField.php
src/Services/Search/TokenSearchField.php
src/Services/SocialHistoryService.php [new file with mode: 0644]
src/Services/VitalsService.php [new file with mode: 0644]
src/Validators/ProcessingResult.php
tests/Tests/RestControllers/FacilityRestControllerTest.php
tests/Tests/Services/FHIR/FhirVitalsServiceTest.php [new file with mode: 0644]
version.php