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

Quantity type is not supported yet for minValue and MaxValue extension #881

Closed
santosh-pingle opened this issue Oct 27, 2021 · 11 comments · Fixed by #2082 or #2090
Closed

Quantity type is not supported yet for minValue and MaxValue extension #881

santosh-pingle opened this issue Oct 27, 2021 · 11 comments · Fixed by #2082 or #2090
Labels
effort:small Small effort - 2 days P3 Low priority issue type:enhancement New feature or request

Comments

@santosh-pingle
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
It gives error not implemented yet.

Implemented below unit test, but it had thrown quantity type is not implemented yet.

@Test
  @UiThreadTest
  fun displayValidationResult_validValue_shouldAssignErrorNull() {
    viewHolder.bind(
      QuestionnaireItemViewItem(
        Questionnaire.QuestionnaireItemComponent().apply {
          addExtension().apply {
            url = "http://hl7.org/fhir/StructureDefinition/minValue"
            setValue(Quantity(2.2))
          }
          addExtension().apply {
            url = "http://hl7.org/fhir/StructureDefinition/maxValue"
            setValue(Quantity(4.4))
          }
        },
        QuestionnaireResponse.QuestionnaireResponseItemComponent().apply {
          addAnswer(
            QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent().apply {
              value = Quantity(3.3)
            }
          )
        }
      ) {}
    )

    assertThat(viewHolder.itemView.findViewById<TextInputEditText>(R.id.textInputEditText).error).isNull()
  }

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Would you like to work on the issue?
Please state if this issue should be assigned to you or who you think could help to solve this issue.

@santosh-pingle santosh-pingle added the type:enhancement New feature or request label Oct 27, 2021
@epicadk
Copy link
Contributor

epicadk commented Oct 28, 2021

Isn't this because minValue is suppose to be applied only to date, dateTime, time, decimal, integer?
As mentioned here.

I think we could improve the error message to say quantity type is not supported by the min/maxvalue extensions.

@santosh-pingle
Copy link
Collaborator Author

santosh-pingle commented Oct 29, 2021

Can't we jut mark this ticket invalid and also not include test? as you rightly mentioned minValue and maxValue supported types.

@epicadk
Copy link
Contributor

epicadk commented Oct 29, 2021

Can't we jut mark this ticket invalid and also not include test? as you rightly mentioned minValue and maxValue supported types.

I agree, but do you think the NotImplementedError thrown may be confusing. Maybe we could replace that with an IllegalArgumentException?

@Tarun-Bhardwaj Tarun-Bhardwaj added P3 Low priority issue effort:small Small effort - 2 days labels Nov 10, 2021
@jingtang10
Copy link
Collaborator

Isn't this because minValue is suppose to be applied only to date, dateTime, time, decimal, integer? As mentioned here.

I think we could improve the error message to say quantity type is not supported by the min/maxvalue extensions.

yeah i don't undrestand why shouldn't the min/max value validation support quantity - i kinda feel like we should propose a change to the standard. can you do that please @epicadk (if you agree)?

i kinda think we should at least try to compare on a best-effort basis and in this case the unit test shouldn't throw exception.

@jingtang10
Copy link
Collaborator

@epicadk
Copy link
Contributor

epicadk commented Dec 9, 2021

please see http://build.fhir.org/ig/HL7/sdc/behavior.html

that's interesting, so we probably want to support minQuantity and maxQuantity extensions. I would be open to working on this.

@jingtang10
Copy link
Collaborator

@epicadk you already have a few things on your plate. If you don't mind let's let @juanchazo work on this and for you for focus on the other issues? Thanks

@epicadk
Copy link
Contributor

epicadk commented Dec 9, 2021

@epicadk you already have a few things on your plate. If you don't mind let's let @juanchazo work on this and for you for focus on the other issues? Thanks

Oh sure

@delcroip
Copy link
Collaborator

linked to #1849

@delcroip
Copy link
Collaborator

