@openmrs/esm-cohort-builder-app 4.0.7-pre.1548 → 4.0.7-pre.1553

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/117.js CHANGED
@@ -1 +1 @@
1
- "use strict";(globalThis.webpackChunk_openmrs_esm_cohort_builder_app=globalThis.webpackChunk_openmrs_esm_cohort_builder_app||[]).push([["117"],{4300(e){e.exports=JSON.parse('{"age":"Age","ageBetween":"Age between","alive":"Alive","all":"All","and":"and","any":"Any","anyEncounter":"Any Encounter","atLeast":"at least many","average":"Average","birthDate":"Birth date","clearHistory":"Clear Search History","clearing":"Clearing","clearItemFromHistory":"clearItemFromHistory","clearSearch":"Clear search","clearSearchHistory":"Clear search history","clearSearchHistoryModalText":"clearSearchHistoryModalText","cohortBuilder":"Cohort Builder","cohortDeleted":"cohortDeleted","cohortDescriptionRequired":"Description is required","cohortNameRequired":"Cohort name is required","cohorts":"cohorts","cohortSaved":"Cohort created successfully","cohortViewError":"Error viewing the cohort","completedBetween":"Completed between","composition":"Composition","compositionExplanationOne":"This query combines multiple cohorts using the logical operators:- AND,OR and NOT.","compositionExplanationThree":"Example: if the search history #1 is a cohort of patients who are males, and if the search history #2 is a cohort of patients with ages between 23 and 35 years; then \'1 AND 2\' will result in a cohort of patients who are males with ages between 23 and 35 years.","compositionExplanationTwo":"To use this query you need to already have query results in your search history. Those existing query results can then be combined to yield the results of the composition query.","concepts":"Concepts","data":"data","dateRange":"Date Range","dead":"Dead","delete":"Delete","deleteCohort":"deleteCohort","deleteCohortModalText":"deleteCohortModalText","deleteFromHistory":"Delete from history","deleteSavedQuery":"Delete saved query","deleteSavedQueryConfirmation":"Are you sure you want to delete this saved query?","deleting":"deleting","demographics":"Demographics","description":"Description","downloadResults":"Download Results","drugOrder":"Drug Order","earliest":"Earliest","earliestEncounter":"Earliest Encounter","encounters":"Encounters","endDate":"End date","enrolledBetween":"Enrolled between","enrollments":"Enrollments","enterCohortDescription":"Enter a cohort description","enterCohortName":"Enter a cohort name","enterQueryDescription":"Enter a description of the query","enterQueryName":"Enter a name for the query","error":"error","errorCreatingCohort":"Error creating the cohort","females":"Female","from":"From","gender":"Gender","haveNoObservations":"Patients who do not have these observations","haveObservations":"Patients who have these observations","highest":"Highest","invalidComposition":"Composition is not valid","itemsPerPage":"Items per page:","lastDays":"and / or days","location":"Location","lowest":"Lowest","males":"Male","manageCohorts":"Manage Cohorts","maxAgeIsNotValid":"The age must be less than 200","minAgeIsNotValid":"The age must be greater than 0","mostRecentEncounter":"Most Recent Encounter","name":"Name","nextPage":"Next page","noMatchingConcepts":"No concepts were found that match","none":"None","noOfResultsFound_one":"{{count}} results found","noOfResultsFound_other":"{{count}} results found","numberIsNotValid":"Number is not valid","openmrsId":"OpenMRS ID","patientsWithObservationsWhoseAnswerIs":"Patients with observations whose answer is","personAttributes":"Person Attributes","previousPage":"Previous page","queries":"queries","query":"Query","queryDeleteError":"Error deleting the query","QueryDeleteError":"QueryDeleteError","queryDescriptionRequired":"Description is required","queryIsDeleted":"the query is deleted","queryNameRequired":"Name is required","recent":"Most Recent","removeItemFromSearchHistory":"Are you sure you want to remove this item from the search history?","removing":"removing","results":"Results","saveCohort":"Save Cohort","savedCohortDescription":"You can only search for Cohort Definitions that you have saved using a Name.","savedCohortsOptions":"Saved cohorts options","savedDefinitions":"Saved Definitions","savedQueriesOptions":"Saved queries options","savedQueryDescription":"You can only search for Query Definitions that you have saved using a Name.","saveQuery":"Save Query","saving":"saving","searchCompleted":"Search completed","searchConcepts":"Search Concepts","searchCriteria":"Search Criteria","searchForALocation":"Search for a location","searchHistory":"Search History","searchHistoryOptions":"Search history options","searching":"Searching","searchItemDeleteError":"Error deleting the search item","searchResults":"Search Results","selectAttribute":"Select a person attribute","selectCareSettings":"Select a care setting","selectDrugs":"Select drugs","selectedAttributeValues":"Enter Comma Delimited Values","selectEncounterTypes":"Select encounter types","selectForms":"Select forms","selectLocations":"Select locations","selectMethod":"Select a method","selectPrograms":"Select programs","success":"Success","to":"to","upto":"upto this many","used":"Used between","using":"Using between","valueIn":"Enter a value in ","view":"View","whatObservations":"What observations","whatValues":"What values","withinTheLast":"Within the last"}')}}]);
1
+ "use strict";(globalThis.webpackChunk_openmrs_esm_cohort_builder_app=globalThis.webpackChunk_openmrs_esm_cohort_builder_app||[]).push([["117"],{4300(e){e.exports=JSON.parse('{"age":"Age","ageBetween":"Age between","alive":"Alive","all":"All","and":"and","any":"Any","anyEncounter":"Any Encounter","atLeast":"at least","average":"Average","birthDate":"Birth date between","clearHistory":"Clear history","clearing":"Clearing","clearItemFromHistory":"Clear item from search history","clearSearch":"Clear search","clearSearchHistory":"Clear search history","clearSearchHistoryModalText":"Are you sure you want to clear the search history?","cohortBuilder":"Cohort Builder","cohortDeleted":"Cohort deleted","cohortDescriptionRequired":"Description is required","cohortNameRequired":"Cohort name is required","cohorts":"cohorts","cohortSaved":"Cohort created successfully","cohortViewError":"Error viewing the cohort","completedBetween":"Completed between","composition":"Composition","compositionExplanationOne":"This query combines multiple cohorts using the logical operators:- AND,OR and NOT.","compositionExplanationThree":"Example: if the search history #1 is a cohort of patients who are males, and if the search history #2 is a cohort of patients with ages between 23 and 35 years; then \'1 AND 2\' will result in a cohort of patients who are males with ages between 23 and 35 years.","compositionExplanationTwo":"To use this query you need to already have query results in your search history. Those existing query results can then be combined to yield the results of the composition query.","concepts":"Concepts","data":"data","dateRange":"Date range start date","dead":"Dead","delete":"Delete","deleteCohort":"Delete cohort","deleteCohortModalText":"Are you sure you want to delete the cohort","deleteFromHistory":"Delete from history","deleteSavedQuery":"Delete saved query","deleteSavedQueryConfirmation":"Are you sure you want to delete this saved query?","deleting":"Deleting","demographics":"Demographics","description":"Description","downloadResults":"Download results","drugOrder":"Drug Order","earliest":"Earliest","earliestEncounter":"Earliest Encounter","encounters":"Encounters","endDate":"End date","enrolledBetween":"Enrolled between","enrollments":"Enrollments","enterCohortDescription":"Enter a cohort description","enterCohortName":"Enter a cohort name","enterQueryDescription":"Enter a description of the query","enterQueryName":"Enter a name for the query","error":"Error","errorCreatingCohort":"Error creating the cohort","females":"Female","from":"From","gender":"Gender","haveNoObservations":"Patients who do not have these observations","haveObservations":"Patients who have these observations","highest":"Highest","invalidComposition":"Composition is not valid","itemsPerPage":"Items per page:","lastDays":"and / or days","location":"Location","lowest":"Lowest","males":"Male","manageCohorts":"Manage Cohorts","maxAgeIsNotValid":"The age must be less than 200","minAgeIsNotValid":"The age must be greater than 0","mostRecentEncounter":"Most Recent Encounter","name":"Name","nextPage":"Next page","noMatchingConcepts":"No concepts were found that match","none":"None","noOfResultsFound_one":"{{count}} results found","noOfResultsFound_other":"{{count}} results found","numberIsNotValid":"Number is not valid","openmrsId":"OpenMRS ID","patientsWithObservationsWhoseAnswerIs":"Patients with observations whose answer is","personAttributes":"Person Attributes","previousPage":"Previous page","queries":"queries","query":"Query","queryDeleteError":"Error saving the query","QueryDeleteError":"Something went wrong","queryDescriptionRequired":"Description is required","queryIsDeleted":"the query is deleted","queryNameRequired":"Name is required","recent":"Most Recent","removeItemFromSearchHistory":"Are you sure you want to remove this item from the search history?","removing":"Removing","results":"Results","saveCohort":"Save cohort","savedCohortDescription":"You can only search for Cohort Definitions that you have saved using a Name.","savedCohorts":"Saved Cohorts","savedCohortsOptions":"Saved cohorts options","savedQueries":"Saved Queries","savedQueriesOptions":"Saved queries options","savedQueryDescription":"You can only search for Query Definitions that you have saved using a Name.","saveQuery":"Save query","saving":"Saving","searchCompleted":"Search completed","searchConcepts":"Search Concepts","searchCriteria":"Search Criteria","searchForALocation":"Search for a location","searchHistory":"Search History","searchHistoryOptions":"Search history options","searching":"Searching","searchItemDeleteError":"Error deleting the search item","searchResults":"Search Results","selectAttribute":"Select a person attribute","selectCareSettings":"Select a care setting","selectDrugs":"Select drugs","selectedAttributeValues":"Enter Comma Delimited Values","selectEncounterTypes":"Select encounter types","selectForms":"Select forms","selectLocations":"Select locations","selectMethod":"Select a method","selectPrograms":"Select programs","success":"Success","to":"to","upto":"upto this many","used":"Used between","using":"Using between","valueIn":"Enter a value in ","view":"View","whatObservations":"What observations","whatValues":"What values","withinTheLast":"Within the last months"}')}}]);
package/dist/117.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"117.js","sources":["webpack://@openmrs/esm-cohort-builder-app/json|/home/runner/work/openmrs-esm-cohortbuilder-app/openmrs-esm-cohortbuilder-app/translations/en.json"],"names":["JSON"],"mappings":"wJAAA,EAAO,OAAO,CAAGA,KAAK,KAAK,CAAC,+7J"}
1
+ {"version":3,"file":"117.js","sources":["webpack://@openmrs/esm-cohort-builder-app/json|/home/runner/work/openmrs-esm-cohortbuilder-app/openmrs-esm-cohortbuilder-app/translations/en.json"],"names":["JSON"],"mappings":"wJAAA,EAAO,OAAO,CAAGA,KAAK,KAAK,CAAC,8hK"}
package/dist/321.js CHANGED
@@ -1 +1 @@
1
- (globalThis.webpackChunk_openmrs_esm_cohort_builder_app=globalThis.webpackChunk_openmrs_esm_cohort_builder_app||[]).push([["321"],{4767(e,t,a){var r={"./en.json":["4300","117"]};function n(e){if(!a.o(r,e))return Promise.resolve().then(function(){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t});var t=r[e],n=t[0];return a.e(t[1]).then(function(){return a(n)})}n.keys=()=>Object.keys(r),n.id=4767,e.exports=n},6720(e,t,a){"use strict";a.r(t),a.d(t,{cohortBuilder:()=>eq,clearSearchHistoryModal:()=>eF,saveCohortModal:()=>eU,importTranslation:()=>eP,deleteQueryModal:()=>ez,cohortBuilderAdminPageCardLink:()=>eR,deleteCohortModal:()=>eH,clearItemFromSearchHistoryModal:()=>eB,startupApp:()=>e$,saveQueryModal:()=>eQ});var r=a(3609),n=a(4923),l=a.n(n),o=a(9536),s=a(202);let i="-esm-cohort-builder__modals__deleteButton___wIYdW";var c=a(2137),m=a(6942),d=a.n(m),u=a(6880),h=a.n(u);let p=async e=>await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/adhocquery?v=full`,{method:"POST",headers:{"Content-Type":"application/json"},body:e.query}),b=()=>{let{data:e,error:t}=h()(`${r.restBaseUrl}/location`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,locations:a,locationsError:t}},E=async e=>(await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/dataSet/${e}`,{method:"GET"})).data.rows.map(e=>(e.id=e.patientId.toString(),e.name=`${e.firstname} ${e.lastname}`,e)),g=async e=>(await (0,r.openmrsFetch)(`${r.restBaseUrl}/cohort/${e}/member?v=full`,{method:"GET"})).data.rows.map(e=>(e.id=e.patientId.toString(),e.name=`${e.firstname} ${e.lastname}`,e)),_=e=>{let t={type:"org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",columns:[],rowFilters:[],customRowFilterCombination:""};t.columns=C();let a=0;for(let r in t.rowFilters=[],e){if(y(e[r])){delete e[r];continue}"all"!=e[r]&&""!=e&&(t.rowFilters[a]={},t.rowFilters[a].key=v(r,e[r])),Array.isArray(e[r])&&(t.rowFilters[a].parameterValues=S(e[r])),e[r].length>=1&&"alive"===e[r][0].livingStatus&&(t.rowFilters[a].livingStatus="alive"),t.rowFilters[a].type="org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",a+=1}return t.customRowFilterCombination=w(t.rowFilters),{query:t}},y=e=>Array.isArray(e)&&e.length>=1?!e[0].value:"all"===e||!e,v=(e,t)=>{let a="reporting.library.cohortDefinition.builtIn";return"gender"===e?a+=`.${t}`:a+=`.${e}`,a},S=e=>{let t={};return e.forEach(e=>{t[e.name]=e.value}),t},w=e=>{let t="",a=e.length;for(let r=1;r<=a;r++)"alive"===e[r-1].livingStatus?(t+=`NOT ${r}`,delete e[r-1].livingStatus):t+=`${r}`,t+=r<a?" AND ":"";return t},C=()=>[{name:"firstname",key:"preferredName.givenName"},{name:"lastname",key:"preferredName.familyName"},{name:"gender",key:"gender"},{name:"age",key:"ageOnDate.fullYears"},{name:"patientId",key:"patientId"}].map(e=>(e.type="org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition",e.key=`reporting.library.patientDataDefinition.builtIn.${e.key}`,e)),f=e=>{let t=new Date(e),a=t.getDate(),r=t.getMonth()+1,n=t.getFullYear();return`${a}/${r}/${n}`},T="-esm-cohort-builder__search-button-set__button___tg6-2",k=({isLoading:e,onHandleSubmit:t,onHandleReset:a})=>{let{t:r}=(0,s.useTranslation)();return l().createElement(o.Column,{sm:2,md:{offset:4},className:"-esm-cohort-builder__search-button-set__container___jIXOL"},l().createElement(o.ButtonSet,{className:"-esm-cohort-builder__search-button-set__buttonSet___itc+A"},l().createElement(o.Button,{className:T,kind:"secondary",onClick:a,"data-testid":"reset-btn"},r("reset","Reset")),l().createElement(o.Button,{className:T,kind:"primary",disabled:e,onClick:t,"data-testid":"search-btn"},e?l().createElement(o.InlineLoading,{description:r("loading","Loading")}):r("search","Search"))))},D="-esm-cohort-builder__composition-style__text___YdbOd",N=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(!1),[c,m]=(0,n.useState)(""),[d,u]=(0,n.useState)(""),h=async()=>{i(!0);try{let a;if(a=c.match(/and|or|not|\d+|\)|\(|union|intersection|!|\+/gi),null!==a&&a.length===c.split(/\s+/g).length){let t,a,r=(t=c.replace(/(\(|\))+/g,e=>"("===e?"( ":" )"),a={type:"org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",columns:C(),rowFilters:[],customRowFilterCombination:""},t.split(/\s+/).forEach(e=>{if(e.match(/\d/)){let t,r,n=JSON.parse(window.sessionStorage.getItem("openmrsHistory"))[parseInt(e)-1].parameters;t=n.customRowFilterCombination,r=a.rowFilters.length,n.customRowFilterCombination=t.replace(/\d+/g,e=>(parseInt(e)+r).toString()),a.customRowFilterCombination+=`(${n.customRowFilterCombination})`,a.rowFilters=a.rowFilters.concat(n.rowFilters)}else a.customRowFilterCombination+=` ${e} `}),{query:a});await e(r,d)}else(0,r.showSnackbar)({title:t("error","Error!"),kind:"error",isLowContrast:!0,subtitle:t("invalidComposition","Composition is not valid")});i(!1)}catch(e){i(!1),(0,r.showSnackbar)({title:t("error","Error!"),kind:"error",isLowContrast:!0,subtitle:t("invalidComposition","Composition is not valid")})}};return l().createElement(l().Fragment,null,l().createElement(o.TextInput,{labelText:t("composition","Composition"),"data-testid":"composition-query",id:"composition-query",onChange:e=>{var t;m(t=e.target.value),u("Composition of "+t)},value:c}),l().createElement("br",null),l().createElement(o.TextInput,{labelText:t("description","Description"),"data-testid":"composition-description",id:"composition-description",onChange:e=>u(e.target.value),value:d}),l().createElement("br",null),l().createElement("p",{className:D},t("compositionExplanationOne","A composition query combines together the results of multiple cohorts using the logical operators: AND, OR and NOT.")),l().createElement("br",null),l().createElement("p",{className:D},t("compositionExplanationTwo","To use this query you need to already have query results in your search history. Those existing query results can then be combined to yield the results of the composition query.")),l().createElement("br",null),l().createElement("p",{className:D},t("compositionExplanationThree","Example: if the search history #1 is a cohort of patients who are males, and if the search history #2 is a cohort of patients with ages between 23 and 35 years; then '1 AND 2' will result in a cohort of patients who are males with ages between 23 and 35 years.")),l().createElement("br",null),l().createElement(k,{onHandleReset:()=>{u(""),m("")},onHandleSubmit:h,isLoading:a}))};var I=a(2551),M=a.n(I);let Y=async e=>await (0,r.openmrsFetch)(`${r.restBaseUrl}/cohort/${e}`,{method:"DELETE"}),x=e=>l().createElement(o.Layer,null,l().createElement(o.Tile,{className:"-esm-cohort-builder__empty-data-style__tile___kGzLZ"},l().createElement(r.EmptyCardIllustration,null),l().createElement("p",{className:"-esm-cohort-builder__empty-data-style__content___zUidZ"},"There are no ",e.displayText.toLowerCase()," to display"))),O="-esm-cohort-builder__saved-cohort-options__menuItem___rX2ia",L="view",A="delete",P=({cohort:e,onViewCohort:t,onDeleteCohort:a})=>{let{t:n}=(0,s.useTranslation)(),i=async()=>{try{await t(e.id)}catch(e){(0,r.showSnackbar)({title:n("cohortViewError","Error viewing the cohort"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},c=async t=>{switch(t){case L:i();break;case A:m(e.id)}},m=t=>{let a=(0,r.showModal)("delete-cohort-modal",{closeModal:()=>a(),cohortName:e.name,cohortId:t,onDeleteCohort:d,size:"sm"})},d=async()=>{await a(e.id)};return l().createElement(o.OverflowMenu,{"aria-label":n("savedCohortsOptions","Saved cohorts options"),flipped:!0,direction:"bottom","data-testid":"options"},l().createElement(o.OverflowMenuItem,{className:O,"data-testid":"view",itemText:n("view","View"),onClick:()=>c(L)}),l().createElement(o.OverflowMenuItem,{className:O,"data-testid":"delete",hasDivider:!0,isDelete:!0,itemText:n("delete","Delete"),onClick:()=>c(A)}))},$="-esm-cohort-builder__cohort-builder__heading___fKg4I",q="-esm-cohort-builder__cohort-builder__tab___OIkeX",R="-esm-cohort-builder__cohort-builder__optionCell___0dfgH",B="-esm-cohort-builder__cohort-builder__optionHeader___IBQGc",F="-esm-cohort-builder__cohort-builder__text___Dk0eN",H=({onViewCohort:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(1),[c,m]=(0,n.useState)(10),{cohorts:d}=function(){let e=`${r.restBaseUrl}/cohort?v=full`,{data:t,isLoading:a,isValidating:l}=M()(e,r.openmrsFetch);return{cohorts:(0,n.useMemo)(()=>t?.data?.results?.map(e=>({id:e.uuid,name:e.name,description:e.description})),[t])??[],isLoading:a,isValidating:l}}(),u=[{key:"name",header:t("name","Name")},{key:"description",header:t("description","Description")}],h=async e=>{try{await Y(e),(0,r.showSnackbar)({title:t("cohortDeleted","Cohort deleted"),kind:"success",isLowContrast:!0,subtitle:t("cohortDeleted","Cohort deleted")})}catch(e){(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:e?.message})}};return l().createElement("div",{className:"-esm-cohort-builder__saved-cohorts__container___RcI67"},l().createElement("p",{className:F},t("savedCohortDescription","You can only search for Cohort Definitions that you have saved using a Name.")),l().createElement(o.DataTable,{rows:d,headers:u,useZebraStyles:!0},({rows:t,headers:r,getTableProps:n,getHeaderProps:s,getRowProps:i})=>l().createElement(o.Table,n(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,r.map(e=>l().createElement(o.TableHeader,s({header:e}),e.header)),l().createElement(o.TableHeader,{className:B}))),l().createElement(o.TableBody,null,t.slice((a-1)*c).slice(0,c).map((t,a)=>l().createElement(o.TableRow,{...i({row:t}),key:a},t.cells.map((e,t)=>l().createElement(o.TableCell,{key:t},e.value)),l().createElement(o.TableCell,{className:R},l().createElement(P,{cohort:d[a],onViewCohort:e,onDeleteCohort:h}))))))),d?.length>10&&l().createElement(o.Pagination,{backwardText:t("previousPage","Previous page"),forwardText:t("nextPage","Next page"),itemsPerPageText:t("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{i(e),m(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:d.length}),!d?.length&&l().createElement(x,{displayText:t("cohorts","cohorts")}))};async function z(){let e=await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/dataSetDefinition?v=full`,{method:"GET"}),t=[];return e.data.results.length>0&&e.data.results.map(e=>{let a={id:e.uuid,name:e.name.replace("[AdHocDataExport]",""),description:e.description};t.push(a)}),t}let U=async e=>await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/adhocdataset/${e}?purge=true`,{method:"DELETE"}),Q="-esm-cohort-builder__saved-queries-options__menuItem___Qs6Ro",V="delete",j="view",G=({query:e,onViewQuery:t,deleteQuery:a})=>{let{t:n}=(0,s.useTranslation)(),i=async e=>{switch(e){case j:c();break;case V:m()}},c=async()=>{try{await t(e.id)}catch(e){(0,r.showSnackbar)({title:n("QueryDeleteError","Something went wrong"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},m=()=>{let t=(0,r.showModal)("delete-query-modal",{closeModal:()=>t(),queryName:e.name,queryId:e.id,onDelete:d,size:"sm"})},d=async()=>{await a(e.id)};return l().createElement(o.OverflowMenu,{"aria-label":n("savedQueriesOptions","Saved queries options"),size:"md",flipped:!0,direction:"bottom"},l().createElement(o.OverflowMenuItem,{className:Q,"data-testid":"view",itemText:n("view","View"),onClick:()=>i(j)}),l().createElement(o.OverflowMenuItem,{className:Q,"data-testid":"delete",hasDivider:!0,isDelete:!0,itemText:n("delete","Delete"),onClick:()=>i(V)}))},W=({onViewQuery:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(1),[c,m]=(0,n.useState)(10),[d,u]=(0,n.useState)([]),h=async()=>{u(await z())},p=async e=>{try{await U(e),(0,r.showSnackbar)({title:t("success","Success"),kind:"success",isLowContrast:!0,subtitle:t("queryIsDeleted","the query is deleted")}),h()}catch(e){(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:e?.message})}};(0,n.useEffect)(()=>{h()},[]);let b=[{key:"name",header:t("name","Name")},{key:"description",header:t("description","Description")}];return l().createElement("div",{className:"-esm-cohort-builder__saved-queries__container___apr+8"},l().createElement("p",{className:F},t("savedQueryDescription","You can only search for Query Definitions that you have saved using a Name.")),l().createElement(o.DataTable,{rows:d,headers:b,useZebraStyles:!0},({rows:t,headers:r,getTableProps:n,getHeaderProps:s,getRowProps:i})=>l().createElement(o.Table,n(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,r.map(e=>l().createElement(o.TableHeader,s({header:e}),e.header)),l().createElement(o.TableHeader,{className:B}))),l().createElement(o.TableBody,null,t.slice((a-1)*c).slice(0,c).map((t,a)=>l().createElement(o.TableRow,{...i({row:t}),key:a},t.cells.map((e,t)=>l().createElement(o.TableCell,{key:t},e.value)),l().createElement(o.TableCell,{className:R},l().createElement(G,{query:d[a],onViewQuery:e,deleteQuery:p}))))))),d.length>10&&l().createElement(o.Pagination,{backwardText:t("previousPage","Previous page"),forwardText:t("nextPage","Next page"),itemsPerPageText:t("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{i(e),m(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:d.length}),!d.length&&l().createElement(x,{displayText:t("queries","queries")}))};var X=a(4353),Z=a.n(X),J=a(4861);async function K(e){let t=await (0,r.openmrsFetch)(`${r.restBaseUrl}/concept?v=full&q=${e}`,{method:"GET"}),a=[];return t.data.results.length>0&&(a=t.data.results.map(e=>{let t=e.descriptions.filter(e=>"en"==e.locale?e.description:"");return{uuid:e.uuid,units:e.units||"",answers:e.answers,hl7Abbrev:e.datatype.hl7Abbreviation,name:e.name.name,description:t.length>0?t[0].description:"no description available",datatype:e.datatype}})),a}let ee={searchContainer:"-esm-cohort-builder__search-concept__searchContainer___dpJim",search:"-esm-cohort-builder__search-concept__search___9eq8D",loader:"-esm-cohort-builder__search-concept__loader___RvR4m",concept:"-esm-cohort-builder__search-concept__concept___WbcYA",conceptList:"-esm-cohort-builder__search-concept__conceptList___XqGdL",text:"-esm-cohort-builder__search-concept__text___Ow696",notification:"-esm-cohort-builder__search-concept__notification___x7E6s"},et=({concept:e,searchText:t,setConcept:a,setSearchText:r})=>{let{t:i}=(0,s.useTranslation)(),[c,m]=(0,n.useState)([]),[d,u]=(0,n.useState)(""),[h,p]=(0,n.useState)(!1),[b,E]=(0,n.useState)(!1),g=async e=>{m([]),a(null),p(!0),E(!1);try{let t=await K(e);t.length?m(t):E(!0),p(!1)}catch(e){u(e.toString()),p(!1)}},_=(0,n.useRef)((0,J.A)(async e=>{e&&await g(e)},500)).current;return(0,n.useEffect)(()=>()=>{_.cancel()},[_]),l().createElement("div",null,l().createElement(o.Column,{className:ee.column},l().createElement("div",{className:ee.searchContainer},l().createElement(o.Search,{closeButtonLabelText:i("clearSearch","Clear search"),id:"concept-search",labelText:i("searchConcepts","Search Concepts"),onChange:e=>{r(e.target.value),_(e.target.value)},onClear:()=>{E(!1),m([])},placeholder:i("searchConcepts","Search Concepts"),value:t}),l().createElement("div",{className:ee.search},h?l().createElement(o.InlineLoading,{className:ee.loader,description:i("searching","Searching")+"..."}):l().createElement("ul",{className:ee.conceptList},c?.map((e,t)=>l().createElement("li",{role:"menuitem",className:ee.concept,key:t,onClick:()=>{a(e),m([]),E(!1)}},e.name))))),e&&l().createElement("span",{className:ee.text},i("patientsWithObservationsWhoseAnswerIs","Patients with observations whose answer is"),l().createElement("strong",null,' "',e.name,'"'),"."),t&&b&&l().createElement(o.Tile,null,l().createElement("span",null,i("noMatchingConcepts","No concepts were found that match"),l().createElement("strong",null,' "',t,'"'),".")),d&&l().createElement("span",null,d)))},ea="-esm-cohort-builder__search-by-concepts-style__column___fpjOs",er="-esm-cohort-builder__search-by-concepts-style__dateRange___unfDl",en="-esm-cohort-builder__search-by-concepts-style__multipleInputs___O7iAI",el=[{id:0,label:"<",value:"LESS_THAN"},{id:1,label:"<=",value:"LESS_EQUAL"},{id:2,label:"=",value:"EQUAL"},{id:3,label:">=",value:"GREATER_EQUAL"},{id:4,label:">",value:"GREATER_THAN"}],eo={CWE:"codedObsSearchAdvanced",NM:"numericObsSearchAdvanced",DT:"dateObsSearchAdvanced",ST:"dateObsSearchAdvanced",TS:"textObsSearchAdvanced",ZZ:"codedObsSearchAdvanced",BIT:"codedObsSearchAdvanced"},es=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,r]=(0,n.useState)(null),[i,c]=(0,n.useState)(0),[m,d]=(0,n.useState)(0),[u,h]=(0,n.useState)(0),[p,b]=(0,n.useState)("LESS_THAN"),[E,g]=(0,n.useState)("ANY"),[y,v]=(0,n.useState)(""),[S,w]=(0,n.useState)(""),[C,T]=(0,n.useState)(""),[D,N]=(0,n.useState)(!1),I=[{id:"option-0",label:t("haveObservations","Patients who have these observations"),value:"ANY"},{id:"option-1",label:t("haveNoObservations","Patients who do not have these observations"),value:"NO"}],M=[{id:"option-0",label:t("any","Any"),value:"ANY"},{id:"option-1",label:t("none","None"),value:"NO"},{id:"option-2",label:t("earliest","Earliest"),value:"FIRST"},{id:"option-3",label:t("recent","Most Recent"),value:"LAST"},{id:"option-4",label:t("lowest","Lowest"),value:"MIN"},{id:"option-5",label:t("highest","Highest"),value:"MAX"},{id:"option-6",label:t("average","Average"),value:"AVG"}],Y=async()=>{if(!a)return;N(!0);let t={modifier:"",operator1:p,value1:u>0?u.toString():"",question:a.uuid,onOrBefore:(()=>{if(i>0||m>0)return Z()().subtract(i,"days").subtract(m,"months").format()})()||S,onOrAfter:y,timeModifier:E},r=eo[a.hl7Abbrev],n={[r]:[]};Object.keys(t).forEach(e=>{""!==t[e]&&n[r].push({name:"modifier"===e?["CWE","TS"].includes(a.hl7Abbrev)?"values":"value1":e,value:"modifier"===e&&["CWE","TS"].includes(a.hl7Abbrev)?[t[e]]:t[e]})}),await e(_(n),((e,t)=>{let{timeModifier:a,onOrAfter:r,onOrBefore:n}=e,l=r?`since ${f(r)}`:"",o=n?`until ${f(n)}`:"";return`Patients with ${a} ${t} ${l} ${o}`.trim()})(t,a.name)),N(!1)};return l().createElement(l().Fragment,null,l().createElement("div",null,l().createElement(et,{setConcept:r,concept:a,searchText:C,setSearchText:T}),a?.hl7Abbrev==="NM"?l().createElement(l().Fragment,null,l().createElement(o.Column,{className:ea},l().createElement("div",{style:{display:"flex"}},l().createElement("div",{className:en},l().createElement("p",{style:{paddingRight:20}},t("whatObservations","What observations")),l().createElement(o.Dropdown,{id:"timeModifier",onChange:e=>g(e.selectedItem.value),initialSelectedItem:M[0],items:M,className:"-esm-cohort-builder__search-by-concepts-style__timeModifier___SeThC",label:"",titleText:""})))),l().createElement(o.Column,{className:ea},l().createElement("p",{className:"-esm-cohort-builder__search-by-concepts-style__value___FUIbI"},t("whatValues","What values")),l().createElement("div",{className:"-esm-cohort-builder__search-by-concepts-style__whatValuesInputs___5UXAP"},l().createElement("div",{className:"-esm-cohort-builder__search-by-concepts-style__operators___KUi3k"},l().createElement(o.ContentSwitcher,{selectedIndex:el[0].id,className:"-esm-cohort-builder__search-by-concepts-style__contentSwitcher___LXxCi",size:"lg",onChange:({index:e})=>b(el[e].value)},el.map(e=>l().createElement(o.Switch,{key:e.id,name:e.value,text:e.label})))),l().createElement("div",{className:en},l().createElement(o.NumberInput,{hideSteppers:!0,id:"operator-value",invalidText:t("numberIsNotValid","Number is not valid"),label:t("valueIn","Enter a value in ")+a.units,min:0,size:"sm",value:u,onChange:(e,{value:t})=>h(Number(t))}))))):l().createElement(o.Column,{className:ea},l().createElement(o.Dropdown,{id:"timeModifier","data-testid":"timeModifier",onChange:e=>g(e.selectedItem.value),initialSelectedItem:I[0],items:I,label:"",titleText:""})),l().createElement(o.Column,{className:er},l().createElement(o.Column,null,l().createElement(o.NumberInput,{hideSteppers:!0,id:"last-months","data-testid":"last-months",label:t("withinTheLast","Within the last months"),invalidText:t("numberIsNotValid","Number is not valid"),min:0,value:m,onChange:(e,{value:t})=>d(Number(t))})),l().createElement(o.Column,null,l().createElement(o.NumberInput,{hideSteppers:!0,label:t("lastDays","and / or days"),id:"last-days","data-testid":"last-days",invalidText:t("numberIsNotValid","Number is not valid"),min:0,value:i,onChange:(e,{value:t})=>c(Number(t))}))),l().createElement("div",{className:er},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>v(Z()(e[0]).format()),value:y&&Z()(y).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"startDate",labelText:t("dateRange","Date range start date"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>w(Z()(e[0]).format()),value:S&&Z()(S).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"endDate",labelText:t("endDate","End date"),placeholder:"DD-MM-YYYY",size:"md"}))))),l().createElement(k,{isLoading:D,onHandleSubmit:Y,onHandleReset:()=>{r(null),c(0),T(""),v(""),w(""),d(0),h(0),b("LESS_THAN"),g("ANY")}}))},ei="-esm-cohort-builder__search-by-demographics-style__contentSwitcher___L5GhV",ec="-esm-cohort-builder__search-by-demographics-style__column___agceq",em="-esm-cohort-builder__search-by-demographics-style__switch___Q01uO",ed=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,r]=(0,n.useState)("alive"),[i,c]=(0,n.useState)("all"),[m,u]=(0,n.useState)(""),[h,p]=(0,n.useState)(""),[b,E]=(0,n.useState)(0),[g,y]=(0,n.useState)(0),[v,S]=(0,n.useState)(!1),w=[{id:0,label:t("all","All"),value:"all"},{id:1,label:t("males","Male"),value:"males"},{id:3,label:t("females","Female"),value:"females"}],C=[{id:0,label:t("alive","Alive"),value:"alive"},{id:1,label:t("dead","Dead"),value:"dead"}],f=async()=>{S(!0);let t={gender:i,minAge:b,maxAge:g,birthDayStartDate:m,birthDayEndDate:h,livingStatus:a};await e((({gender:e,minAge:t,maxAge:a,birthDayStartDate:r,birthDayEndDate:n,livingStatus:l})=>{let o={gender:e};t&&a?o.ageRangeOnDate=[{name:"minAge",value:t},{name:"maxAge",value:a}]:t?o.atLeastAgeOnDate=[{name:"minAge",value:t}]:o.upToAgeOnDate=[{name:"maxAge",value:a}],r&&n&&(o.bornDuringPeriod=[{name:"startDate",dataType:"date",value:r},{name:"endDate",dataType:"date",value:n}]),o.diedDuringPeriod=[{name:"endDate",dataType:"date",value:Z()().format(),livingStatus:l}];let s=_(o);if("all"===o.gender){let e=["males","females","unknownGender"].map(e=>({type:"org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",key:`reporting.library.cohortDefinition.builtIn.${e}`})),{query:{rowFilters:t,customRowFilterCombination:a}}=s,r=t=t.length>0?[...t,...e]:e,n=a;a=n?`(${r.length-2} OR ${r.length-1} OR ${r.length}) AND ${n}`:"(1 OR 2 OR 3)"}return s})(t),(({gender:e,minAge:t,maxAge:a,birthDayStartDate:r,birthDayEndDate:n,livingStatus:l})=>{let o="all"!=e?`${"males"===e?"Male":"Female"} Patients`:"All Patients";return(t||a)&&(t&&a?o+=` with ages between ${t} and ${a}`:o+=t?` with minimum age of ${t}`:` with maximum age of ${a}`,o+=" years"),(""!=r||""!=n)&&(r&&n?o+=` and birthdate between ${r} and ${n}`:o+=t?` and born before ${r}`:` and born before ${n}`),l&&(o+=` that are ${l}`),o})(t)),S(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("p",{className:d()("-esm-cohort-builder__search-by-demographics-style__text___x8MO2","-esm-cohort-builder__search-by-demographics-style__genderTitle___06Nb4")},t("gender","Gender")),l().createElement("div",{className:"-esm-cohort-builder__search-by-demographics-style__genderContainer___VkE-3"},l().createElement("div",{className:em},l().createElement(o.ContentSwitcher,{selectedIndex:w[0].id,className:ei,size:"lg",onChange:({index:e})=>c(w[e].value)},w.map(e=>l().createElement(o.Switch,{"data-testid":e.label,key:e.id,name:e.value,text:e.label})))),l().createElement("div",{className:em},l().createElement(o.ContentSwitcher,{selectedIndex:C[0].id,className:ei,size:"lg",onChange:({index:e})=>r(C[e].value)},C.map(e=>l().createElement(o.Switch,{key:e.id,name:e.value,text:e.label})))))),l().createElement("div",{className:ec},l().createElement(o.Column,{className:"-esm-cohort-builder__search-by-demographics-style__age___DEuDD"},l().createElement(o.Column,null,l().createElement(o.NumberInput,{"data-testid":"minAge",hideSteppers:!0,id:"minAge",invalidText:t("minAgeIsNotValid","The age must be greater than 0"),label:t("ageBetween","Age between"),min:0,onChange:(e,{value:t})=>E(Number(t)),value:b})),l().createElement(o.Column,null,l().createElement(o.NumberInput,{"data-testid":"maxAge",hideSteppers:!0,id:"maxAge",invalidText:t("maxAgeIsNotValid","The age must be less than 200"),label:t("and","and"),max:200,min:0,onChange:(e,{value:t})=>y(Number(t)),value:g})))),l().createElement("div",{className:ec},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>u(Z()(e[0]).format()),value:m&&Z()(m).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"startDate",labelText:t("birthDate","Birth date between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{allowInput:!1,datePickerType:"single",onChange:e=>p(Z()(e[0]).format()),value:h&&Z()(h).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"endDate",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{isLoading:v,onHandleSubmit:f,onHandleReset:()=>{y(0),E(0),p(""),u("")}}))},eu="-esm-cohort-builder__search-by-drug-orders-style__column___nQLUC",eh=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),{drugs:a,drugsError:i}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/drug`,r.openmrsFetch);return(0,n.useMemo)(()=>{let a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,drugs:a,drugsError:t}},[e,t])}(),{careSettings:c,careSettingsError:m}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/caresetting`,r.openmrsFetch);return(0,n.useMemo)(()=>{let a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,careSettings:a,careSettingsError:t}},[e,t])}(),[d,u]=(0,n.useState)(""),[p,b]=(0,n.useState)(""),[E,g]=(0,n.useState)(""),[y,v]=(0,n.useState)(""),[S,w]=(0,n.useState)(null),[C,f]=(0,n.useState)(null),[T,D]=(0,n.useState)(!1);i&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:i?.message}),m&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:m?.message});let N=async()=>{D(!0);let t={selectedDrugs:S,selectedCareSetting:C,activeOnOrAfter:d,activeOnOrBefore:p,activatedOnOrAfter:E,activatedOnOrBefore:y};await e((({selectedDrugs:e,selectedCareSetting:t,activeOnOrBefore:a,activeOnOrAfter:r,activatedOnOrBefore:n,activatedOnOrAfter:l})=>{let o={drugOrderSearch:[]};return r&&o.drugOrderSearch.push({name:"activeOnOrAfter",value:r}),l&&o.drugOrderSearch.push({name:"activatedOnOrAfter",value:l}),n&&o.drugOrderSearch.push({name:"activatedOnOrBefore",value:n}),t&&o.drugOrderSearch.push({name:"careSetting",value:t.value}),e.length&&o.drugOrderSearch.push({name:"drugs",value:e.map(e=>e.value)}),a&&o.drugOrderSearch.push({name:"activeOnOrBefore",value:a}),_(o)})(t),(({selectedDrugs:e,selectedCareSetting:t,activeOnOrBefore:a,activeOnOrAfter:n,activatedOnOrBefore:l,activatedOnOrAfter:o})=>{let s="Patients who taking "+e.map(e=>e.label).join(", ").replace(/,(?=[^,]*$)/," and");if(t&&(s+=` from ${t.label}`),n){let e=(0,r.formatDate)(new Date(n),{mode:"standard"});a?s+=` from ${e}`:s+=` on or after ${e}`}if(a){let e=(0,r.formatDate)(new Date(a),{mode:"standard"});n?s+=` to ${e}`:s+=` on or before ${e}`}if(o){let e=(0,r.formatDate)(new Date(o),{mode:"standard"});l?s+=` from ${e}`:s+=` on or after ${e}`}if(l){let e=(0,r.formatDate)(new Date(l),{mode:"standard"});o?s+=` to ${e}`:s+=` on or before ${e}`}return s})(t)),D(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"drugs","data-testid":"drugs",onChange:e=>w(e.selectedItems),items:a,label:t("selectDrugs","Select drugs")}))),l().createElement("div",{className:eu},l().createElement(o.Column,null,l().createElement(o.Dropdown,{id:"careSettings","data-testid":"careSettings",onChange:e=>f(e.selectedItem),initialSelectedItem:c[0],items:c,label:t("selectCareSettings","Select a care setting"),titleText:""}))),l().createElement("div",{className:eu},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>u(Z()(e[0]).format()),value:d&&Z()(d).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activeOnOrAfter",labelText:t("using","Using between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>b(Z()(e[0]).format()),value:p&&Z()(p).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activeOnOrBefore",labelText:t("to","to"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement("div",{className:eu},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>g(Z()(e[0]).format()),value:E&&Z()(E).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activatedOnOrAfter",labelText:t("used","Used between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>v(Z()(e[0]).format()),value:y&&Z()(y).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activatedOnOrBefore",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{onHandleReset:()=>{w(null),f(null),u(""),b(""),g(""),v("")},onHandleSubmit:N,isLoading:T}))},ep="-esm-cohort-builder__search-by-encounters-style__column___2KGkF",eb="-esm-cohort-builder__search-by-encounters-style__multipleInputs___AQXO8",eE=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(0),[c,m]=(0,n.useState)(0),{encounterTypes:d,encounterTypesError:u}=(()=>{let{data:e,error:t}=h()(`${r.restBaseUrl}/encountertype`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,encounterTypes:a,encounterTypesError:t}})(),[p,E]=(0,n.useState)([]),[g,y]=(0,n.useState)([]),[v,S]=(0,n.useState)([]),{locations:w,locationsError:C}=b(),{forms:f,formsError:T}=(()=>{let{data:e,error:t}=h()(`${r.restBaseUrl}/form`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,forms:a,formsError:t}})(),[D,N]=(0,n.useState)(""),[I,M]=(0,n.useState)(""),[Y,x]=(0,n.useState)(!1);C&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:C?.message}),T&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:T?.message}),u&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:u?.message});let O=async()=>{x(!0);let t={onOrAfter:I,atLeastCount:a,atMostCount:c,encounterForms:v,encounterLocations:g,onOrBefore:D,selectedEncounterTypes:p};await e((({onOrAfter:e,atLeastCount:t,atMostCount:a,encounterForms:r,encounterLocations:n,onOrBefore:l,selectedEncounterTypes:o})=>{let s={encounterSearchAdvanced:[]};return e&&s.encounterSearchAdvanced.push({name:"onOrAfter",value:e}),t&&s.encounterSearchAdvanced.push({name:"atLeastCount",value:t}),a&&s.encounterSearchAdvanced.push({name:"atMostCount",value:a}),r.length&&s.encounterSearchAdvanced.push({name:"formList",value:r.map(e=>e.value)}),n.length&&s.encounterSearchAdvanced.push({name:"locationList",value:n.map(e=>e.value)}),l&&s.encounterSearchAdvanced.push({name:"onOrBefore",value:l}),o.length>0&&s.encounterSearchAdvanced.push({name:"encounterTypeList",value:o.map(e=>e.value)}),_(s)})(t),(({selectedEncounterTypes:e,encounterLocations:t,encounterForms:a,atLeastCount:r,atMostCount:n,onOrAfter:l,onOrBefore:o})=>{let s="Patients with Encounter of",i=e.map(e=>e.label).join(", ").replace(/,(?=[^,]*$)/," and ");return s+=i?` Type${i.length>1?"s":""} ${i}`:" any Type",t.length&&(s+=` at ${t.map(e=>e.label).join(", ")}`),a.length&&(s+=` from ${a.map(e=>e.label).join(", ")}`),r&&(s+=` at least ${r} ${r>1?"times":"time"}`),n&&(s+=` ${r?" and":""} at most ${n} ${n>1?"times":"time"}`),l&&(o?s+=` from ${l}`:s+=` on or after ${l}`),o&&(l?s+=` to ${o}`:s+=` on or before ${o}`),s})(t)),x(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"encounters",onChange:e=>E(e.selectedItems),items:d,label:t("selectEncounterTypes","Select encounter types")}))),l().createElement(o.MultiSelect,{id:"forms","data-testid":"forms",onChange:e=>S(e.selectedItems),items:f,label:t("selectForms","Select forms")}),l().createElement(o.MultiSelect,{id:"locations",onChange:e=>y(e.selectedItems),items:w,label:t("selectLocations","Select locations")}),l().createElement("div",{className:ep},l().createElement(o.Column,{className:"-esm-cohort-builder__search-by-encounters-style__encounterRange___0Q8rh"},l().createElement("div",{className:eb},l().createElement(o.NumberInput,{hideSteppers:!0,id:"atLeastCount","data-testid":"atLeastCount",label:t("atLeast","at least"),min:0,size:"sm",value:a,onChange:(e,{value:t})=>i(Number(t))})),l().createElement("div",{className:eb},l().createElement(o.NumberInput,{hideSteppers:!0,id:"atMostCount","data-testid":"atMostCount",label:t("upto","upto this many"),min:0,size:"sm",value:c,onChange:(e,{value:t})=>m(Number(t))})))),l().createElement("div",{className:ep},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>M(Z()(e[0]).format()),value:I&&Z()(I).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"onOrAfter",labelText:t("from","From"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>N(Z()(e[0]).format()),value:D&&Z()(D).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"onOrBefore",labelText:t("to","to"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{isLoading:Y,onHandleSubmit:O,onHandleReset:()=>{i(0),m(0),N(""),M("")}}))},eg="-esm-cohort-builder__search-by-enrollments-style__column___10FcT",e_=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),{programs:a,programsError:i}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/program`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.name,value:e.uuid})}),{isLoading:!e&&!t,programs:a,programsError:t}}(),{locations:c,locationsError:m}=b(),[d,u]=(0,n.useState)(""),[p,E]=(0,n.useState)(""),[g,y]=(0,n.useState)(""),[v,S]=(0,n.useState)(""),[w,C]=(0,n.useState)(null),[f,T]=(0,n.useState)(null),[D,N]=(0,n.useState)(!1);i&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:i?.message}),m&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:m?.message});let I=async()=>{N(!0);let t={enrolledOnOrAfter:d,enrolledOnOrBefore:p,completedOnOrAfter:g,completedOnOrBefore:v,selectedPrograms:f,selectedLocations:w};await e((({enrolledOnOrAfter:e,enrolledOnOrBefore:t,completedOnOrAfter:a,completedOnOrBefore:r,selectedPrograms:n,selectedLocations:l})=>_({patientsWithEnrollment:[{name:"programs",value:n?.map(e=>e.value)},e&&{name:"enrolledOnOrAfter",value:e},t&&{name:"enrolledOnOrBefore",value:t},a&&{name:"completedOnOrAfter",value:a},r&&{name:"completedOnOrBefore",value:r},{name:"locationList",value:l?.map(e=>e.value)}]}))(t),(({selectedPrograms:e,selectedLocations:t})=>{let a=`Patients enrolled in ${e?.map(e=>e.label).join(", ")}`;return t?.length&&(a+=` at ${t?.map(e=>e.label).join(", ")}`),a})(t)),N(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"programs","data-testid":"programs",onChange:e=>T(e.selectedItems),items:a,label:t("selectPrograms","Select programs")}))),l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"locations","data-testid":"locations",onChange:e=>C(e.selectedItems),items:c,label:t("selectLocations","Select locations")}))),l().createElement("div",{className:eg},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>u(Z()(e[0]).format()),value:d&&Z()(d).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"enrolledOnOrAfter",labelText:t("enrolledBetween","Enrolled between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>E(Z()(e[0]).format()),value:p&&Z()(p).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"enrolledOnOrBefore",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement("div",{className:eg},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>y(Z()(e[0]).format()),value:g&&Z()(g).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"completedOnOrAfter",labelText:t("completedBetween","Completed between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>S(Z()(e[0]).format()),value:v&&Z()(v).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"completedOnOrBefore",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{onHandleReset:()=>{T(null),u(""),E(""),y(""),S("")},onHandleSubmit:I,isLoading:D}))},ey=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),a=[{id:0,label:t("anyEncounter","Any Encounter"),value:"ANY"},{id:1,label:t("mostRecentEncounter","Most Recent Encounter"),value:"LAST"},{id:2,label:t("earliestEncounter","Earliest Encounter"),value:"FIRST"}],{locations:i,locationsError:c}=b(),[m,d]=(0,n.useState)(null),[u,h]=(0,n.useState)(a[0]),[p,E]=(0,n.useState)(!1);c&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:c?.message});let g=async()=>{var t;let a;E(!0),await e((t=u.value,a=[],m?.map(e=>a.push(e.value)),_({encounterSearchAdvanced:[{name:"locationList",value:a},{name:"timeQualifier",value:t}]})),((e,t)=>{let a=`Patients in ${t?.map(e=>e.label).join(", ")}`;switch(e){case"FIRST":a+=" (by method EARLIEST_ENCOUNTER).";break;case"LAST":a+=" (by method LATEST_ENCOUNTER).";break;default:a+=" (by method ANY_ENCOUNTER)."}return a})(u.label,m)),E(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{"aria-label":t("selectLocations","Select locations"),id:"locations","data-testid":"locations",onChange:e=>d(e.selectedItems),items:i,label:t("selectLocations","Select locations"),placeholder:t("searchForALocation","Search for a location")}))),l().createElement("div",{className:"-esm-cohort-builder__search-by-location-style__column___yC9N2"},l().createElement(o.Column,null,l().createElement(o.Dropdown,{id:"methods","data-testid":"methods",onChange:e=>h(e.selectedItem),initialSelectedItem:a[0],items:a,label:t("selectMethod","Select a method"),titleText:""}))),l().createElement(k,{onHandleReset:()=>{d(null),h(null)},onHandleSubmit:g,isLoading:p}))},ev=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),{personAttributes:a,personAttributesError:i}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/personattributetype`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,personAttributes:a,personAttributesError:t}}(),[c,m]=(0,n.useState)([]),[d,u]=(0,n.useState)(null),[p,b]=(0,n.useState)(!1);i&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:i?.message});let E=async()=>{var t;let r,n;b(!0);let l=a?.find(e=>e.value==d);await e(_({personWithAttribute:[{name:"attributeType",value:d},{name:"values",value:c}]}),(t=l?.label,r="Patients",n=c.length>0?c.join(", ").replace(/,(?=[^,]*$)/," or"):"",r+=t?` with${n?"":" any"} ${t}`:t,r+=n?` equal to ${n.length>1&&"either"} ${n}`:"")),b(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.Dropdown,{id:"personAttributes","data-testid":"personAttributes",onChange:e=>u(e.selectedItem.value),items:a,label:t("selectAttribute","Select a person attribute"),titleText:""}))),l().createElement("div",{className:"-esm-cohort-builder__search-by-person-attributes-style__column___Tvomw"},l().createElement(o.Column,null,l().createElement(o.TextInput,{id:"selectedAttributeValues","data-testid":"selectedAttributeValues",disabled:!d,labelText:t("selectedAttributeValues","Enter Comma Delimited Values"),onChange:e=>m(e.target.value.trim().split(","))}))),l().createElement(k,{onHandleReset:()=>{u(null),m([])},onHandleSubmit:E,isLoading:p}))};async function eS(e){return await (0,r.openmrsFetch)(`${r.restBaseUrl}/cohort`,{method:"POST",headers:{"Content-Type":"application/json"},body:e})}async function ew(e){return await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/adhocdataset`,{method:"POST",headers:{"Content-Type":"application/json"},body:e})}let eC="-esm-cohort-builder__search-history-options__menuItem___iYtpR",ef="delete",eT="download",ek="saveCohort",eD="saveQuery",eN=async(e,t,a,n)=>{let l=[],{patients:o}=a;o.forEach(e=>l.push(parseInt(e.id)));try{await eS({display:e,memberIds:l,description:t,name:e}),(0,r.showSnackbar)({title:n("success","Success"),kind:"success",isLowContrast:!0,subtitle:n("cohortSaved","Cohort created successfully")})}catch(e){(0,r.showSnackbar)({title:n("errorCreatingCohort","Error creating the cohort"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},eI=({searchItem:e,updateSearchHistory:t})=>{let{t:a}=(0,s.useTranslation)(),[i,c]=(0,n.useState)(""),[m,d]=(0,n.useState)(""),[u,h]=(0,n.useState)(""),[p,b]=(0,n.useState)(""),E=async t=>{let{patients:a,description:r}=e;switch(t){case ek:d(r),S();break;case eD:b(r),y();break;case eT:let n=new Blob(["patient_id, full_name, age, gender\n"+a.map(e=>Object.keys({patientId:e.patientId,name:e.name,age:e.age,gender:e.gender}).map(t=>`"${e[t]}"`).join(",")).join("\n")],{type:"text/csv;charset=utf-8;"}),l=URL.createObjectURL(n),o=document.createElement("a");o.href=l,o.setAttribute("download",r),o.click();break;case ef:v()}},g=async()=>{try{t(e),(0,r.showSnackbar)({title:a("success","Success"),kind:"success",isLowContrast:!0,subtitle:"the search item is deleted"})}catch(e){(0,r.showSnackbar)({title:a("searchItemDeleteError","Error deleting the cohort"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},_=async()=>{try{let{parameters:t}=e;t.name=u,t.description=p,await ew(t),h(""),b(""),(0,r.showSnackbar)({title:a("success","Success"),kind:"success",isLowContrast:!0,subtitle:"the query is saved"})}catch(e){(0,r.showSnackbar)({title:a("queryDeleteError","Error saving the query"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},y=()=>{let e=(0,r.showModal)("save-query-modal",{closeModal:()=>e(),onSaveQuery:_,size:"sm"})},v=()=>{let t=(0,r.showModal)("clear-item-from-search-history-modal",{closeModal:()=>t(),onRemove:g,searchItemName:e?.description,size:"sm"})},S=()=>{let t=(0,r.showModal)("save-cohort-modal",{closeModal:()=>t(),onSave:(t,r)=>eN(t,r,e,a),size:"sm"})};return l().createElement(o.OverflowMenu,{"aria-label":a("searchHistoryOptions","Search history options"),size:"md",flipped:!0,direction:"top","data-testid":"options"},l().createElement(o.OverflowMenuItem,{className:eC,"data-testid":"save-cohort",itemText:a("saveCohort","Save cohort"),onClick:()=>E(ek)}),l().createElement(o.OverflowMenuItem,{className:eC,"data-testid":"save-query",itemText:a("saveQuery","Save query"),onClick:()=>E(eD)}),l().createElement(o.OverflowMenuItem,{className:eC,itemText:a("downloadResults","Download results"),onClick:()=>E(eT)}),l().createElement(o.OverflowMenuItem,{className:eC,"data-testid":"deleteFromHistory",hasDivider:!0,isDelete:!0,itemText:a("deleteFromHistory","Delete from history"),onClick:()=>E(ef)}))},eM=({isHistoryUpdated:e,setIsHistoryUpdated:t})=>{let{t:a}=(0,s.useTranslation)(),[i,c]=(0,n.useState)([]),[m,d]=(0,n.useState)(1),[u,h]=(0,n.useState)(10);(0,n.useEffect)(()=>{if(e){let e,a;c((e=JSON.parse(window.sessionStorage.getItem("openmrsHistory")),a=[],e?.map((e,t)=>a.push({...e,id:(t+1).toString(),results:e.patients.length})),a)),t(!1)}},[e,t]);let p=[{key:"id",header:"#"},{key:"description",header:a("query","Query")},{key:"results",header:a("results","Results")}],b=()=>{window.sessionStorage.removeItem("openmrsHistory"),c([])},E=e=>{let t=[...i].filter((t,a)=>a!=i.indexOf(e));c(t),window.sessionStorage.setItem("openmrsHistory",JSON.stringify(t))};return l().createElement("div",{className:"-esm-cohort-builder__search-history-style__container___KJBMK"},l().createElement("div",{className:"-esm-cohort-builder__search-history-style__header___C-R7x"},l().createElement("p",{className:$},a("searchHistory","Search History")),i.length>0&&l().createElement(o.Button,{kind:"danger--tertiary",onClick:()=>{let e=(0,r.showModal)("clear-search-history-modal",{closeModal:()=>e(),onClearHistory:b,size:"sm"})}},a("clearSearchHistory","Clear search history"))),l().createElement(o.DataTable,{rows:i,headers:p,useZebraStyles:!0},({rows:e,headers:t,getTableProps:a,getHeaderProps:r,getRowProps:n})=>l().createElement(o.Table,a(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,t.map(e=>l().createElement(o.TableHeader,r({header:e}),e.header)),l().createElement(o.TableHeader,{className:B}))),l().createElement(o.TableBody,null,e.slice((m-1)*u).slice(0,u).map((e,t)=>l().createElement(o.TableRow,n({row:e}),e.cells.map(e=>l().createElement(o.TableCell,{key:e.id},e.value)),l().createElement(o.TableCell,{className:R},l().createElement(eI,{searchItem:i[t],updateSearchHistory:E}))))))),i.length>10&&l().createElement(o.Pagination,{backwardText:a("previousPage","Previous page"),forwardText:a("nextPage","Next page"),itemsPerPageText:a("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{d(e),h(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:i.length}),!i.length&&l().createElement(x,{displayText:a("data","data")}))},eY=({patients:e})=>{let[t,a]=(0,n.useState)(1),[r,i]=(0,n.useState)(10),{t:c}=(0,s.useTranslation)(),m=[{key:"id",header:c("openmrsId","OpenMRS ID")},{key:"name",header:c("name","Name")},{key:"age",header:c("age","Age")},{key:"gender",header:c("gender","Gender")}];return l().createElement("div",{className:"-esm-cohort-builder__search-results-table__container___y4+06"},l().createElement("p",{className:$},c("searchResults","Search Results")),l().createElement(o.DataTable,{rows:e,headers:m,useZebraStyles:!0},({rows:e,headers:a,getTableProps:n,getHeaderProps:s,getRowProps:i})=>l().createElement(o.Table,n(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,a.map(e=>l().createElement(o.TableHeader,s({header:e}),e.header)))),l().createElement(o.TableBody,null,e.slice((t-1)*r).slice(0,r).map((e,t)=>l().createElement(o.TableRow,{...i({row:e}),key:t},e.cells.map((e,t)=>l().createElement(o.TableCell,{key:t},e.value))))))),e.length>10&&l().createElement(o.Pagination,{backwardText:c("previousPage","Previous page"),forwardText:c("nextPage","Next page"),itemsPerPageText:c("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{a(e),i(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:e.length}),!e.length&&l().createElement(x,{displayText:c("data","data")}))};var ex=a(9785),eO=a(3285),eL=a(4476);let eA={featureName:"cohort-builder",moduleName:"@openmrs/esm-cohort-builder"},eP=a(4767);function e$(){}let eq=(0,r.getSyncLifecycle)(()=>{let{t:e}=(0,s.useTranslation)(),[t,a]=(0,n.useState)([]),[i,c]=(0,n.useState)(!0),m="tablet"===(0,r.useLayoutType)(),u=(t,n)=>new Promise(l=>{a([]),p(t).then(({data:{rows:o}})=>{var s;let i,m;o.map(e=>{e.id=e.patientId.toString(),e.name=`${e.firstname} ${e.lastname}`}),a(o),s=t.query,i=JSON.parse(window.sessionStorage.getItem("openmrsHistory")),m=[],m=i?[...i,{description:n,patients:o,parameters:s}]:[{description:n,patients:o,parameters:s}],window.sessionStorage.setItem("openmrsHistory",JSON.stringify(m)),(0,r.showSnackbar)({title:e("searchCompleted","Search completed"),kind:"success",isLowContrast:!0,subtitle:e("noOfResultsFound","{{count}} results found",{count:o.length})}),c(!0),l(!0)}).catch(t=>{(0,r.showSnackbar)({title:e("error","Error"),kind:"error",isLowContrast:!1,subtitle:t?.message}),l(!0)})}),h=async t=>{try{let n=await E(t);a(n),(0,r.showSnackbar)({title:e("searchCompleted","Search completed"),kind:"success",isLowContrast:!0,subtitle:e("noOfResultsFound","{{count}} results found",{count:n.length})})}catch(t){(0,r.showSnackbar)({title:e("error","Error"),kind:"error",isLowContrast:!1,subtitle:t?.message})}},b=async t=>{try{let n=await g(t);a(n),(0,r.showSnackbar)({title:e("searchCompleted","Search completed"),kind:"success",isLowContrast:!0,subtitle:e("noOfResultsFound","{{count}} results found",{count:n.length})})}catch(t){(0,r.showSnackbar)({title:e("error","Error"),kind:"error",isLowContrast:!1,subtitle:t?.message})}},_=[{name:e("concepts","Concepts"),component:l().createElement(es,{onSubmit:u})},{name:e("demographics","Demographics"),component:l().createElement(ed,{onSubmit:u})},{name:e("personAttributes","Person Attributes"),component:l().createElement(ev,{onSubmit:u})},{name:e("encounters","Encounters"),component:l().createElement(eE,{onSubmit:u})},{name:e("location","Location"),component:l().createElement(ey,{onSubmit:u})},{name:e("enrollments","Enrollments"),component:l().createElement(e_,{onSubmit:u})},{name:e("drugOrder","Drug Order"),component:l().createElement(eh,{onSubmit:u})},{name:e("composition","Composition"),component:l().createElement(N,{onSubmit:u})},{name:e("savedDefinitions","Saved Cohorts"),component:l().createElement(H,{onViewCohort:b})},{name:e("savedDefinitions","Saved Queries"),component:l().createElement(W,{onViewQuery:h})}];return l().createElement("div",null,l().createElement(r.PageHeader,{className:"-esm-cohort-builder__cohort-builder__header___VRsag"},l().createElement(r.PageHeaderContent,{illustration:l().createElement(r.CohortsPictogram,null),title:e("cohortBuilder","Cohort Builder")})),l().createElement("div",{className:d()("-esm-cohort-builder__cohort-builder__mainContainer___LXqCB","-esm-cohort-builder__cohort-builder__cohortBuilder___IqfBP")},l().createElement("div",{className:d()(m?"-esm-cohort-builder__cohort-builder__tabletContainer___7xD+u":"-esm-cohort-builder__cohort-builder__desktopContainer___I5sch")},l().createElement("div",{className:"-esm-cohort-builder__cohort-builder__tabContainer___u8YU-"},l().createElement("p",{className:$},e("searchCriteria","Search Criteria")),l().createElement("div",{className:q},l().createElement(o.Tabs,null,l().createElement(o.TabList,{"aria-label":"navigation"},_.map((e,t)=>l().createElement(o.Tab,{className:q,key:t},e.name))),l().createElement(o.TabPanels,null,_.map((e,t)=>l().createElement(o.TabPanel,{key:t},e.component)))))),l().createElement(eY,{patients:t}),l().createElement(eM,{isHistoryUpdated:i,setIsHistoryUpdated:c}))))},eA),eR=(0,r.getSyncLifecycle)(()=>{let{t:e}=(0,s.useTranslation)();return l().createElement(o.Layer,null,l().createElement(o.ClickableTile,{href:`${window.spaBase}/cohort-builder`},l().createElement("div",null,l().createElement("div",{className:"heading"},e("manageCohorts","Manage Cohorts")),l().createElement("div",{className:"content"},e("cohortBuilder","Cohort Builder"))),l().createElement("div",{className:"iconWrapper"},l().createElement(c.Qp,{size:16}))))},eA),eB=(0,r.getSyncLifecycle)(({closeModal:e,onRemove:t,searchItemName:a})=>{let{t:c}=(0,s.useTranslation)(),[m,d]=(0,n.useState)(!1);return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:c("clearItemFromHistory","Clear item from search history")}),l().createElement(o.ModalBody,null,l().createElement("p",null,c("removeItemFromSearchHistory","Are you sure you want to remove this item from the search history?")),l().createElement("br",null),l().createElement("p",null,l().createElement("strong",null,'"',a,'"'))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,kind:"danger",onClick:()=>{d(!0),t(),d(!1),e()},disabled:m},m?l().createElement(o.InlineLoading,{description:c("removing","Removing")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("delete")))))},eA),eF=(0,r.getSyncLifecycle)(({closeModal:e,onClearHistory:t,searchItemName:a})=>{let{t:c}=(0,s.useTranslation)(),[m,d]=(0,n.useState)(!1);return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:c("clearSearchHistory","Clear search history")}),l().createElement(o.ModalBody,null,l().createElement("p",null,c("clearSearchHistoryModalText","Are you sure you want to clear the search history?"))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,disabled:m,kind:"danger",onClick:()=>{d(!0),t(),d(!1),e()}},m?l().createElement(o.InlineLoading,{description:c("clearing","Clearing")+"..."}):l().createElement("span",null,c("clearHistory","Clear history")))))},eA),eH=(0,r.getSyncLifecycle)(({closeModal:e,cohortName:t,onDeleteCohort:a})=>{let{t:i}=(0,s.useTranslation)(),[c,m]=(0,n.useState)(!1);return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:i("deleteCohort","Delete cohort")}),l().createElement(o.ModalBody,null,l().createElement("p",null,i("deleteCohortModalText","Are you sure you want to delete the cohort")," ",l().createElement("strong",null,'"',t,'"'),"?")),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:"-esm-cohort-builder__delete-cohort__deleteButton___15Gkt",kind:"danger",onClick:()=>{m(!0),a(),m(!1),e()},disabled:c},c?l().createElement(o.InlineLoading,{description:i("deleting","Deleting")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("delete")))))},eA),ez=(0,r.getSyncLifecycle)(({closeModal:e,queryName:t,queryId:a,onDelete:i})=>{let{t:c}=(0,s.useTranslation)(),[m,d]=(0,n.useState)(!1),u=async()=>{d(!0),await i(a),d(!1)};return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:c("deleteSavedQuery","Delete saved query")}),l().createElement(o.ModalBody,null,l().createElement("p",null,c("deleteSavedQueryConfirmation","Are you sure you want to delete this saved query?"))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{kind:"danger",onClick:u,disabled:m},m?l().createElement(o.InlineLoading,{description:c("deleting","Deleting")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("delete")))))},eA),eU=(0,r.getSyncLifecycle)(({closeModal:e,onSave:t})=>{let{t:a}=(0,s.useTranslation)(),{control:n,handleSubmit:c,formState:{errors:m}}=(0,ex.mN)({resolver:(0,eO.u)(eL.z.object({name:eL.z.string({required_error:a("cohortNameRequired","Cohort name is required")}).trim().min(1,a("cohortNameRequired","Cohort name is required")),description:eL.z.string({required_error:a("cohortDescriptionRequired","Description is required")}).trim().min(1,a("cohortDescriptionRequired","Description is required"))})),mode:"onChange"}),d=a=>{t(a.name.trim(),a.description.trim()),e()};return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:a("saveCohort","Save cohort")}),l().createElement(o.ModalBody,null,l().createElement("form",{onSubmit:c(d)},l().createElement(o.Stack,{gap:5},l().createElement(ex.xI,{name:"name",control:n,render:({field:e})=>l().createElement(o.TextInput,{"data-testid":"cohort-name",id:"cohort-name",labelText:a("enterCohortName","Enter a cohort name"),...e,invalid:!!m.name,invalidText:m.name?.message})}),l().createElement(ex.xI,{name:"description",control:n,render:({field:e})=>l().createElement(o.TextInput,{"data-testid":"cohort-description",id:"cohort-description",labelText:a("enterCohortDescription","Enter a cohort description"),...e,invalid:!!m.description,invalidText:m.description?.message})})))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,kind:"danger",onClick:c(d)},l().createElement("span",null,(0,r.getCoreTranslation)("save")))))},eA),eQ=(0,r.getSyncLifecycle)(({closeModal:e,onSaveQuery:t})=>{let{t:a}=(0,s.useTranslation)(),{control:n,handleSubmit:c,formState:{errors:m,isSubmitting:d}}=(0,ex.mN)({resolver:(0,eO.u)(eL.z.object({queryName:eL.z.string({required_error:a("queryNameRequired","Name is required")}).min(1,a("queryNameRequired","Name is required")),queryDescription:eL.z.string({required_error:a("queryDescriptionRequired","Description is required")}).min(1,a("queryDescriptionRequired","Description is required"))})),defaultValues:{queryName:"",queryDescription:""}}),u=async a=>{await t(a),e()};return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:a("saveQuery","Save query")}),l().createElement("form",{onSubmit:c(u)},l().createElement(o.ModalBody,null,l().createElement(o.Stack,{gap:5},l().createElement(ex.xI,{name:"queryName",control:n,render:({field:e})=>l().createElement(o.TextInput,{...e,labelText:a("enterQueryName","Enter a name for the query"),id:"query-name","data-testid":"query-name",invalid:!!m.queryName,invalidText:m.queryName?.message})}),l().createElement(ex.xI,{name:"queryDescription",control:n,render:({field:e})=>l().createElement(o.TextInput,{...e,labelText:a("enterQueryDescription","Enter a description of the query"),id:"query-description",invalid:!!m.queryDescription,invalidText:m.queryDescription?.message})}))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,disabled:d,kind:"primary",type:"submit"},d?l().createElement(o.InlineLoading,{description:a("saving","Saving")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("save"))))))},eA)}}]);
1
+ (globalThis.webpackChunk_openmrs_esm_cohort_builder_app=globalThis.webpackChunk_openmrs_esm_cohort_builder_app||[]).push([["321"],{4767(e,t,a){var r={"./en.json":["4300","117"]};function n(e){if(!a.o(r,e))return Promise.resolve().then(function(){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t});var t=r[e],n=t[0];return a.e(t[1]).then(function(){return a(n)})}n.keys=()=>Object.keys(r),n.id=4767,e.exports=n},6720(e,t,a){"use strict";a.r(t),a.d(t,{cohortBuilder:()=>eq,clearSearchHistoryModal:()=>eF,saveCohortModal:()=>eU,importTranslation:()=>eP,deleteQueryModal:()=>ez,cohortBuilderAdminPageCardLink:()=>eR,deleteCohortModal:()=>eH,clearItemFromSearchHistoryModal:()=>eB,startupApp:()=>e$,saveQueryModal:()=>eQ});var r=a(2388),n=a(4923),l=a.n(n),o=a(9536),s=a(202);let i="-esm-cohort-builder__modals__deleteButton___wIYdW";var c=a(2137),m=a(6942),d=a.n(m),u=a(6880),h=a.n(u);let p=async e=>await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/adhocquery?v=full`,{method:"POST",headers:{"Content-Type":"application/json"},body:e.query}),b=()=>{let{data:e,error:t}=h()(`${r.restBaseUrl}/location`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,locations:a,locationsError:t}},E=async e=>(await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/dataSet/${e}`,{method:"GET"})).data.rows.map(e=>(e.id=e.patientId.toString(),e.name=`${e.firstname} ${e.lastname}`,e)),g=async e=>(await (0,r.openmrsFetch)(`${r.restBaseUrl}/cohort/${e}/member?v=full`,{method:"GET"})).data.rows.map(e=>(e.id=e.patientId.toString(),e.name=`${e.firstname} ${e.lastname}`,e)),_=e=>{let t={type:"org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",columns:[],rowFilters:[],customRowFilterCombination:""};t.columns=C();let a=0;for(let r in t.rowFilters=[],e){if(y(e[r])){delete e[r];continue}"all"!=e[r]&&""!=e&&(t.rowFilters[a]={},t.rowFilters[a].key=v(r,e[r])),Array.isArray(e[r])&&(t.rowFilters[a].parameterValues=S(e[r])),e[r].length>=1&&"alive"===e[r][0].livingStatus&&(t.rowFilters[a].livingStatus="alive"),t.rowFilters[a].type="org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",a+=1}return t.customRowFilterCombination=w(t.rowFilters),{query:t}},y=e=>Array.isArray(e)&&e.length>=1?!e[0].value:"all"===e||!e,v=(e,t)=>{let a="reporting.library.cohortDefinition.builtIn";return"gender"===e?a+=`.${t}`:a+=`.${e}`,a},S=e=>{let t={};return e.forEach(e=>{t[e.name]=e.value}),t},w=e=>{let t="",a=e.length;for(let r=1;r<=a;r++)"alive"===e[r-1].livingStatus?(t+=`NOT ${r}`,delete e[r-1].livingStatus):t+=`${r}`,t+=r<a?" AND ":"";return t},C=()=>[{name:"firstname",key:"preferredName.givenName"},{name:"lastname",key:"preferredName.familyName"},{name:"gender",key:"gender"},{name:"age",key:"ageOnDate.fullYears"},{name:"patientId",key:"patientId"}].map(e=>(e.type="org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition",e.key=`reporting.library.patientDataDefinition.builtIn.${e.key}`,e)),f=e=>{let t=new Date(e),a=t.getDate(),r=t.getMonth()+1,n=t.getFullYear();return`${a}/${r}/${n}`},T="-esm-cohort-builder__search-button-set__button___tg6-2",k=({isLoading:e,onHandleSubmit:t,onHandleReset:a})=>{let{t:r}=(0,s.useTranslation)();return l().createElement(o.Column,{sm:2,md:{offset:4},className:"-esm-cohort-builder__search-button-set__container___jIXOL"},l().createElement(o.ButtonSet,{className:"-esm-cohort-builder__search-button-set__buttonSet___itc+A"},l().createElement(o.Button,{className:T,kind:"secondary",onClick:a,"data-testid":"reset-btn"},r("reset","Reset")),l().createElement(o.Button,{className:T,kind:"primary",disabled:e,onClick:t,"data-testid":"search-btn"},e?l().createElement(o.InlineLoading,{description:r("loading","Loading")}):r("search","Search"))))},D="-esm-cohort-builder__composition-style__text___YdbOd",N=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(!1),[c,m]=(0,n.useState)(""),[d,u]=(0,n.useState)(""),h=async()=>{i(!0);try{let a;if(a=c.match(/and|or|not|\d+|\)|\(|union|intersection|!|\+/gi),null!==a&&a.length===c.split(/\s+/g).length){let t,a,r=(t=c.replace(/(\(|\))+/g,e=>"("===e?"( ":" )"),a={type:"org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",columns:C(),rowFilters:[],customRowFilterCombination:""},t.split(/\s+/).forEach(e=>{if(e.match(/\d/)){let t,r,n=JSON.parse(window.sessionStorage.getItem("openmrsHistory"))[parseInt(e)-1].parameters;t=n.customRowFilterCombination,r=a.rowFilters.length,n.customRowFilterCombination=t.replace(/\d+/g,e=>(parseInt(e)+r).toString()),a.customRowFilterCombination+=`(${n.customRowFilterCombination})`,a.rowFilters=a.rowFilters.concat(n.rowFilters)}else a.customRowFilterCombination+=` ${e} `}),{query:a});await e(r,d)}else(0,r.showSnackbar)({title:t("error","Error!"),kind:"error",isLowContrast:!0,subtitle:t("invalidComposition","Composition is not valid")});i(!1)}catch(e){i(!1),(0,r.showSnackbar)({title:t("error","Error!"),kind:"error",isLowContrast:!0,subtitle:t("invalidComposition","Composition is not valid")})}};return l().createElement(l().Fragment,null,l().createElement(o.TextInput,{labelText:t("composition","Composition"),"data-testid":"composition-query",id:"composition-query",onChange:e=>{var t;m(t=e.target.value),u("Composition of "+t)},value:c}),l().createElement("br",null),l().createElement(o.TextInput,{labelText:t("description","Description"),"data-testid":"composition-description",id:"composition-description",onChange:e=>u(e.target.value),value:d}),l().createElement("br",null),l().createElement("p",{className:D},t("compositionExplanationOne","A composition query combines together the results of multiple cohorts using the logical operators: AND, OR and NOT.")),l().createElement("br",null),l().createElement("p",{className:D},t("compositionExplanationTwo","To use this query you need to already have query results in your search history. Those existing query results can then be combined to yield the results of the composition query.")),l().createElement("br",null),l().createElement("p",{className:D},t("compositionExplanationThree","Example: if the search history #1 is a cohort of patients who are males, and if the search history #2 is a cohort of patients with ages between 23 and 35 years; then '1 AND 2' will result in a cohort of patients who are males with ages between 23 and 35 years.")),l().createElement("br",null),l().createElement(k,{onHandleReset:()=>{u(""),m("")},onHandleSubmit:h,isLoading:a}))};var I=a(2551),M=a.n(I);let Y=async e=>await (0,r.openmrsFetch)(`${r.restBaseUrl}/cohort/${e}`,{method:"DELETE"}),x=e=>l().createElement(o.Layer,null,l().createElement(o.Tile,{className:"-esm-cohort-builder__empty-data-style__tile___kGzLZ"},l().createElement(r.EmptyCardIllustration,null),l().createElement("p",{className:"-esm-cohort-builder__empty-data-style__content___zUidZ"},"There are no ",e.displayText.toLowerCase()," to display"))),O="-esm-cohort-builder__saved-cohort-options__menuItem___rX2ia",L="view",A="delete",P=({cohort:e,onViewCohort:t,onDeleteCohort:a})=>{let{t:n}=(0,s.useTranslation)(),i=async()=>{try{await t(e.id)}catch(e){(0,r.showSnackbar)({title:n("cohortViewError","Error viewing the cohort"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},c=async t=>{switch(t){case L:i();break;case A:m(e.id)}},m=t=>{let a=(0,r.showModal)("delete-cohort-modal",{closeModal:()=>a(),cohortName:e.name,cohortId:t,onDeleteCohort:d,size:"sm"})},d=async()=>{await a(e.id)};return l().createElement(o.OverflowMenu,{"aria-label":n("savedCohortsOptions","Saved cohorts options"),flipped:!0,direction:"bottom","data-testid":"options"},l().createElement(o.OverflowMenuItem,{className:O,"data-testid":"view",itemText:n("view","View"),onClick:()=>c(L)}),l().createElement(o.OverflowMenuItem,{className:O,"data-testid":"delete",hasDivider:!0,isDelete:!0,itemText:n("delete","Delete"),onClick:()=>c(A)}))},$="-esm-cohort-builder__cohort-builder__heading___fKg4I",q="-esm-cohort-builder__cohort-builder__tab___OIkeX",R="-esm-cohort-builder__cohort-builder__optionCell___0dfgH",B="-esm-cohort-builder__cohort-builder__optionHeader___IBQGc",F="-esm-cohort-builder__cohort-builder__text___Dk0eN",H=({onViewCohort:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(1),[c,m]=(0,n.useState)(10),{cohorts:d}=function(){let e=`${r.restBaseUrl}/cohort?v=full`,{data:t,isLoading:a,isValidating:l}=M()(e,r.openmrsFetch);return{cohorts:(0,n.useMemo)(()=>t?.data?.results?.map(e=>({id:e.uuid,name:e.name,description:e.description})),[t])??[],isLoading:a,isValidating:l}}(),u=[{key:"name",header:t("name","Name")},{key:"description",header:t("description","Description")}],h=async e=>{try{await Y(e),(0,r.showSnackbar)({title:t("cohortDeleted","Cohort deleted"),kind:"success",isLowContrast:!0,subtitle:t("cohortDeleted","Cohort deleted")})}catch(e){(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:e?.message})}};return l().createElement("div",{className:"-esm-cohort-builder__saved-cohorts__container___RcI67"},l().createElement("p",{className:F},t("savedCohortDescription","You can only search for Cohort Definitions that you have saved using a Name.")),l().createElement(o.DataTable,{rows:d,headers:u,useZebraStyles:!0},({rows:t,headers:r,getTableProps:n,getHeaderProps:s,getRowProps:i})=>l().createElement(o.Table,n(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,r.map(e=>l().createElement(o.TableHeader,s({header:e}),e.header)),l().createElement(o.TableHeader,{className:B}))),l().createElement(o.TableBody,null,t.slice((a-1)*c).slice(0,c).map((t,a)=>l().createElement(o.TableRow,{...i({row:t}),key:a},t.cells.map((e,t)=>l().createElement(o.TableCell,{key:t},e.value)),l().createElement(o.TableCell,{className:R},l().createElement(P,{cohort:d[a],onViewCohort:e,onDeleteCohort:h}))))))),d?.length>10&&l().createElement(o.Pagination,{backwardText:t("previousPage","Previous page"),forwardText:t("nextPage","Next page"),itemsPerPageText:t("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{i(e),m(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:d.length}),!d?.length&&l().createElement(x,{displayText:t("cohorts","cohorts")}))};async function z(){let e=await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/dataSetDefinition?v=full`,{method:"GET"}),t=[];return e.data.results.length>0&&e.data.results.map(e=>{let a={id:e.uuid,name:e.name.replace("[AdHocDataExport]",""),description:e.description};t.push(a)}),t}let U=async e=>await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/adhocdataset/${e}?purge=true`,{method:"DELETE"}),Q="-esm-cohort-builder__saved-queries-options__menuItem___Qs6Ro",V="delete",j="view",G=({query:e,onViewQuery:t,deleteQuery:a})=>{let{t:n}=(0,s.useTranslation)(),i=async e=>{switch(e){case j:c();break;case V:m()}},c=async()=>{try{await t(e.id)}catch(e){(0,r.showSnackbar)({title:n("QueryDeleteError","Something went wrong"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},m=()=>{let t=(0,r.showModal)("delete-query-modal",{closeModal:()=>t(),queryName:e.name,queryId:e.id,onDelete:d,size:"sm"})},d=async()=>{await a(e.id)};return l().createElement(o.OverflowMenu,{"aria-label":n("savedQueriesOptions","Saved queries options"),size:"md",flipped:!0,direction:"bottom"},l().createElement(o.OverflowMenuItem,{className:Q,"data-testid":"view",itemText:n("view","View"),onClick:()=>i(j)}),l().createElement(o.OverflowMenuItem,{className:Q,"data-testid":"delete",hasDivider:!0,isDelete:!0,itemText:n("delete","Delete"),onClick:()=>i(V)}))},W=({onViewQuery:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(1),[c,m]=(0,n.useState)(10),[d,u]=(0,n.useState)([]),h=async()=>{u(await z())},p=async e=>{try{await U(e),(0,r.showSnackbar)({title:t("success","Success"),kind:"success",isLowContrast:!0,subtitle:t("queryIsDeleted","the query is deleted")}),h()}catch(e){(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:e?.message})}};(0,n.useEffect)(()=>{h()},[]);let b=[{key:"name",header:t("name","Name")},{key:"description",header:t("description","Description")}];return l().createElement("div",{className:"-esm-cohort-builder__saved-queries__container___apr+8"},l().createElement("p",{className:F},t("savedQueryDescription","You can only search for Query Definitions that you have saved using a Name.")),l().createElement(o.DataTable,{rows:d,headers:b,useZebraStyles:!0},({rows:t,headers:r,getTableProps:n,getHeaderProps:s,getRowProps:i})=>l().createElement(o.Table,n(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,r.map(e=>l().createElement(o.TableHeader,s({header:e}),e.header)),l().createElement(o.TableHeader,{className:B}))),l().createElement(o.TableBody,null,t.slice((a-1)*c).slice(0,c).map((t,a)=>l().createElement(o.TableRow,{...i({row:t}),key:a},t.cells.map((e,t)=>l().createElement(o.TableCell,{key:t},e.value)),l().createElement(o.TableCell,{className:R},l().createElement(G,{query:d[a],onViewQuery:e,deleteQuery:p}))))))),d.length>10&&l().createElement(o.Pagination,{backwardText:t("previousPage","Previous page"),forwardText:t("nextPage","Next page"),itemsPerPageText:t("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{i(e),m(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:d.length}),!d.length&&l().createElement(x,{displayText:t("queries","queries")}))};var X=a(4353),Z=a.n(X),J=a(4861);async function K(e){let t=await (0,r.openmrsFetch)(`${r.restBaseUrl}/concept?v=full&q=${e}`,{method:"GET"}),a=[];return t.data.results.length>0&&(a=t.data.results.map(e=>{let t=e.descriptions.filter(e=>"en"==e.locale?e.description:"");return{uuid:e.uuid,units:e.units||"",answers:e.answers,hl7Abbrev:e.datatype.hl7Abbreviation,name:e.name.name,description:t.length>0?t[0].description:"no description available",datatype:e.datatype}})),a}let ee={searchContainer:"-esm-cohort-builder__search-concept__searchContainer___dpJim",search:"-esm-cohort-builder__search-concept__search___9eq8D",loader:"-esm-cohort-builder__search-concept__loader___RvR4m",concept:"-esm-cohort-builder__search-concept__concept___WbcYA",conceptList:"-esm-cohort-builder__search-concept__conceptList___XqGdL",text:"-esm-cohort-builder__search-concept__text___Ow696",notification:"-esm-cohort-builder__search-concept__notification___x7E6s"},et=({concept:e,searchText:t,setConcept:a,setSearchText:r})=>{let{t:i}=(0,s.useTranslation)(),[c,m]=(0,n.useState)([]),[d,u]=(0,n.useState)(""),[h,p]=(0,n.useState)(!1),[b,E]=(0,n.useState)(!1),g=async e=>{m([]),a(null),p(!0),E(!1);try{let t=await K(e);t.length?m(t):E(!0),p(!1)}catch(e){u(e.toString()),p(!1)}},_=(0,n.useRef)((0,J.A)(async e=>{e&&await g(e)},500)).current;return(0,n.useEffect)(()=>()=>{_.cancel()},[_]),l().createElement("div",null,l().createElement(o.Column,{className:ee.column},l().createElement("div",{className:ee.searchContainer},l().createElement(o.Search,{closeButtonLabelText:i("clearSearch","Clear search"),id:"concept-search",labelText:i("searchConcepts","Search Concepts"),onChange:e=>{r(e.target.value),_(e.target.value)},onClear:()=>{E(!1),m([])},placeholder:i("searchConcepts","Search Concepts"),value:t}),l().createElement("div",{className:ee.search},h?l().createElement(o.InlineLoading,{className:ee.loader,description:i("searching","Searching")+"..."}):l().createElement("ul",{className:ee.conceptList},c?.map((e,t)=>l().createElement("li",{role:"menuitem",className:ee.concept,key:t,onClick:()=>{a(e),m([]),E(!1)}},e.name))))),e&&l().createElement("span",{className:ee.text},i("patientsWithObservationsWhoseAnswerIs","Patients with observations whose answer is"),l().createElement("strong",null,' "',e.name,'"'),"."),t&&b&&l().createElement(o.Tile,null,l().createElement("span",null,i("noMatchingConcepts","No concepts were found that match"),l().createElement("strong",null,' "',t,'"'),".")),d&&l().createElement("span",null,d)))},ea="-esm-cohort-builder__search-by-concepts-style__column___fpjOs",er="-esm-cohort-builder__search-by-concepts-style__dateRange___unfDl",en="-esm-cohort-builder__search-by-concepts-style__multipleInputs___O7iAI",el=[{id:0,label:"<",value:"LESS_THAN"},{id:1,label:"<=",value:"LESS_EQUAL"},{id:2,label:"=",value:"EQUAL"},{id:3,label:">=",value:"GREATER_EQUAL"},{id:4,label:">",value:"GREATER_THAN"}],eo={CWE:"codedObsSearchAdvanced",NM:"numericObsSearchAdvanced",DT:"dateObsSearchAdvanced",ST:"dateObsSearchAdvanced",TS:"textObsSearchAdvanced",ZZ:"codedObsSearchAdvanced",BIT:"codedObsSearchAdvanced"},es=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,r]=(0,n.useState)(null),[i,c]=(0,n.useState)(0),[m,d]=(0,n.useState)(0),[u,h]=(0,n.useState)(0),[p,b]=(0,n.useState)("LESS_THAN"),[E,g]=(0,n.useState)("ANY"),[y,v]=(0,n.useState)(""),[S,w]=(0,n.useState)(""),[C,T]=(0,n.useState)(""),[D,N]=(0,n.useState)(!1),I=[{id:"option-0",label:t("haveObservations","Patients who have these observations"),value:"ANY"},{id:"option-1",label:t("haveNoObservations","Patients who do not have these observations"),value:"NO"}],M=[{id:"option-0",label:t("any","Any"),value:"ANY"},{id:"option-1",label:t("none","None"),value:"NO"},{id:"option-2",label:t("earliest","Earliest"),value:"FIRST"},{id:"option-3",label:t("recent","Most Recent"),value:"LAST"},{id:"option-4",label:t("lowest","Lowest"),value:"MIN"},{id:"option-5",label:t("highest","Highest"),value:"MAX"},{id:"option-6",label:t("average","Average"),value:"AVG"}],Y=async()=>{if(!a)return;N(!0);let t={modifier:"",operator1:p,value1:u>0?u.toString():"",question:a.uuid,onOrBefore:(()=>{if(i>0||m>0)return Z()().subtract(i,"days").subtract(m,"months").format()})()||S,onOrAfter:y,timeModifier:E},r=eo[a.hl7Abbrev],n={[r]:[]};Object.keys(t).forEach(e=>{""!==t[e]&&n[r].push({name:"modifier"===e?["CWE","TS"].includes(a.hl7Abbrev)?"values":"value1":e,value:"modifier"===e&&["CWE","TS"].includes(a.hl7Abbrev)?[t[e]]:t[e]})}),await e(_(n),((e,t)=>{let{timeModifier:a,onOrAfter:r,onOrBefore:n}=e,l=r?`since ${f(r)}`:"",o=n?`until ${f(n)}`:"";return`Patients with ${a} ${t} ${l} ${o}`.trim()})(t,a.name)),N(!1)};return l().createElement(l().Fragment,null,l().createElement("div",null,l().createElement(et,{setConcept:r,concept:a,searchText:C,setSearchText:T}),a?.hl7Abbrev==="NM"?l().createElement(l().Fragment,null,l().createElement(o.Column,{className:ea},l().createElement("div",{style:{display:"flex"}},l().createElement("div",{className:en},l().createElement("p",{style:{paddingRight:20}},t("whatObservations","What observations")),l().createElement(o.Dropdown,{id:"timeModifier",onChange:e=>g(e.selectedItem.value),initialSelectedItem:M[0],items:M,className:"-esm-cohort-builder__search-by-concepts-style__timeModifier___SeThC",label:"",titleText:""})))),l().createElement(o.Column,{className:ea},l().createElement("p",{className:"-esm-cohort-builder__search-by-concepts-style__value___FUIbI"},t("whatValues","What values")),l().createElement("div",{className:"-esm-cohort-builder__search-by-concepts-style__whatValuesInputs___5UXAP"},l().createElement("div",{className:"-esm-cohort-builder__search-by-concepts-style__operators___KUi3k"},l().createElement(o.ContentSwitcher,{selectedIndex:el[0].id,className:"-esm-cohort-builder__search-by-concepts-style__contentSwitcher___LXxCi",size:"lg",onChange:({index:e})=>b(el[e].value)},el.map(e=>l().createElement(o.Switch,{key:e.id,name:e.value,text:e.label})))),l().createElement("div",{className:en},l().createElement(o.NumberInput,{hideSteppers:!0,id:"operator-value",invalidText:t("numberIsNotValid","Number is not valid"),label:t("valueIn","Enter a value in ")+a.units,min:0,size:"sm",value:u,onChange:(e,{value:t})=>h(Number(t))}))))):l().createElement(o.Column,{className:ea},l().createElement(o.Dropdown,{id:"timeModifier","data-testid":"timeModifier",onChange:e=>g(e.selectedItem.value),initialSelectedItem:I[0],items:I,label:"",titleText:""})),l().createElement(o.Column,{className:er},l().createElement(o.Column,null,l().createElement(o.NumberInput,{hideSteppers:!0,id:"last-months","data-testid":"last-months",label:t("withinTheLast","Within the last months"),invalidText:t("numberIsNotValid","Number is not valid"),min:0,value:m,onChange:(e,{value:t})=>d(Number(t))})),l().createElement(o.Column,null,l().createElement(o.NumberInput,{hideSteppers:!0,label:t("lastDays","and / or days"),id:"last-days","data-testid":"last-days",invalidText:t("numberIsNotValid","Number is not valid"),min:0,value:i,onChange:(e,{value:t})=>c(Number(t))}))),l().createElement("div",{className:er},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>v(Z()(e[0]).format()),value:y&&Z()(y).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"startDate",labelText:t("dateRange","Date range start date"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>w(Z()(e[0]).format()),value:S&&Z()(S).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"endDate",labelText:t("endDate","End date"),placeholder:"DD-MM-YYYY",size:"md"}))))),l().createElement(k,{isLoading:D,onHandleSubmit:Y,onHandleReset:()=>{r(null),c(0),T(""),v(""),w(""),d(0),h(0),b("LESS_THAN"),g("ANY")}}))},ei="-esm-cohort-builder__search-by-demographics-style__contentSwitcher___L5GhV",ec="-esm-cohort-builder__search-by-demographics-style__column___agceq",em="-esm-cohort-builder__search-by-demographics-style__switch___Q01uO",ed=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,r]=(0,n.useState)("alive"),[i,c]=(0,n.useState)("all"),[m,u]=(0,n.useState)(""),[h,p]=(0,n.useState)(""),[b,E]=(0,n.useState)(0),[g,y]=(0,n.useState)(0),[v,S]=(0,n.useState)(!1),w=[{id:0,label:t("all","All"),value:"all"},{id:1,label:t("males","Male"),value:"males"},{id:3,label:t("females","Female"),value:"females"}],C=[{id:0,label:t("alive","Alive"),value:"alive"},{id:1,label:t("dead","Dead"),value:"dead"}],f=async()=>{S(!0);let t={gender:i,minAge:b,maxAge:g,birthDayStartDate:m,birthDayEndDate:h,livingStatus:a};await e((({gender:e,minAge:t,maxAge:a,birthDayStartDate:r,birthDayEndDate:n,livingStatus:l})=>{let o={gender:e};t&&a?o.ageRangeOnDate=[{name:"minAge",value:t},{name:"maxAge",value:a}]:t?o.atLeastAgeOnDate=[{name:"minAge",value:t}]:o.upToAgeOnDate=[{name:"maxAge",value:a}],r&&n&&(o.bornDuringPeriod=[{name:"startDate",dataType:"date",value:r},{name:"endDate",dataType:"date",value:n}]),o.diedDuringPeriod=[{name:"endDate",dataType:"date",value:Z()().format(),livingStatus:l}];let s=_(o);if("all"===o.gender){let e=["males","females","unknownGender"].map(e=>({type:"org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",key:`reporting.library.cohortDefinition.builtIn.${e}`})),{query:{rowFilters:t,customRowFilterCombination:a}}=s,r=t=t.length>0?[...t,...e]:e,n=a;a=n?`(${r.length-2} OR ${r.length-1} OR ${r.length}) AND ${n}`:"(1 OR 2 OR 3)"}return s})(t),(({gender:e,minAge:t,maxAge:a,birthDayStartDate:r,birthDayEndDate:n,livingStatus:l})=>{let o="all"!=e?`${"males"===e?"Male":"Female"} Patients`:"All Patients";return(t||a)&&(t&&a?o+=` with ages between ${t} and ${a}`:o+=t?` with minimum age of ${t}`:` with maximum age of ${a}`,o+=" years"),(""!=r||""!=n)&&(r&&n?o+=` and birthdate between ${r} and ${n}`:o+=t?` and born before ${r}`:` and born before ${n}`),l&&(o+=` that are ${l}`),o})(t)),S(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("p",{className:d()("-esm-cohort-builder__search-by-demographics-style__text___x8MO2","-esm-cohort-builder__search-by-demographics-style__genderTitle___06Nb4")},t("gender","Gender")),l().createElement("div",{className:"-esm-cohort-builder__search-by-demographics-style__genderContainer___VkE-3"},l().createElement("div",{className:em},l().createElement(o.ContentSwitcher,{selectedIndex:w[0].id,className:ei,size:"lg",onChange:({index:e})=>c(w[e].value)},w.map(e=>l().createElement(o.Switch,{"data-testid":e.label,key:e.id,name:e.value,text:e.label})))),l().createElement("div",{className:em},l().createElement(o.ContentSwitcher,{selectedIndex:C[0].id,className:ei,size:"lg",onChange:({index:e})=>r(C[e].value)},C.map(e=>l().createElement(o.Switch,{key:e.id,name:e.value,text:e.label})))))),l().createElement("div",{className:ec},l().createElement(o.Column,{className:"-esm-cohort-builder__search-by-demographics-style__age___DEuDD"},l().createElement(o.Column,null,l().createElement(o.NumberInput,{"data-testid":"minAge",hideSteppers:!0,id:"minAge",invalidText:t("minAgeIsNotValid","The age must be greater than 0"),label:t("ageBetween","Age between"),min:0,onChange:(e,{value:t})=>E(Number(t)),value:b})),l().createElement(o.Column,null,l().createElement(o.NumberInput,{"data-testid":"maxAge",hideSteppers:!0,id:"maxAge",invalidText:t("maxAgeIsNotValid","The age must be less than 200"),label:t("and","and"),max:200,min:0,onChange:(e,{value:t})=>y(Number(t)),value:g})))),l().createElement("div",{className:ec},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>u(Z()(e[0]).format()),value:m&&Z()(m).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"startDate",labelText:t("birthDate","Birth date between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{allowInput:!1,datePickerType:"single",onChange:e=>p(Z()(e[0]).format()),value:h&&Z()(h).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"endDate",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{isLoading:v,onHandleSubmit:f,onHandleReset:()=>{y(0),E(0),p(""),u("")}}))},eu="-esm-cohort-builder__search-by-drug-orders-style__column___nQLUC",eh=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),{drugs:a,drugsError:i}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/drug`,r.openmrsFetch);return(0,n.useMemo)(()=>{let a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,drugs:a,drugsError:t}},[e,t])}(),{careSettings:c,careSettingsError:m}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/caresetting`,r.openmrsFetch);return(0,n.useMemo)(()=>{let a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,careSettings:a,careSettingsError:t}},[e,t])}(),[d,u]=(0,n.useState)(""),[p,b]=(0,n.useState)(""),[E,g]=(0,n.useState)(""),[y,v]=(0,n.useState)(""),[S,w]=(0,n.useState)(null),[C,f]=(0,n.useState)(null),[T,D]=(0,n.useState)(!1);i&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:i?.message}),m&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:m?.message});let N=async()=>{D(!0);let t={selectedDrugs:S,selectedCareSetting:C,activeOnOrAfter:d,activeOnOrBefore:p,activatedOnOrAfter:E,activatedOnOrBefore:y};await e((({selectedDrugs:e,selectedCareSetting:t,activeOnOrBefore:a,activeOnOrAfter:r,activatedOnOrBefore:n,activatedOnOrAfter:l})=>{let o={drugOrderSearch:[]};return r&&o.drugOrderSearch.push({name:"activeOnOrAfter",value:r}),l&&o.drugOrderSearch.push({name:"activatedOnOrAfter",value:l}),n&&o.drugOrderSearch.push({name:"activatedOnOrBefore",value:n}),t&&o.drugOrderSearch.push({name:"careSetting",value:t.value}),e.length&&o.drugOrderSearch.push({name:"drugs",value:e.map(e=>e.value)}),a&&o.drugOrderSearch.push({name:"activeOnOrBefore",value:a}),_(o)})(t),(({selectedDrugs:e,selectedCareSetting:t,activeOnOrBefore:a,activeOnOrAfter:n,activatedOnOrBefore:l,activatedOnOrAfter:o})=>{let s="Patients who taking "+e.map(e=>e.label).join(", ").replace(/,(?=[^,]*$)/," and");if(t&&(s+=` from ${t.label}`),n){let e=(0,r.formatDate)(new Date(n),{mode:"standard"});a?s+=` from ${e}`:s+=` on or after ${e}`}if(a){let e=(0,r.formatDate)(new Date(a),{mode:"standard"});n?s+=` to ${e}`:s+=` on or before ${e}`}if(o){let e=(0,r.formatDate)(new Date(o),{mode:"standard"});l?s+=` from ${e}`:s+=` on or after ${e}`}if(l){let e=(0,r.formatDate)(new Date(l),{mode:"standard"});o?s+=` to ${e}`:s+=` on or before ${e}`}return s})(t)),D(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"drugs","data-testid":"drugs",onChange:e=>w(e.selectedItems),items:a,label:t("selectDrugs","Select drugs")}))),l().createElement("div",{className:eu},l().createElement(o.Column,null,l().createElement(o.Dropdown,{id:"careSettings","data-testid":"careSettings",onChange:e=>f(e.selectedItem),initialSelectedItem:c[0],items:c,label:t("selectCareSettings","Select a care setting"),titleText:""}))),l().createElement("div",{className:eu},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>u(Z()(e[0]).format()),value:d&&Z()(d).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activeOnOrAfter",labelText:t("using","Using between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>b(Z()(e[0]).format()),value:p&&Z()(p).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activeOnOrBefore",labelText:t("to","to"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement("div",{className:eu},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>g(Z()(e[0]).format()),value:E&&Z()(E).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activatedOnOrAfter",labelText:t("used","Used between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>v(Z()(e[0]).format()),value:y&&Z()(y).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"activatedOnOrBefore",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{onHandleReset:()=>{w(null),f(null),u(""),b(""),g(""),v("")},onHandleSubmit:N,isLoading:T}))},ep="-esm-cohort-builder__search-by-encounters-style__column___2KGkF",eb="-esm-cohort-builder__search-by-encounters-style__multipleInputs___AQXO8",eE=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),[a,i]=(0,n.useState)(0),[c,m]=(0,n.useState)(0),{encounterTypes:d,encounterTypesError:u}=(()=>{let{data:e,error:t}=h()(`${r.restBaseUrl}/encountertype`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,encounterTypes:a,encounterTypesError:t}})(),[p,E]=(0,n.useState)([]),[g,y]=(0,n.useState)([]),[v,S]=(0,n.useState)([]),{locations:w,locationsError:C}=b(),{forms:f,formsError:T}=(()=>{let{data:e,error:t}=h()(`${r.restBaseUrl}/form`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,forms:a,formsError:t}})(),[D,N]=(0,n.useState)(""),[I,M]=(0,n.useState)(""),[Y,x]=(0,n.useState)(!1);C&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:C?.message}),T&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:T?.message}),u&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:u?.message});let O=async()=>{x(!0);let t={onOrAfter:I,atLeastCount:a,atMostCount:c,encounterForms:v,encounterLocations:g,onOrBefore:D,selectedEncounterTypes:p};await e((({onOrAfter:e,atLeastCount:t,atMostCount:a,encounterForms:r,encounterLocations:n,onOrBefore:l,selectedEncounterTypes:o})=>{let s={encounterSearchAdvanced:[]};return e&&s.encounterSearchAdvanced.push({name:"onOrAfter",value:e}),t&&s.encounterSearchAdvanced.push({name:"atLeastCount",value:t}),a&&s.encounterSearchAdvanced.push({name:"atMostCount",value:a}),r.length&&s.encounterSearchAdvanced.push({name:"formList",value:r.map(e=>e.value)}),n.length&&s.encounterSearchAdvanced.push({name:"locationList",value:n.map(e=>e.value)}),l&&s.encounterSearchAdvanced.push({name:"onOrBefore",value:l}),o.length>0&&s.encounterSearchAdvanced.push({name:"encounterTypeList",value:o.map(e=>e.value)}),_(s)})(t),(({selectedEncounterTypes:e,encounterLocations:t,encounterForms:a,atLeastCount:r,atMostCount:n,onOrAfter:l,onOrBefore:o})=>{let s="Patients with Encounter of",i=e.map(e=>e.label).join(", ").replace(/,(?=[^,]*$)/," and ");return s+=i?` Type${i.length>1?"s":""} ${i}`:" any Type",t.length&&(s+=` at ${t.map(e=>e.label).join(", ")}`),a.length&&(s+=` from ${a.map(e=>e.label).join(", ")}`),r&&(s+=` at least ${r} ${r>1?"times":"time"}`),n&&(s+=` ${r?" and":""} at most ${n} ${n>1?"times":"time"}`),l&&(o?s+=` from ${l}`:s+=` on or after ${l}`),o&&(l?s+=` to ${o}`:s+=` on or before ${o}`),s})(t)),x(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"encounters",onChange:e=>E(e.selectedItems),items:d,label:t("selectEncounterTypes","Select encounter types")}))),l().createElement(o.MultiSelect,{id:"forms","data-testid":"forms",onChange:e=>S(e.selectedItems),items:f,label:t("selectForms","Select forms")}),l().createElement(o.MultiSelect,{id:"locations",onChange:e=>y(e.selectedItems),items:w,label:t("selectLocations","Select locations")}),l().createElement("div",{className:ep},l().createElement(o.Column,{className:"-esm-cohort-builder__search-by-encounters-style__encounterRange___0Q8rh"},l().createElement("div",{className:eb},l().createElement(o.NumberInput,{hideSteppers:!0,id:"atLeastCount","data-testid":"atLeastCount",label:t("atLeast","at least"),min:0,size:"sm",value:a,onChange:(e,{value:t})=>i(Number(t))})),l().createElement("div",{className:eb},l().createElement(o.NumberInput,{hideSteppers:!0,id:"atMostCount","data-testid":"atMostCount",label:t("upto","upto this many"),min:0,size:"sm",value:c,onChange:(e,{value:t})=>m(Number(t))})))),l().createElement("div",{className:ep},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>M(Z()(e[0]).format()),value:I&&Z()(I).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"onOrAfter",labelText:t("from","From"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>N(Z()(e[0]).format()),value:D&&Z()(D).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"onOrBefore",labelText:t("to","to"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{isLoading:Y,onHandleSubmit:O,onHandleReset:()=>{i(0),m(0),N(""),M("")}}))},eg="-esm-cohort-builder__search-by-enrollments-style__column___10FcT",e_=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),{programs:a,programsError:i}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/program`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.name,value:e.uuid})}),{isLoading:!e&&!t,programs:a,programsError:t}}(),{locations:c,locationsError:m}=b(),[d,u]=(0,n.useState)(""),[p,E]=(0,n.useState)(""),[g,y]=(0,n.useState)(""),[v,S]=(0,n.useState)(""),[w,C]=(0,n.useState)(null),[f,T]=(0,n.useState)(null),[D,N]=(0,n.useState)(!1);i&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:i?.message}),m&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:m?.message});let I=async()=>{N(!0);let t={enrolledOnOrAfter:d,enrolledOnOrBefore:p,completedOnOrAfter:g,completedOnOrBefore:v,selectedPrograms:f,selectedLocations:w};await e((({enrolledOnOrAfter:e,enrolledOnOrBefore:t,completedOnOrAfter:a,completedOnOrBefore:r,selectedPrograms:n,selectedLocations:l})=>_({patientsWithEnrollment:[{name:"programs",value:n?.map(e=>e.value)},e&&{name:"enrolledOnOrAfter",value:e},t&&{name:"enrolledOnOrBefore",value:t},a&&{name:"completedOnOrAfter",value:a},r&&{name:"completedOnOrBefore",value:r},{name:"locationList",value:l?.map(e=>e.value)}]}))(t),(({selectedPrograms:e,selectedLocations:t})=>{let a=`Patients enrolled in ${e?.map(e=>e.label).join(", ")}`;return t?.length&&(a+=` at ${t?.map(e=>e.label).join(", ")}`),a})(t)),N(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"programs","data-testid":"programs",onChange:e=>T(e.selectedItems),items:a,label:t("selectPrograms","Select programs")}))),l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{id:"locations","data-testid":"locations",onChange:e=>C(e.selectedItems),items:c,label:t("selectLocations","Select locations")}))),l().createElement("div",{className:eg},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>u(Z()(e[0]).format()),value:d&&Z()(d).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"enrolledOnOrAfter",labelText:t("enrolledBetween","Enrolled between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>E(Z()(e[0]).format()),value:p&&Z()(p).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"enrolledOnOrBefore",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement("div",{className:eg},l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>y(Z()(e[0]).format()),value:g&&Z()(g).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"completedOnOrAfter",labelText:t("completedBetween","Completed between"),placeholder:"DD-MM-YYYY",size:"md"}))),l().createElement(o.Column,null,l().createElement(o.DatePicker,{datePickerType:"single",allowInput:!1,onChange:e=>S(Z()(e[0]).format()),value:v&&Z()(v).format("DD-MM-YYYY")},l().createElement(o.DatePickerInput,{id:"completedOnOrBefore",labelText:t("and","and"),placeholder:"DD-MM-YYYY",size:"md"})))),l().createElement(k,{onHandleReset:()=>{T(null),u(""),E(""),y(""),S("")},onHandleSubmit:I,isLoading:D}))},ey=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),a=[{id:0,label:t("anyEncounter","Any Encounter"),value:"ANY"},{id:1,label:t("mostRecentEncounter","Most Recent Encounter"),value:"LAST"},{id:2,label:t("earliestEncounter","Earliest Encounter"),value:"FIRST"}],{locations:i,locationsError:c}=b(),[m,d]=(0,n.useState)(null),[u,h]=(0,n.useState)(a[0]),[p,E]=(0,n.useState)(!1);c&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:c?.message});let g=async()=>{var t;let a;E(!0),await e((t=u.value,a=[],m?.map(e=>a.push(e.value)),_({encounterSearchAdvanced:[{name:"locationList",value:a},{name:"timeQualifier",value:t}]})),((e,t)=>{let a=`Patients in ${t?.map(e=>e.label).join(", ")}`;switch(e){case"FIRST":a+=" (by method EARLIEST_ENCOUNTER).";break;case"LAST":a+=" (by method LATEST_ENCOUNTER).";break;default:a+=" (by method ANY_ENCOUNTER)."}return a})(u.label,m)),E(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.MultiSelect,{"aria-label":t("selectLocations","Select locations"),id:"locations","data-testid":"locations",onChange:e=>d(e.selectedItems),items:i,label:t("selectLocations","Select locations"),placeholder:t("searchForALocation","Search for a location")}))),l().createElement("div",{className:"-esm-cohort-builder__search-by-location-style__column___yC9N2"},l().createElement(o.Column,null,l().createElement(o.Dropdown,{id:"methods","data-testid":"methods",onChange:e=>h(e.selectedItem),initialSelectedItem:a[0],items:a,label:t("selectMethod","Select a method"),titleText:""}))),l().createElement(k,{onHandleReset:()=>{d(null),h(null)},onHandleSubmit:g,isLoading:p}))},ev=({onSubmit:e})=>{let{t}=(0,s.useTranslation)(),{personAttributes:a,personAttributesError:i}=function(){let{data:e,error:t}=h()(`${r.restBaseUrl}/personattributetype`,r.openmrsFetch),a=[];return e?.data.results.map((e,t)=>{a.push({id:t,label:e.display,value:e.uuid})}),{isLoading:!e&&!t,personAttributes:a,personAttributesError:t}}(),[c,m]=(0,n.useState)([]),[d,u]=(0,n.useState)(null),[p,b]=(0,n.useState)(!1);i&&(0,r.showSnackbar)({title:t("error","Error"),kind:"error",isLowContrast:!1,subtitle:i?.message});let E=async()=>{var t;let r,n;b(!0);let l=a?.find(e=>e.value==d);await e(_({personWithAttribute:[{name:"attributeType",value:d},{name:"values",value:c}]}),(t=l?.label,r="Patients",n=c.length>0?c.join(", ").replace(/,(?=[^,]*$)/," or"):"",r+=t?` with${n?"":" any"} ${t}`:t,r+=n?` equal to ${n.length>1&&"either"} ${n}`:"")),b(!1)};return l().createElement(l().Fragment,null,l().createElement(o.Column,null,l().createElement("div",null,l().createElement(o.Dropdown,{id:"personAttributes","data-testid":"personAttributes",onChange:e=>u(e.selectedItem.value),items:a,label:t("selectAttribute","Select a person attribute"),titleText:""}))),l().createElement("div",{className:"-esm-cohort-builder__search-by-person-attributes-style__column___Tvomw"},l().createElement(o.Column,null,l().createElement(o.TextInput,{id:"selectedAttributeValues","data-testid":"selectedAttributeValues",disabled:!d,labelText:t("selectedAttributeValues","Enter Comma Delimited Values"),onChange:e=>m(e.target.value.trim().split(","))}))),l().createElement(k,{onHandleReset:()=>{u(null),m([])},onHandleSubmit:E,isLoading:p}))};async function eS(e){return await (0,r.openmrsFetch)(`${r.restBaseUrl}/cohort`,{method:"POST",headers:{"Content-Type":"application/json"},body:e})}async function ew(e){return await (0,r.openmrsFetch)(`${r.restBaseUrl}/reportingrest/adhocdataset`,{method:"POST",headers:{"Content-Type":"application/json"},body:e})}let eC="-esm-cohort-builder__search-history-options__menuItem___iYtpR",ef="delete",eT="download",ek="saveCohort",eD="saveQuery",eN=async(e,t,a,n)=>{let l=[],{patients:o}=a;o.forEach(e=>l.push(parseInt(e.id)));try{await eS({display:e,memberIds:l,description:t,name:e}),(0,r.showSnackbar)({title:n("success","Success"),kind:"success",isLowContrast:!0,subtitle:n("cohortSaved","Cohort created successfully")})}catch(e){(0,r.showSnackbar)({title:n("errorCreatingCohort","Error creating the cohort"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},eI=({searchItem:e,updateSearchHistory:t})=>{let{t:a}=(0,s.useTranslation)(),[i,c]=(0,n.useState)(""),[m,d]=(0,n.useState)(""),[u,h]=(0,n.useState)(""),[p,b]=(0,n.useState)(""),E=async t=>{let{patients:a,description:r}=e;switch(t){case ek:d(r),S();break;case eD:b(r),y();break;case eT:let n=new Blob(["patient_id, full_name, age, gender\n"+a.map(e=>Object.keys({patientId:e.patientId,name:e.name,age:e.age,gender:e.gender}).map(t=>`"${e[t]}"`).join(",")).join("\n")],{type:"text/csv;charset=utf-8;"}),l=URL.createObjectURL(n),o=document.createElement("a");o.href=l,o.setAttribute("download",r),o.click();break;case ef:v()}},g=async()=>{try{t(e),(0,r.showSnackbar)({title:a("success","Success"),kind:"success",isLowContrast:!0,subtitle:"the search item is deleted"})}catch(e){(0,r.showSnackbar)({title:a("searchItemDeleteError","Error deleting the cohort"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},_=async()=>{try{let{parameters:t}=e;t.name=u,t.description=p,await ew(t),h(""),b(""),(0,r.showSnackbar)({title:a("success","Success"),kind:"success",isLowContrast:!0,subtitle:"the query is saved"})}catch(e){(0,r.showSnackbar)({title:a("queryDeleteError","Error saving the query"),kind:"error",isLowContrast:!0,subtitle:e?.message})}},y=()=>{let e=(0,r.showModal)("save-query-modal",{closeModal:()=>e(),onSaveQuery:_,size:"sm"})},v=()=>{let t=(0,r.showModal)("clear-item-from-search-history-modal",{closeModal:()=>t(),onRemove:g,searchItemName:e?.description,size:"sm"})},S=()=>{let t=(0,r.showModal)("save-cohort-modal",{closeModal:()=>t(),onSave:(t,r)=>eN(t,r,e,a),size:"sm"})};return l().createElement(o.OverflowMenu,{"aria-label":a("searchHistoryOptions","Search history options"),size:"md",flipped:!0,direction:"top","data-testid":"options"},l().createElement(o.OverflowMenuItem,{className:eC,"data-testid":"save-cohort",itemText:a("saveCohort","Save cohort"),onClick:()=>E(ek)}),l().createElement(o.OverflowMenuItem,{className:eC,"data-testid":"save-query",itemText:a("saveQuery","Save query"),onClick:()=>E(eD)}),l().createElement(o.OverflowMenuItem,{className:eC,itemText:a("downloadResults","Download results"),onClick:()=>E(eT)}),l().createElement(o.OverflowMenuItem,{className:eC,"data-testid":"deleteFromHistory",hasDivider:!0,isDelete:!0,itemText:a("deleteFromHistory","Delete from history"),onClick:()=>E(ef)}))},eM=({isHistoryUpdated:e,setIsHistoryUpdated:t})=>{let{t:a}=(0,s.useTranslation)(),[i,c]=(0,n.useState)([]),[m,d]=(0,n.useState)(1),[u,h]=(0,n.useState)(10);(0,n.useEffect)(()=>{if(e){let e,a;c((e=JSON.parse(window.sessionStorage.getItem("openmrsHistory")),a=[],e?.map((e,t)=>a.push({...e,id:(t+1).toString(),results:e.patients.length})),a)),t(!1)}},[e,t]);let p=[{key:"id",header:"#"},{key:"description",header:a("query","Query")},{key:"results",header:a("results","Results")}],b=()=>{window.sessionStorage.removeItem("openmrsHistory"),c([])},E=e=>{let t=[...i].filter((t,a)=>a!=i.indexOf(e));c(t),window.sessionStorage.setItem("openmrsHistory",JSON.stringify(t))};return l().createElement("div",{className:"-esm-cohort-builder__search-history-style__container___KJBMK"},l().createElement("div",{className:"-esm-cohort-builder__search-history-style__header___C-R7x"},l().createElement("p",{className:$},a("searchHistory","Search History")),i.length>0&&l().createElement(o.Button,{kind:"danger--tertiary",onClick:()=>{let e=(0,r.showModal)("clear-search-history-modal",{closeModal:()=>e(),onClearHistory:b,size:"sm"})}},a("clearSearchHistory","Clear search history"))),l().createElement(o.DataTable,{rows:i,headers:p,useZebraStyles:!0},({rows:e,headers:t,getTableProps:a,getHeaderProps:r,getRowProps:n})=>l().createElement(o.Table,a(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,t.map(e=>l().createElement(o.TableHeader,r({header:e}),e.header)),l().createElement(o.TableHeader,{className:B}))),l().createElement(o.TableBody,null,e.slice((m-1)*u).slice(0,u).map((e,t)=>l().createElement(o.TableRow,n({row:e}),e.cells.map(e=>l().createElement(o.TableCell,{key:e.id},e.value)),l().createElement(o.TableCell,{className:R},l().createElement(eI,{searchItem:i[t],updateSearchHistory:E}))))))),i.length>10&&l().createElement(o.Pagination,{backwardText:a("previousPage","Previous page"),forwardText:a("nextPage","Next page"),itemsPerPageText:a("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{d(e),h(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:i.length}),!i.length&&l().createElement(x,{displayText:a("data","data")}))},eY=({patients:e})=>{let[t,a]=(0,n.useState)(1),[r,i]=(0,n.useState)(10),{t:c}=(0,s.useTranslation)(),m=[{key:"id",header:c("openmrsId","OpenMRS ID")},{key:"name",header:c("name","Name")},{key:"age",header:c("age","Age")},{key:"gender",header:c("gender","Gender")}];return l().createElement("div",{className:"-esm-cohort-builder__search-results-table__container___y4+06"},l().createElement("p",{className:$},c("searchResults","Search Results")),l().createElement(o.DataTable,{rows:e,headers:m,useZebraStyles:!0},({rows:e,headers:a,getTableProps:n,getHeaderProps:s,getRowProps:i})=>l().createElement(o.Table,n(),l().createElement(o.TableHead,null,l().createElement(o.TableRow,null,a.map(e=>l().createElement(o.TableHeader,s({header:e}),e.header)))),l().createElement(o.TableBody,null,e.slice((t-1)*r).slice(0,r).map((e,t)=>l().createElement(o.TableRow,{...i({row:e}),key:t},e.cells.map((e,t)=>l().createElement(o.TableCell,{key:t},e.value))))))),e.length>10&&l().createElement(o.Pagination,{backwardText:c("previousPage","Previous page"),forwardText:c("nextPage","Next page"),itemsPerPageText:c("itemsPerPage","Items per page:"),onChange:({page:e,pageSize:t})=>{a(e),i(t)},page:1,pageSize:10,pageSizes:[10,20,30,40,50],size:"md",totalItems:e.length}),!e.length&&l().createElement(x,{displayText:c("data","data")}))};var ex=a(9785),eO=a(3285),eL=a(4476);let eA={featureName:"cohort-builder",moduleName:"@openmrs/esm-cohort-builder-app"},eP=a(4767);function e$(){}let eq=(0,r.getSyncLifecycle)(()=>{let{t:e}=(0,s.useTranslation)(),[t,a]=(0,n.useState)([]),[i,c]=(0,n.useState)(!0),m="tablet"===(0,r.useLayoutType)(),u=(t,n)=>new Promise(l=>{a([]),p(t).then(({data:{rows:o}})=>{var s;let i,m;o.map(e=>{e.id=e.patientId.toString(),e.name=`${e.firstname} ${e.lastname}`}),a(o),s=t.query,i=JSON.parse(window.sessionStorage.getItem("openmrsHistory")),m=[],m=i?[...i,{description:n,patients:o,parameters:s}]:[{description:n,patients:o,parameters:s}],window.sessionStorage.setItem("openmrsHistory",JSON.stringify(m)),(0,r.showSnackbar)({title:e("searchCompleted","Search completed"),kind:"success",isLowContrast:!0,subtitle:e("noOfResultsFound","{{count}} results found",{count:o.length})}),c(!0),l(!0)}).catch(t=>{(0,r.showSnackbar)({title:e("error","Error"),kind:"error",isLowContrast:!1,subtitle:t?.message}),l(!0)})}),h=async t=>{try{let n=await E(t);a(n),(0,r.showSnackbar)({title:e("searchCompleted","Search completed"),kind:"success",isLowContrast:!0,subtitle:e("noOfResultsFound","{{count}} results found",{count:n.length})})}catch(t){(0,r.showSnackbar)({title:e("error","Error"),kind:"error",isLowContrast:!1,subtitle:t?.message})}},b=async t=>{try{let n=await g(t);a(n),(0,r.showSnackbar)({title:e("searchCompleted","Search completed"),kind:"success",isLowContrast:!0,subtitle:e("noOfResultsFound","{{count}} results found",{count:n.length})})}catch(t){(0,r.showSnackbar)({title:e("error","Error"),kind:"error",isLowContrast:!1,subtitle:t?.message})}},_=[{name:e("concepts","Concepts"),component:l().createElement(es,{onSubmit:u})},{name:e("demographics","Demographics"),component:l().createElement(ed,{onSubmit:u})},{name:e("personAttributes","Person Attributes"),component:l().createElement(ev,{onSubmit:u})},{name:e("encounters","Encounters"),component:l().createElement(eE,{onSubmit:u})},{name:e("location","Location"),component:l().createElement(ey,{onSubmit:u})},{name:e("enrollments","Enrollments"),component:l().createElement(e_,{onSubmit:u})},{name:e("drugOrder","Drug Order"),component:l().createElement(eh,{onSubmit:u})},{name:e("composition","Composition"),component:l().createElement(N,{onSubmit:u})},{name:e("savedCohorts","Saved Cohorts"),component:l().createElement(H,{onViewCohort:b})},{name:e("savedQueries","Saved Queries"),component:l().createElement(W,{onViewQuery:h})}];return l().createElement("div",null,l().createElement(r.PageHeader,{className:"-esm-cohort-builder__cohort-builder__header___VRsag"},l().createElement(r.PageHeaderContent,{illustration:l().createElement(r.CohortsPictogram,null),title:e("cohortBuilder","Cohort Builder")})),l().createElement("div",{className:d()("-esm-cohort-builder__cohort-builder__mainContainer___LXqCB","-esm-cohort-builder__cohort-builder__cohortBuilder___IqfBP")},l().createElement("div",{className:d()(m?"-esm-cohort-builder__cohort-builder__tabletContainer___7xD+u":"-esm-cohort-builder__cohort-builder__desktopContainer___I5sch")},l().createElement("div",{className:"-esm-cohort-builder__cohort-builder__tabContainer___u8YU-"},l().createElement("p",{className:$},e("searchCriteria","Search Criteria")),l().createElement("div",{className:q},l().createElement(o.Tabs,null,l().createElement(o.TabList,{"aria-label":"navigation"},_.map((e,t)=>l().createElement(o.Tab,{className:q,key:t},e.name))),l().createElement(o.TabPanels,null,_.map((e,t)=>l().createElement(o.TabPanel,{key:t},e.component)))))),l().createElement(eY,{patients:t}),l().createElement(eM,{isHistoryUpdated:i,setIsHistoryUpdated:c}))))},eA),eR=(0,r.getSyncLifecycle)(()=>{let{t:e}=(0,s.useTranslation)();return l().createElement(o.Layer,null,l().createElement(o.ClickableTile,{href:`${window.spaBase}/cohort-builder`},l().createElement("div",null,l().createElement("div",{className:"heading"},e("manageCohorts","Manage Cohorts")),l().createElement("div",{className:"content"},e("cohortBuilder","Cohort Builder"))),l().createElement("div",{className:"iconWrapper"},l().createElement(c.Qp,{size:16}))))},eA),eB=(0,r.getSyncLifecycle)(({closeModal:e,onRemove:t,searchItemName:a})=>{let{t:c}=(0,s.useTranslation)(),[m,d]=(0,n.useState)(!1);return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:c("clearItemFromHistory","Clear item from search history")}),l().createElement(o.ModalBody,null,l().createElement("p",null,c("removeItemFromSearchHistory","Are you sure you want to remove this item from the search history?")),l().createElement("br",null),l().createElement("p",null,l().createElement("strong",null,'"',a,'"'))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,kind:"danger",onClick:()=>{d(!0),t(),d(!1),e()},disabled:m},m?l().createElement(o.InlineLoading,{description:c("removing","Removing")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("delete")))))},eA),eF=(0,r.getSyncLifecycle)(({closeModal:e,onClearHistory:t,searchItemName:a})=>{let{t:c}=(0,s.useTranslation)(),[m,d]=(0,n.useState)(!1);return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:c("clearSearchHistory","Clear search history")}),l().createElement(o.ModalBody,null,l().createElement("p",null,c("clearSearchHistoryModalText","Are you sure you want to clear the search history?"))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,disabled:m,kind:"danger",onClick:()=>{d(!0),t(),d(!1),e()}},m?l().createElement(o.InlineLoading,{description:c("clearing","Clearing")+"..."}):l().createElement("span",null,c("clearHistory","Clear history")))))},eA),eH=(0,r.getSyncLifecycle)(({closeModal:e,cohortName:t,onDeleteCohort:a})=>{let{t:i}=(0,s.useTranslation)(),[c,m]=(0,n.useState)(!1);return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:i("deleteCohort","Delete cohort")}),l().createElement(o.ModalBody,null,l().createElement("p",null,i("deleteCohortModalText","Are you sure you want to delete the cohort")," ",l().createElement("strong",null,'"',t,'"'),"?")),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:"-esm-cohort-builder__delete-cohort__deleteButton___15Gkt",kind:"danger",onClick:()=>{m(!0),a(),m(!1),e()},disabled:c},c?l().createElement(o.InlineLoading,{description:i("deleting","Deleting")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("delete")))))},eA),ez=(0,r.getSyncLifecycle)(({closeModal:e,queryName:t,queryId:a,onDelete:i})=>{let{t:c}=(0,s.useTranslation)(),[m,d]=(0,n.useState)(!1),u=async()=>{d(!0),await i(a),d(!1)};return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:c("deleteSavedQuery","Delete saved query")}),l().createElement(o.ModalBody,null,l().createElement("p",null,c("deleteSavedQueryConfirmation","Are you sure you want to delete this saved query?"))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{kind:"danger",onClick:u,disabled:m},m?l().createElement(o.InlineLoading,{description:c("deleting","Deleting")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("delete")))))},eA),eU=(0,r.getSyncLifecycle)(({closeModal:e,onSave:t})=>{let{t:a}=(0,s.useTranslation)(),{control:n,handleSubmit:c,formState:{errors:m}}=(0,ex.mN)({resolver:(0,eO.u)(eL.z.object({name:eL.z.string({required_error:a("cohortNameRequired","Cohort name is required")}).trim().min(1,a("cohortNameRequired","Cohort name is required")),description:eL.z.string({required_error:a("cohortDescriptionRequired","Description is required")}).trim().min(1,a("cohortDescriptionRequired","Description is required"))})),mode:"onChange"}),d=a=>{t(a.name.trim(),a.description.trim()),e()};return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:a("saveCohort","Save cohort")}),l().createElement(o.ModalBody,null,l().createElement("form",{onSubmit:c(d)},l().createElement(o.Stack,{gap:5},l().createElement(ex.xI,{name:"name",control:n,render:({field:e})=>l().createElement(o.TextInput,{"data-testid":"cohort-name",id:"cohort-name",labelText:a("enterCohortName","Enter a cohort name"),...e,invalid:!!m.name,invalidText:m.name?.message})}),l().createElement(ex.xI,{name:"description",control:n,render:({field:e})=>l().createElement(o.TextInput,{"data-testid":"cohort-description",id:"cohort-description",labelText:a("enterCohortDescription","Enter a cohort description"),...e,invalid:!!m.description,invalidText:m.description?.message})})))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,kind:"danger",onClick:c(d)},l().createElement("span",null,(0,r.getCoreTranslation)("save")))))},eA),eQ=(0,r.getSyncLifecycle)(({closeModal:e,onSaveQuery:t})=>{let{t:a}=(0,s.useTranslation)(),{control:n,handleSubmit:c,formState:{errors:m,isSubmitting:d}}=(0,ex.mN)({resolver:(0,eO.u)(eL.z.object({queryName:eL.z.string({required_error:a("queryNameRequired","Name is required")}).min(1,a("queryNameRequired","Name is required")),queryDescription:eL.z.string({required_error:a("queryDescriptionRequired","Description is required")}).min(1,a("queryDescriptionRequired","Description is required"))})),defaultValues:{queryName:"",queryDescription:""}}),u=async a=>{await t(a),e()};return l().createElement("div",null,l().createElement(o.ModalHeader,{closeModal:e,title:a("saveQuery","Save query")}),l().createElement("form",{onSubmit:c(u)},l().createElement(o.ModalBody,null,l().createElement(o.Stack,{gap:5},l().createElement(ex.xI,{name:"queryName",control:n,render:({field:e})=>l().createElement(o.TextInput,{...e,labelText:a("enterQueryName","Enter a name for the query"),id:"query-name","data-testid":"query-name",invalid:!!m.queryName,invalidText:m.queryName?.message})}),l().createElement(ex.xI,{name:"queryDescription",control:n,render:({field:e})=>l().createElement(o.TextInput,{...e,labelText:a("enterQueryDescription","Enter a description of the query"),id:"query-description",invalid:!!m.queryDescription,invalidText:m.queryDescription?.message})}))),l().createElement(o.ModalFooter,null,l().createElement(o.Button,{kind:"secondary",onClick:e},(0,r.getCoreTranslation)("cancel")),l().createElement(o.Button,{className:i,disabled:d,kind:"primary",type:"submit"},d?l().createElement(o.InlineLoading,{description:a("saving","Saving")+"..."}):l().createElement("span",null,(0,r.getCoreTranslation)("save"))))))},eA)}}]);