Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed an issue described in #7199 #7440

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sla363
Copy link

@sla363 sla363 commented May 19, 2024

Fixes #7199

Short description of what this resolves: resolves an issue with returning null value when $records[0] is actually a 0 value, which should be returned.

Changes proposed in this pull request: "if" statement replaced with null coalescing operator to ensure that if the value is set and not null it will be returned, which is true for integer 0 as well.

}
return null;

return $records[0] ?? null;
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sla363 , thanks for submitting the PR.
@adunsulag , I feel like we have talked about this before. Guessing there could be some implications in current code with doing this.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my original issue in #7199

The function is used in a lot of places so changing this behavior would require a lot of testing.

Everywhere we use the function needs to be eyeballed and make sure someone isn't relying on the broken behavior. I think most callers will be safe, but still needs to be checked.

PHPStorm returns the following areas where this is used:

Method
    fetchSingleValue
Usages in All Places  (46 usages found)
    Method call  (46 usages found)
        openemr  (46 usages found)
            interface/modules/custom_modules/oe-module-cmsvt-rri-billing/src/Services  (2 usages found)
                CMSVTBillingService.php  (1 usage found)
                    CMSVTBillingService  (1 usage found)
                        updateOrCreateBillingRecordType  (1 usage found)
                            147 $id = QueryUtils::fetchSingleValue(
                ReferringProviderFileService.php  (1 usage found)
                    ReferringProviderFileService  (1 usage found)
                        addReferringProvider  (1 usage found)
                            64 $lastRefKey = QueryUtils::fetchSingleValue($sql, 'refkey', []);
            interface/modules/custom_modules/oe-module-cmsvt-rri-billing/tests/Tests/Integration  (1 usage found)
                PatientImporterTest.php  (1 usage found)
                    PatientImporterTest  (1 usage found)
                        testImportPatients  (1 usage found)
                            31 $singleValue = QueryUtils::fetchSingleValue("SELECT COUNT(*) AS cnt FROM patient_data WHERE pubpid LIKE 'rri-test-%'", 'cnt', []);
            interface/modules/custom_modules/oe-module-cmsvt-rri-billing/tests/Tests/Unit  (1 usage found)
                DataInstallerTest.php  (1 usage found)
                    DataInstallerTest  (1 usage found)
                        testInstall  (1 usage found)
                            32 $count = QueryUtils::fetchSingleValue("SELECT COUNT(*) AS cnt FROM insurance_companies WHERE name LIKE 'rri-test-%'", 'cnt', []);
            interface/modules/custom_modules/oe-module-dc-assessments/src/Listeners  (1 usage found)
                QuestionnaireAssignmentListener.php  (1 usage found)
                    QuestionnaireAssignmentListener  (1 usage found)
                        updateAssignmentItem  (1 usage found)
                            81 $category = QueryUtils::fetchSingleValue("SELECT id FROM categories WHERE name = ?", 'id', ['Reviewed']) ?: 3;
            interface/modules/custom_modules/oe-module-dc-assessments/src/Services  (7 usages found)
                AssessmentReportRepository.php  (1 usage found)
                    AssessmentReportRepository  (1 usage found)
                        existsReport  (1 usage found)
                            147 $result = QueryUtils::fetchSingleValue($sql, 'count', $params);
                AssessmentRepository.php  (3 usages found)
                    AssessmentRepository  (3 usages found)
                        canEditAssessment  (1 usage found)
                            204 $assessmentCompanyId = QueryUtils::fetchSingleValue($sql, 'company_id', [$id]);
                        existsAssessment  (1 usage found)
                            194 return QueryUtils::fetchSingleValue($sql, 'cnt', $params) > 0;
                        getMostRecentAssessmentIdForUid  (1 usage found)
                            146 return QueryUtils::fetchSingleValue($sql, 'id', [$uid]);
                AssignmentRepository.php  (3 usages found)
                    AssignmentRepository  (3 usages found)
                        getAssignmentIdForAssignmentItem  (1 usage found)
                            546 return QueryUtils::fetchSingleValue(
                        hasCompletedAssignmentItems  (1 usage found)
                            556 $count = QueryUtils::fetchSingleValue($sql, 'count', [$assignmentId]);
                        hasCompletedAssignments  (1 usage found)
                            562 $count = QueryUtils::fetchSingleValue($sql, 'count', [$clientId]);
            interface/modules/custom_modules/oe-module-dc-assessments/src/Services/Task  (1 usage found)
                QuestionnairePortalTaskFHIRResourceService.php  (1 usage found)
                    QuestionnairePortalTaskFHIRResourceService  (1 usage found)
                        update  (1 usage found)
                            120 $category = QueryUtils::fetchSingleValue("SELECT id FROM categories WHERE name = ?", 'id', ['Reviewed']) ?: 3;
            interface/modules/custom_modules/oe-module-ehi-exporter/src/Services  (3 usages found)
                EhiExporter.php  (3 usages found)
                    EhiExporter  (3 usages found)
                        createDatabaseDocumentFromZip  (1 usage found)
                            538 $categoryId = QueryUtils::fetchSingleValue('Select `id` FROM categories WHERE name=?', 'id', [self::EHI_DOCUMENT_CATEGORY]);
                        getExportSizeSettings  (2 usages found)
                            715 $maxDocSize = QueryUtils::fetchSingleValue("select max(size) as size FROM documents WHERE foreign_id != 0", 'size', []);
                            716 $totalPatients = QueryUtils::fetchSingleValue("select count(*) as cnt FROM patient_data", 'cnt', []);
            interface/modules/zend_modules/module/Carecoordination/src/Carecoordination/Model  (1 usage found)
                EncounterccdadispatchTable.php  (1 usage found)
                    EncounterccdadispatchTable  (1 usage found)
                        logCCDA  (1 usage found)
                            3353 $categoryId = QueryUtils::fetchSingleValue(
            interface/modules/zend_modules/module/CodeTypes/src/CodeTypes/Listener  (4 usages found)
                CodeTypeEventsSubscriber.php  (4 usages found)
                    CodeTypeEventsSubscriber  (4 usages found)
                        shouldUpdateCPT4Mappings  (2 usages found)
                            165 $code_id = QueryUtils::fetchSingleValue("SELECT `code` FROM codes WHERE code_text =? "
                            174 $codes = QueryUtils::fetchSingleValue($sql, 'codes', [self::LIST_ID_ENCOUNTER_TYPES, $option_id]);
                        shouldUpdateListWithSnomedCodes  (1 usage found)
                            205 $codes = QueryUtils::fetchSingleValue($sql, 'codes', [$list_id, $option_id]);
                        updateCPT4Mappings  (1 usage found)
                            256 $code_id = QueryUtils::fetchSingleValue("SELECT `code` FROM codes WHERE code_text =? "
            library/classes  (1 usage found)
                Document.class.php  (1 usage found)
                    Document  (1 usage found)
                        getDocumentForUuid  (1 usage found)
                            443 $id = \OpenEMR\Common\Database\QueryUtils::fetchSingleValue($sql, 'id', [UuidRegistry::uuidToBytes($uuid)]);
            src/Services  (13 usages found)
                AppointmentService.php  (3 usages found)
                    AppointmentService  (3 usages found)
                        createEncounterForAppointment  (1 usage found)
                            610 $pos_code = QueryUtils::fetchSingleValue(
                        validate  (2 usages found)
                              (1 usage found)
                                102 $id = QueryUtils::fetchSingleValue('Select id FROM users WHERE id = ? ', 'id', [$value]);
                              (1 usage found)
                                109 $id = QueryUtils::fetchSingleValue('Select id FROM patient_data WHERE pid = ? ', 'id', [$value]);
                ClinicalNotesService.php  (2 usages found)
                    ClinicalNotesService  (2 usages found)
                        createClinicalNotesParentForm  (1 usage found)
                            223 $largestId = QueryUtils::fetchSingleValue("SELECT COALESCE(MAX(form_id), 0) as largestId FROM `form_clinical_notes`", 'largestId');
                        saveArray  (1 usage found)
                            256 $largestId = QueryUtils::fetchSingleValue("SELECT COALESCE(MAX(form_id), 0) as largestId FROM `form_clinical_notes`", 'largestId');
                EncounterService.php  (1 usage found)
                    EncounterService  (1 usage found)
                        insertVital  (1 usage found)
                            567 $formId = intval(QueryUtils::fetchSingleValue('select id FROM forms WHERE form_id = ? ', 'id', [$vitalsFormId]));
                InsuranceService.php  (1 usage found)
                    InsuranceService  (1 usage found)
                        swapInsurance  (1 usage found)
                            485 $targetUuid = QueryUtils::fetchSingleValue("SELECT uuid FROM insurance_data WHERE pid = ? AND type = ? ORDER BY (date IS NULL) ASC, date DESC", 'uuid', [$pid, $targetType]);
                ObservationLabService.php  (2 usages found)
                    ObservationLabService  (2 usages found)
                        isValidProcedureCode  (1 usage found)
                            77 $code = QueryUtils::fetchSingleValue($sql, 'procedure_code', [$code]);
                        isValidProcedureResultCode  (1 usage found)
                            70 $code = QueryUtils::fetchSingleValue($sql, 'result_code', [$code]);
                PatientIssuesService.php  (1 usage found)
                    PatientIssuesService  (1 usage found)
                        validateIssueType  (1 usage found)
                            133 $value = QueryUtils::fetchSingleValue("select type FROM issue_types WHERE type = ? ", 'type', $type);
                PatientService.php  (2 usages found)
                    PatientService  (2 usages found)
                        createPatientNameHistory  (1 usage found)
                            746 $go_flag = QueryUtils::fetchSingleValue($sql, 'pid', $insertData);
                        search  (1 usage found)
                            458 $uuidCount = QueryUtils::fetchSingleValue($sqlUUidsCount, 'cnt', $whereUuidClause->getBoundValues());
                PatientTransactionService.php  (1 usage found)
                    PatientTransactionService  (1 usage found)
                        getUserIdByNpi  (1 usage found)
                            301 return QueryUtils::fetchSingleValue('Select id FROM users WHERE npi = ? ', 'id', [$npi]);
            src/Services/Cda  (2 usages found)
                CdaTemplateImportDispose.php  (2 usages found)
                    CdaTemplateImportDispose  (2 usages found)
                        InsertImportedFiles  (2 usages found)
                            2192 $categoryId = QueryUtils::fetchSingleValue(
                            2199 $categoryId = QueryUtils::fetchSingleValue(
            src/Validators  (5 usages found)
                CoverageValidator.php  (5 usages found)
                    CoverageValidator  (5 usages found)
                        configureValidator  (5 usages found)
                              (3 usages found)
                                268 $targetDate = QueryUtils::fetchSingleValue(
                                275 $srcTypeCanReceiveTarget = QueryUtils::fetchSingleValue(
                                286 $targetTypeCanReceiveSrc = QueryUtils::fetchSingleValue(
                              (2 usages found)
                                168 $duplicatePolicyCount = QueryUtils::fetchSingleValue($sqlCheck, 'cnt', $binds);
                                186 $currentPolicyCount = QueryUtils::fetchSingleValue($sqlCheck, 'cnt', $binds);
            tests/Tests/Services  (2 usages found)
                EncounterServiceTest.php  (2 usages found)
                    EncounterServiceTest  (2 usages found)
                        testGetOne  (1 usage found)
                            53 $uuid = QueryUtils::fetchSingleValue("SELECT `uuid`,`encounter` FROM `form_encounter`", "uuid");
                        testSearchWithBoundPatientUUID  (1 usage found)
                            72 $uuid = QueryUtils::fetchSingleValue("SELECT `pd`.`uuid` FROM `form_encounter` fe "
            tests/Tests/Services/FHIR  (2 usages found)
                FhirAllergyIntoleranceServiceQueryTest.php  (1 usage found)
                    FhirAllergyIntoleranceServiceQueryTest  (1 usage found)
                        testGetAllWithUuid  (1 usage found)
                            142 $allergy_uuid = QueryUtils::fetchSingleValue($select, 'uuid');
                FhirVitalsServiceTest.php  (1 usage found)
                    FhirVitalsServiceTest  (1 usage found)
                        testConstructor  (1 usage found)
                            47 $uuid = QueryUtils::fetchSingleValue("select `uuid` FROM form_vitals WHERE id=?", 'uuid', [$id]);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I performed a quick review of the function usage and didn't notice any issues at first glance. However, I'm not very familiar with the system, so there might be underlying issues that I'm not aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: QueryUtils::fetchSingleValue() should return 0 instead of null if column value is actually 0
3 participants