Dear all,

it works on some quantity but not all

this "works" (the error message show null instead of the boundary, we do have a fork that push the unit from http://hl7.org/fhir/StructureDefinition/questionnaire-unit which is not the fully correct way, here is the PR that should be more correct #2014)

        {
            "extension": [
                {
                    "url": "http://hl7.org/fhir/StructureDefinition/minValue",
                    "valueQuantity": {
                        "value": 0.5,
                        "system": "http://unitsofmeasure.org",
                        "code": "kg"
                    }
                },
                {
                    "url": "http://hl7.org/fhir/StructureDefinition/maxValue",
                    "valueQuantity": {
                        "value": 40.0,
                        "system": "http://unitsofmeasure.org",
                        "code": "kg"
                    }
                },
                {
                    "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-unit",
                    "valueCoding": {
                        "system": "http://unitsofmeasure.org",
                        "code": "kg"
                    }
                },
                {
                    "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression",
                    "valueExpression": {
                        "language": "text/fhirpath",
                        "expression": "%resource.repeat(item).where(linkId='EmCare.B6.DE07').answer.first().empty()"
                    }
                }
            ],
            "linkId": "EmCare.B6.DE06",
            "text": "Weight (Kg)",
            "type": "quantity",
            "required": true,
            "repeats": false,
}

but this does not (I simplified with only minValue but still failed)

 {
            "extension": [
                {
                    "url": "http://hl7.org/fhir/StructureDefinition/minValue",
                    "valueQuantity": {
                        "value": 0,
                        "system": "http://unitsofmeasure.org",
                        "code": "Cel"
                    }
                },
                {
                    "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-unit",
                    "valueCoding": {
                        "system": "http://unitsofmeasure.org",
                        "code": "Cel"
                    }
                }
            ],
            "linkId": "rest",
            "text": "What is the room temperature",
            "type": "quantity",
            "required": false,
            "repeats": false
        }

here is the error I am getting

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.argusoft.who.emcare.debug, PID: 17054
    com.google.android.fhir.ConverterException: Missing numerical value in the canonical UCUM value
        at com.google.android.fhir.UnitConverter.getCanonicalForm(UnitConverter.kt:63)
        at com.google.android.fhir.MoreTypesKt.compareTo(MoreTypes.kt:68)
        at com.google.android.fhir.datacapture.validation.MinValueValidator$1.invoke(MinValueValidator.kt:36)
        at com.google.android.fhir.datacapture.validation.MinValueValidator$1.invoke(MinValueValidator.kt:33)
        at com.google.android.fhir.datacapture.validation.AnswerExtensionConstraintValidator.validate(AnswerExtensionConstraintValidator.kt:48)
        at com.google.android.fhir.datacapture.validation.QuestionnaireResponseItemValidator.validate(QuestionnaireResponseItemValidator.kt:57)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel.getQuestionnaireAdapterItems(QuestionnaireViewModel.kt:711)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel.getQuestionnaireAdapterItems(QuestionnaireViewModel.kt:679)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel.getQuestionnaireState(QuestionnaireViewModel.kt:627)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel.access$getQuestionnaireState(QuestionnaireViewModel.kt:85)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$1.invokeSuspend(QuestionnaireViewModel.kt:446)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$1.invoke(Unknown Source:9)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel$questionnaireStateFlow$1.invoke(Unknown Source:20)
        at kotlinx.coroutines.flow.FlowKt__ZipKt$combine$$inlined$combineUnsafe$FlowKt__ZipKt$1$2.invokeSuspend(Zip.kt:333)
        at kotlinx.coroutines.flow.FlowKt__ZipKt$combine$$inlined$combineUnsafe$FlowKt__ZipKt$1$2.invoke(Unknown Source:13)
        at kotlinx.coroutines.flow.FlowKt__ZipKt$combine$$inlined$combineUnsafe$FlowKt__ZipKt$1$2.invoke(Unknown Source:6)
        at kotlinx.coroutines.flow.internal.CombineKt$combineInternal$2.invokeSuspend(Combine.kt:79)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
        at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:245)
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
        at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:328)
        at kotlinx.coroutines.flow.StateFlowSlot.makePending(StateFlow.kt:286)
        at kotlinx.coroutines.flow.StateFlowImpl.updateState(StateFlow.kt:351)
        at kotlinx.coroutines.flow.StateFlowImpl.compareAndSet(StateFlow.kt:321)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel$answersChangedCallback$1.invoke(QuestionnaireViewModel.kt:937)
        at com.google.android.fhir.datacapture.QuestionnaireViewModel$answersChangedCallback$1.invoke(QuestionnaireViewModel.kt:313)
        at com.google.android.fhir.datacapture.views.QuestionnaireViewItem.setAnswer(QuestionnaireViewItem.kt:142)
        at com.google.android.fhir.datacapture.views.factories.EditTextQuantityViewHolderFactory$getQuestionnaireItemViewHolderDelegate$1.handleInput(EditTextQuantityViewHolderFactory.kt:40)
        at com.google.android.fhir.datacapture.views.factories.QuestionnaireItemEditTextViewHolderDelegate$bind$$inlined$doAfterTextChanged$1.afterTextChanged(TextView.kt:98)
        at android.widget.TextView.sendAfterTextChanged(TextView.java:11911)
        at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:15283)
