@@ -65,18 +65,84 @@ export default class RequestBox extends Component {
65
65
return preppedResources ;
66
66
}
67
67
68
- submit = ( ) => {
68
+ submit = async ( ) => {
69
69
if ( ! _ . isEmpty ( this . state . request ) ) {
70
- this . props . submitInfo (
70
+ let response = await this . props . submitInfo (
71
71
this . prepPrefetch ( ) ,
72
72
this . state . request ,
73
73
this . state . patient ,
74
74
"order-sign" ,
75
- this . state . deidentifyRecords
75
+ this . state . deidentifyRecords ,
76
+ true
76
77
) ;
77
78
}
78
79
} ;
79
80
81
+ submitAction = async ( ) => {
82
+ console . log ( "submitAction" , this . state . request ) ;
83
+ if ( ! _ . isEmpty ( this . state . request ) ) {
84
+ let response = await this . props . submitInfo (
85
+ this . prepPrefetch ( ) ,
86
+ this . state . request ,
87
+ this . state . patient ,
88
+ "order-sign" ,
89
+ this . state . deidentifyRecords ,
90
+ false
91
+ ) ;
92
+
93
+ console . log ( "submitAction response" , response ) ;
94
+
95
+ if ( ! ! response . systemActions && response . systemActions . length > 0 ) {
96
+ console . log ( "submitAction systemActions" , response . systemActions ) ;
97
+
98
+ // find a resource in the system actions with the CRD coverage information extension
99
+ let resource = null ;
100
+ for ( let action of response . systemActions ) {
101
+
102
+ if ( ! action . resource || ! action . resource . extension || action . resource . extension . length === 0 ) {
103
+ continue ;
104
+ }
105
+ if ( action . resource . extension . findIndex ( e => e . url === "http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information" ) > - 1 ) {
106
+ resource = action . resource ;
107
+ break ;
108
+ }
109
+ }
110
+
111
+ // check if doc-needed and questionnaire extensions are present in the resource of any action
112
+ if ( resource ) {
113
+ console . log ( "submitAction resource" , resource ) ;
114
+ let extension = resource . extension . find ( e => e . url === "http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information" ) ;
115
+
116
+ if ( extension ?. extension . findIndex ( e => e . url === "doc-needed" ) > - 1 ) {
117
+ let questionnaire = extension . extension . find ( e => e . url === "questionnaire" ) ;
118
+
119
+ if ( ! questionnaire ) {
120
+ console . log ( "Questionnaire not found when doc-needed is present" ) ;
121
+ return ;
122
+ }
123
+
124
+ console . log ( "Questionnaire found" , questionnaire ) ;
125
+ console . log ( "Coverage:" , resource . insurance [ 0 ] ) ;
126
+
127
+ let launchLink = await this . buildLaunchLink ( `&questionnaire=${ questionnaire . valueCanonical } ` ) ;
128
+ console . log ( "launchLink" , launchLink ) ;
129
+ window . open ( launchLink . url , "_blank" ) ;
130
+ }
131
+ else {
132
+ console . log ( "doc-needed extension not found" ) ;
133
+ }
134
+
135
+ }
136
+ else {
137
+ console . log ( "submitAction resource not found" ) ;
138
+ }
139
+ }
140
+ else {
141
+ console . log ( "No systemActions" ) ;
142
+ }
143
+ }
144
+ } ;
145
+
80
146
updateStateElement = ( elementName , text ) => {
81
147
this . setState ( { [ elementName ] : text } ) ;
82
148
} ;
@@ -277,10 +343,10 @@ export default class RequestBox extends Component {
277
343
} ) ;
278
344
}
279
345
280
- buildLaunchLink ( ) {
346
+ buildLaunchLink ( additionalContext = "" ) {
281
347
// build appContext and URL encode it
282
348
let appContext = "" ;
283
- let order = undefined , coverage = undefined , response = undefined ;
349
+ let order = undefined , coverage = undefined , response = undefined , questionnaire = undefined ;
284
350
285
351
if ( ! this . isOrderNotSelected ( ) ) {
286
352
if ( Object . keys ( this . state . request ) . length > 0 ) {
@@ -309,6 +375,8 @@ export default class RequestBox extends Component {
309
375
appContext += `response=${ response } `
310
376
}
311
377
378
+ appContext += additionalContext ;
379
+
312
380
const link = {
313
381
appContext : encodeURIComponent ( appContext ) ,
314
382
type : "smart" ,
@@ -398,11 +466,14 @@ export default class RequestBox extends Component {
398
466
</ div >
399
467
</ div >
400
468
</ div >
401
- < button className = { "submit-btn btn btn-class " } onClick = { this . relaunch } disabled = { disableLaunchDTR } >
469
+ { /* <button className={"submit-btn btn btn-class "} onClick={this.relaunch} disabled={disableLaunchDTR}>
402
470
Relaunch DTR
403
- </ button >
471
+ </button> */ }
404
472
< button className = { "submit-btn btn btn-class " } onClick = { this . submit } disabled = { disableSendToCRD } >
405
- Submit to CRD
473
+ Submit to CRD and Display Cards
474
+ </ button >
475
+ < button className = { "submit-btn btn btn-class " } onClick = { this . submitAction } disabled = { disableSendToCRD } >
476
+ Submit to CRD and Launch DTR
406
477
</ button >
407
478
</ div >
408
479
) ;
0 commit comments