Extracting Information from XML in SQL Server after performing a join - sql

I have a SQL table create through the following code with the column UserDefinedXML that contains a information I need to be able to extract.
SELECT A.ExternalID, A.UserDefinedXML, A.ServiceSiteUid, A.LastModifiedDate, A.PersonUid,
B.FirstName, B.LastName, B.PersonUid,
C.Name
FROM Patient A
INNER JOIN Person B ON B.PersonUid = A.PersonUid
INNER JOIN ListServiceSite C ON C.ServiceSiteUid = A.ServiceSiteUid
WHERE A.UserDefinedXML IS NOT NULL
ORDER By LastModifiedDate
I have been extracting it through a lot of gsubs in R but that is inefficient and not the best way to go about it, I'm sure. The XML format is below
<data>
<LOA>
<NotMedNecessaryInsCompany ControlType="PrmTextBox" Value="" Label="" />
<DicontinuedDate ControlType="FindDateBox" Value="" Label="" Display="false" />
<ReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" />
<SentDate ControlType="FindDateBox" Value="" Label="" Display="false" />
<ReasonDiscontinued ControlType="PrmTextBox" Value="" Label="" />
<NoOONBenefitsInsCompany ControlType="PrmTextBox" Value="" Label="" />
<InsuranceStatus ControlType="PrmGroupBox" Label="" Value="" />
<OtherReasonDenied ControlType="PrmTextBox" Value="" Label="" />
<FacilityRefused ControlType="PrmCheckBox" Value="false" Label="Facility Refused" />
<ReasonDenied ControlType="PrmCheckBox" Value="false" Label="Other" />
</LOA>
<Forms>
<POReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" />
<InformedConsentReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" />
<AuthorizationToTreatReceivedDate ControlType="FindDateBox" Value="" Label="" Display="false" />
</Forms>
<Skin_Sheet>
<SkinSheet ControlType="PrmGroupBox" Label="No" Checked="PrmRadioButton1" Value="" />
</Skin_Sheet>
</data>
For the moment, I am just interested in whether "Yes" or "No" is selected in the last few lines under the SkinSheet header. Ultimately, I will need to be able to access all of the fields in this string. Unfortunately I am very inexperienced with SQL and have been thrown into it at work so I am trying to learn on the fly.

Assuming that UserDefinedXML is XML datatype, just use the value function:
SELECT A.UserDefinedXML.value('(//SkinSheet/#Label)[1]', 'varchar(100)'), other, columns
FROM ...

Related

How to manually enter the location coordinates on the Itempost page ( osclass )?

How to manually enter the location coordinates on the Itempost page in osclass?
<input id="d_coord_lat" type="" name="d_coord_lat" value="" />
<input id="d_coord_long" type="" name="d_coord_long" value="" />
I tried it
But it does not add data
If the data is there, it should appear somewhere value
Thank

File Watchers not working in Intellij for isort and autoflake combination

I have a Python file with multiline import statement:
from itertools import (
accumulate,
chain,
combinations,
combinations_with_replacement,
compress,
count,
islice,
product
)
from which I try to remove unused imports by first changing multiline import statement to single-line imports:
isort -sl totest.py
autoflake --remove-all-unused-imports --remove-unused-variables -i totest.py
It works great in command line, but when using File Watchers in Intellij it does not run autoflake when saving file for the first time. Basically, to get around it I need to:
Make some edit, e.g., add some space
Save file
It gets formatted to:
from itertools import accumulate
from itertools import chain
from itertools import combinations
from itertools import combinations_with_replacement
from itertools import compress
from itertools import count
from itertools import islice
from itertools import product
And then make another edit
Save file
And redundant imports gets removed
Steps 4 and 5 are redundant.
I wonder what could be the reason and where should I report that? To IDEA Intellij team, to isort or where?
Here's my watchers.xml to import into Intellij.
<TaskOptions>
<TaskOptions>
<option name="arguments" value="--remove-all-unused-imports --remove-unused-variables -i $FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="py" />
<option name="immediateSync" value="false" />
<option name="name" value="Remove unused variables and imports" />
<option name="output" value="$FilePath$" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="autoflake" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="" />
<envs />
</TaskOptions>
<TaskOptions>
<option name="arguments" value="-sp $$ProjectFileDir$/.isort.cfg $FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="py" />
<option name="immediateSync" value="false" />
<option name="name" value="Organize imports" />
<option name="output" value="$FilePath$" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="isort" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="" />
<envs />
</TaskOptions>
<TaskOptions>
<option name="arguments" value="--config="$ProjectFileDir$"/pyproject.toml $FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="py" />
<option name="immediateSync" value="false" />
<option name="name" value="Format code (with Black)" />
<option name="output" value="$FilePath$" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="black" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="" />
<envs />
</TaskOptions>
</TaskOptions>

How do I pick a value from XML column in a table with a condition. XML form contains different page

I have a xml data column. The XML data contains a form with different page headers. Each page has radio type values. I need to pick the value from one page and its values.
I need the value 'id' from Page topic='Outreach' under that, Question value="Type of Outreach", in that i need the id="1" value and also i need the id value from Question value="Reason for Assessment".
Below is the sample xml data.
<Test name="Assessment " header="" logoimg="" background="" icon="" firstPage="1" allow_abort="1" is_um="0" is_hidden="0" do_only="1" status="1" locale_id="0" version="74" category_id="150011" maxQuestionID="37" id="10234" force_start="0" user_name=" ggg bbb">
<PAGE topic="Outreach " progress="5" background="" headerid="" footerid="" flush_concepts="1" lastPage="false" id="1">
<BRANCH_CONDITION>
<NEXT_PAGE id="2" />
</BRANCH_CONDITION>
<QUESTION value="Type of Outreach " defaultvalue="" style="" tooltip="" read_only="0" usability="5" prefer_concept="0" type="radio" validation="0" id="1" pagename="Outreach ">
<OPTIONS>
<OPTION value="Outbound Telephone " id="1" url="" score="0" />
<OPTION value="Inbound Telephone" id="2" url="" score="0" />
<OPTION value="In Person" id="3" url="" score="0" />
</OPTIONS>
</QUESTION>
<QUESTION value="Reason for Assessment " defaultvalue="" style="" tooltip="" read_only="0" usability="5" prefer_concept="0" type="radio" validation="0" id="2" pagename="Outreach ">
<OPTIONS>
<OPTION value="New" id="1" url="" score="0" />
<OPTION value="Annual" id="2" url="" score="0" />
<OPTION value="Triggering Event " id="3" url="" score="0" />
<OPTION value="LOC Review" id="4" url="" score="0" />
</OPTIONS>
</QUESTION>
I tried the following sql.
SELECT TABLE.META_DATA.value('(/QUESTION//id/node())[1]','int') as outReach
,TABLE.META_DATA.value('(/QUESTION//id/node())[1]','int') as ReasonForAssessment
FROM Table
Below is my expected result
+----------+---------------------+
| Outreach | ReasonForAssessment |
+----------+---------------------+
| 1 | 2 |
Several issues:
QUESTION is not the root of the XML so you must use // or walk down tree from root: /Test/PAGE/QUESTION/.
Adjust XPath to search by attribute with # prefix and not node search as id is an attribute (not child node) of QUESTION.
Adjust node index, [#], to return the corresponding #id attribute value.
Adjusted SQL:
SELECT TABLE.META_DATA.value('(//QUESTION/#id)[1]','int') as outReach
, TABLE.META_DATA.value('(//QUESTION/#id)[2]','int') as ReasonForAssessment
FROM Table;
-- outReach ReasonForAssessment
-- 1 2
Alternatively use bracketed conditionals for columns:
SELECT TABLE.META_DATA.value('(/Test/PAGE/QUESTION[#value=''Type of Outreach '']/#id)[1]','int') as outReach
, TABLE.META_DATA.value('(/Test/PAGE/QUESTION[#value=''Reason for Assessment '']/#id)[1]','int') as ReasonForAssessment
FROM Table;
-- outReach ReasonForAssessment
-- 1 2

dataExporter cannot be rendered because of form needing

I am trying to add dataExporter component to my table.
First I had {Exporters} beside pagination facet , then after a lot of tries I got this error in the console
HTML nesting warning on closing changes: element update not explicitly closed
I solved it also but now there is nothing appears in the Exporter facet. I googled it and found that I need a form in my page because of this commandlink submit a form , so it needs a form.
My Question here is how to apply this example in my project.
Here is my code.
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.ViewLfmTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green"
layout="table" />
</h:panelGroup>
<p:dialog header="Add Task" widgetVar="dlg" position="center center"
onShow="PF('dlg').initPosition()" modal="true" closeOnEscape="true"
resizable="false">
<h:form>
<h:panelGrid columns="2">
<p:outputLabel value="#{bundle.CreateTaskLabel_name}" for="name" />
<p:inputText id="name"
value="#{ViewLfmJpaController.newTaskDTO.name}"
title="#{bundle.CreateTaskTitle_name}" />
<p:outputLabel value="#{bundle.CreateTaskLabel_durationPerMonth}"
for="durationPerMonth" />
<p:inputText id="durationPerMonth"
value="#{ViewLfmJpaController.newTaskDTO.duration}"
title="#{bundle.CreateTaskTitle_durationPerMonth}" />
<p:outputLabel value="#{bundle.CreateTaskLabel_startDate}"
for="startDate" />
<p:calendar id="startDate"
value="#{ViewLfmJpaController.newTaskDTO.startDate}"
title="#{bundle.CreateTaskTitle_startDate}" pattern="d MMM yyyy"
effect="fold">
<f:convertDateTime pattern="d MMM yyyy" />
</p:calendar>
<p:outputLabel value="#{bundle.CreateTaskLabel_endDate}"
for="endDate" />
<p:calendar id="endDate"
value="#{ViewLfmJpaController.newTaskDTO.endDate}"
title="#{bundle.CreateTaskTitle_endDate}" pattern="d MMM yyyy"
effect="fold">
<f:convertDateTime pattern="d MMM yyyy" />
</p:calendar>
<f:facet name="footer">
<p:commandButton value="Add"
actionListener="#{ViewLfmJpaController.addTask}" update="Matrix"
oncomplete="PF('dlg').hide()" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dataTable id="Matrix" resizableColumns="true" scrollable="true"
scrollHeight="80%"
value="#{ViewLfmJpaController.selected.tasksDtoCollection}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
var="item" resizeMode="expand" paginator="true" rows="10"
style="margin-bottom:20px">
<f:facet name="header">
Logical Framewrok Matrix
</f:facet>
<f:facet name="{Exporters}">
<p:commandLink>
<p:graphicImage name="../resources/images/pdf.jpg" width="24" />
<p:dataExporter type="pdf" target="Matrix" fileName="lfm" />
</p:commandLink>
</f:facet>
<p:column headerText="Index" colspan="1">
<c:forEach var="i" begin="1" end="#{ViewLfmJpaController.listSize}">
<p:outputLabel value="#{i}"></p:outputLabel>
</c:forEach>
</p:column>
<p:column headerText="Task Title">
<p:outputLabel value="#{item.name}"></p:outputLabel>
</p:column>
<p:column headerText="Start Date" colspan="3">
<p:outputLabel value="#{item.formatedStartDate}"></p:outputLabel>
</p:column>
<p:column headerText="End Date" colspan="3">
<p:outputLabel value="#{item.formatedEndDate}"></p:outputLabel>
</p:column>
<c:forEach var="i" begin="1"
end="#{ViewLfmJpaController.numberOfMonths}">
<p:column headerText="m ${i}" colspan="1"></p:column>
</c:forEach>
<p:column headerText="Exptected Outcomes" colspan="4">
<ui:repeat value="#{item.tasksExpectedOutcomesCollection}" var="teo">
<li><h:outputText value="#{teo.expectation}">
</h:outputText></li>
</ui:repeat>
</p:column>
</p:dataTable>
<p:commandButton value="Add Task" oncomplete="PF('dlg').show()"></p:commandButton>
</ui:define>
</ui:composition>
I FOUND THE SOLUTION BY MYSELF.
First : You have to know that you cannot make nested forms in your page.
Second : you have to know that to submit <p:dialog> </p:dialog> or to use <h:commandLink> </h:commandLink> you need to use form.
So I had removed the form in the dialog component and add a general component contains dialog and dataTable together

How to loop through components with same prop

I have several TextInputs with the prop 'form' to identify the forms they belong to.
<TextInput form="user" name="first_name" placeholder="First Name"/>
<TextInput form="user" name="last_name" placeholder="Last Name"/>
<TextInput form="login" name="username" placeholder="Username"/>
How do I loop through components that have the prop form="user", in this case I would want to get first_name and last_name and leave out username.