E/AndroidRuntime:     at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1291)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:591)
        at androidx.emoji2.text.SpannableBuilder.replace(SpannableBuilder.java:314)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:521)
        at androidx.emoji2.text.SpannableBuilder.replace(SpannableBuilder.java:304)
        at androidx.emoji2.text.SpannableBuilder.replace(SpannableBuilder.java:48)
        at android.text.method.QwertyKeyListener.onKeyDown(QwertyKeyListener.java:228)
        at android.text.method.TextKeyListener.onKeyDown(TextKeyListener.java:141)
        at androidx.emoji2.viewsintegration.EmojiKeyListener.onKeyDown(EmojiKeyListener.java:58)
        at android.widget.TextView.doKeyDown(TextView.java:9503)
        at android.widget.TextView.onKeyDown(TextView.java:9275)
        at android.view.KeyEvent.dispatch(KeyEvent.java:3508)
        at android.view.View.dispatchKeyEvent(View.java:15395)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
        at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:1105)
        at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1961)
        at android.app.Activity.dispatchKeyEvent(Activity.java:4342)
        at androidx.core.app.ComponentActivity.superDispatchKeyEvent(ComponentActivity.java:122)
        at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:84)
        at androidx.core.app.ComponentActivity.dispatchKeyEvent(ComponentActivity.java:140)
        at androidx.appcompat.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:599)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
        at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:3090)
        at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:929)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:8056)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:7864)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7213)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:7270)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:7236)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:7434)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:7244)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:7491)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7217)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:7270)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:7236)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:7244)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7217)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:10788)
E/AndroidRuntime:     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:10676)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:10632)
        at android.view.ViewRootImpl$ViewRootHandler.handleMessageImpl(ViewRootImpl.java:6822)
        at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:6697)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8757)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
    	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@342d031, Dispatchers.Main.immediate]
    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.fhir.ucum.Decimal.asDecimal()' on a null object reference
        at com.google.android.fhir.UnitConverter.getCanonicalForm(UnitConverter.kt:57)
        	... 99 more
I/Process: Sending signal. PID: 17054 SIG: 9
Disconnected from the target VM, address: 'localhost:36527', transport: 'socket'

@jingtang10
Copy link
Collaborator

Until FHIR/Ucum-java#26 is resolved, I think we can put in a workaround here:

this.fhirType().equals("Quantity") -> {

to at least attempt to compare two quantities if they cannot be canonicalized but have the same unit.

@khyativyasargus @delcroip please feel free to send a PR - this should be a quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment