HL7 segments order - java

I'm parsing SIU S14 with the following segments order:
MSH
SCH
PID
PV1
RGS
AIL
AIS
and although it parses without error, I can't retrieve data from AIS segment. But when I move AIS segement before AIL, everything seems to work fine. So does segments order matter in HL7?

The order of segments in a HL7 message is predetermined by the message type. In Schedule Information Unsolicited messages the AIS segment has to be ahead of AIL.
SIU^S12-S24,S26,S27^SIU_S12: Schedule Information Unsolicited
MSH Message Header
SCH Schedule Activity Information
[ { TQ1 } ] Timing/Quantity
[ { NTE } ] Notes and Comments for the SCH
[ { --- PATIENT begin
PID Patient Identification
[ PD1 ] Additional Demographics
[ PV1 ] Patient Visit
[ PV2 ] Patient Visit - Additional Info
[ { OBX } ] Observation/Result
[ { DG1 } ] Diagnosis
} ] --- PATIENT end
{ --- RESOURCES begin
RGS Resource Group Segment
[ { --- SERVICE begin
AIS Appointment Information - Service
[ { NTE } ] Notes and Comments for the AIS
} ] --- SERVICE end
[ { --- GENERAL_RESOURCE begin
AIG Appointment Information - General Resource
[ { NTE } ] Notes and Comments for the AIG
} ] --- GENERAL_RESOURCE end
[ { --- LOCATION_RESOURCE begin
AIL Appointment Information - Location Resource
[ { NTE } ] Notes and Comments for the AIL
} ] --- LOCATION_RESOURCE end
[ { --- PERSONNEL_RESOURCE begin
AIP Appointment Information - Personnel Resource
[ { NTE } ] Notes and Comments for the AIP
} ] --- PERSONNEL_RESOURCE end
} --- RESOURCES end
But both segments respectively their segment groups are optional. So a message with just an AIL and no AIS segment is syntactically ok. And as HL7 messages are open, there are additional or local defined segments allowed after a complete message.In order to retrieve this additional data you need an adapted template.

Related

Enum implementing traits - memory issues?

I'm trying to DRY my code and I used for that, for the first time, traits to enhance my enums.
What I want to do, is : for a given array of strings, find all the enums matching at least one keyword (non case sensitive)
The code below seems to works fine, but I think it generates me memory leaks when the method getSymbolFromIndustries is called thousands of times.
Here is a capture from VisualVM after about 10 minutes of run, the column Live Objects is always increasing after each snapshot and the number of items compared to the second line is so huge...
My heap size is always increasing too...
The trait :
trait BasedOnCategories {
String[] categories
static getSymbolFromIndustries(Collection<String> candidates) {
values().findAll {
value -> !value.categories.findAll {
categorie -> candidates.any {
candidate -> categorie.equalsIgnoreCase(candidate)
}
}
.unique()
.isEmpty()
}
}
}
One of the multiple enums I have implementing the trait
enum KTC implements BasedOnCategories, BasedOnValues {
KTC_01([
'industries': ['Artificial Intelligence','Machine Learning','Intelligent Systems','Natural Language Processing','Predictive Analytics','Google Glass','Image Recognition', 'Apps' ],
'keywords': ['AI','Voice recognition']
]),
// ... more values
KTC_43 ([
'industries': ['Fuel','Oil and Gas','Fossil Fuels'],
'keywords': ['Petroleum','Oil','Petrochemicals','Hydrocarbon','Refining']
]),
// ... more values
KTC_60([
'industries': ['App Discovery','Apps','Consumer Applications','Enterprise Applications','Mobile Apps','Reading Apps','Web Apps','App Marketing','Application Performance Management', 'Apps' ],
'keywords': ['App','Application']
])
KTC(value) {
this.categories = value.industries
this.keywords = value.keywords
}
My data-driven tests
def "GetKTCsFromIndustries"(Collection<String> actual, Enum[] expected) {
expect:
assert expected == KTC.getSymbolFromIndustries(actual)
where:
actual | expected
[ 'Oil and Gas' ] | [KTC.KTC_43]
[ 'oil and gas' ] | [KTC.KTC_43]
[ 'oil and gas', 'Fossil Fuels' ] | [KTC.KTC_43]
[ 'oil and gas', 'Natural Language Processing' ] | [KTC.KTC_01, KTC.KTC_43]
[ 'apps' ] | [KTC.KTC_01, KTC.KTC_60]
[ 'xyo' ] | []
}
My questions :
If someone have some clues to help me fix those leaks...
Is there a more elegant way to write the getSymbolFromIndustries method ?
thanks.
Not sure about performance issues, but I would redesign your trait like that:
https://groovyconsole.appspot.com/script/5205045624700928
trait BasedOnCategories {
Set<String> categories
void setCategories( Collection<String> cats ) {
categories = new HashSet( cats*.toLowerCase() ).asImmutable()
}
#groovy.transform.Memoized
static getSymbolFromIndustries(Collection<String> candidates) {
def lowers = candidates*.toLowerCase()
values().findAll{ value -> !lowers.disjoint( value.categories ) }
}
}
Now the rest of the context
trait BasedOnValues {
Set<String> keywords
}
enum KTC implements BasedOnCategories, BasedOnValues {
KTC_01([
'industries': ['Artificial Intelligence','Machine Learning','Intelligent Systems','Natural Language Processing','Predictive Analytics','Google Glass','Image Recognition'],
'keywords': ['AI','Voice recognition']
]),
// ... more values
KTC_43 ([
'industries': ['Fuel','Oil and Gas','Fossil Fuels'],
'keywords': ['Petroleum','Oil','Petrochemicals','Hydrocarbon','Refining']
]),
// ... more values
KTC_60([
'industries': ['App Discovery','Apps','Consumer Applications','Enterprise Applications','Mobile Apps','Reading Apps','Web Apps','App Marketing','Application Performance Management'],
'keywords': ['App','Application']
])
KTC(value) {
this.categories = value.industries
this.keywords = value.keywords
}
}
// some tests
[
[ [ 'Oil and Gas' ], [KTC.KTC_43] ],
[ [ 'oil and gas' ], [KTC.KTC_43] ],
[ [ 'oil and gas', 'Fossil Fuels' ], [KTC.KTC_43] ],
[ [ 'oil and gas', 'Natural Language Processing' ], [KTC.KTC_01, KTC.KTC_43] ],
[ [ 'xyo' ], [] ],
].each{
assert KTC.getSymbolFromIndustries( it[ 0 ] ) == it[ 1 ]
}
and then measure the performance

Use JPA to store data in Array-list of coordinates as a polygon in spring-boot

"boundary": {
"type": "Polygon",
"coordinates": [
[
[
-73.9493302,
40.7851967
],
[
-73.9538181,
40.7870864
],
[
-73.9541536,
40.7872279
],
[
-73.9557237,
40.7878894
],
[
-73.9604089,
40.7815447
],
[
-73.9539823,
40.7788333
],
[
-73.9493302,
40.7851967
]
]
]
}
I am getting the above data from an API and I have POJOs to save all the other data. I am however failing to create a polygon from the coordinates in order to save it in MySQL and retrieve later.
#JsonProperty("coordinates")
private Polygon geomertry;
The above won't work. I am fairly new to this so any help is welcome.
You have to use arrays or List.
#JsonProperty("coordinates")
private double[][][] geomertry;

MongoTemplate pull query

I am trying to remove one Item from an array of an embedded field in mongoDb. Array is type of string like the below one.
{
_id: 1,
fruits: [ "apples", "pears", "oranges", "grapes", "bananas" ],
vegetables: [ "carrots", "celery", "squash", "carrots" ]
}
{
_id: 2,
fruits: [ "plums", "kiwis", "oranges", "bananas", "apples" ],
vegetables: [ "broccoli", "zucchini", "carrots", "onions" ]
}
I just wanted to remove the carrots from the embedded array vegetables. using mongo shell, the below query works
db.stores.update(
{ },
{ $pull: { vegetables: "carrots" },
{ multi: true }
)
Now I needed to perform this using mongoTemplate in spring,
I tried with the below answer but it wont remove the element
MongoTemplate pull subdocument.
Can anyone suggest How I to achieve this using mongoTemplate in spring project
You can simply use the below query to pull any string in the array of vegetables object:
mongoTemplate.updateMulti(new Query(), new Update().pull("vegetables", "squash"), "stores");
In the above query, squash will be pulled after execution. For details, I have also added find query on stores collections after and before the above query as :
List<Stores> storesList = mongoTemplate.find(new Query(), Stores.class);
for(Stores stores : storesList) {
System.out.println(stores.toString());
}
mongoTemplate.updateMulti(new Query(), new Update().pull("vegetables", "squash"), "stores");
List<Stores> afterModificationStoresList = mongoTemplate.find(new Query(), Stores.class);
for(Stores stores : afterModificationStoresList) {
System.out.println(stores.toString());
}
The output is as below :
2019-11-26 10:19:57.947 DEBUG 7321 --- [ main] o.s.data.mongodb.core.MongoTemplate : find using query: { } fields: Document{{}} for class: class sample.data.mongo.models.Stores in collection: stores
Stores{id='1.0', fruits=[apples, pears, oranges, grapes, bananas], vegetables=[celery, squash]}
Stores{id='2.0', fruits=[plums, kiwis, oranges, bananas, apples], vegetables=[broccoli, zucchini, onions]}
2019-11-26 10:19:57.975 DEBUG 7321 --- [ main] o.s.data.mongodb.core.MongoTemplate : Calling update using query: { } and update: { "$pull" : { "vegetables" : "squash" } } in collection: stores
2019-11-26 10:19:57.985 DEBUG 7321 --- [ main] o.s.data.mongodb.core.MongoTemplate : find using query: { } fields: Document{{}} for class: class sample.data.mongo.models.Stores in collection: stores
Stores{id='1.0', fruits=[apples, pears, oranges, grapes, bananas], vegetables=[celery]}
Stores{id='2.0', fruits=[plums, kiwis, oranges, bananas, apples], vegetables=[broccoli, zucchini, onions]}
For code details, kinldy visit by Github repo: https://github.com/krishnaiitd/learningJava/blob/master/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/main/Application.java#L126

how to fetch all great grand children from a json object efficiently

I am trying to figure out an efficient way to fetch all great grant children from the root. I understand it is not the best way to store information but I have no control on why we have this structure. Here is my json
{
"root": "some value",
"other-attribute": "some value",
"Level1": [
{"attr": "value"},
"attr" : "value",
"Level2": [
{"attr": "value"},
"Level3" : [
{"attr": "value"},
"Level4" :[
{"attr": "value"},
]
]
]
]
}
How can I fetch list of all "Level3" and "Level4" elements from the json. Do I have to traverse through each hierarchy then my program complexity would be O(n3) for 3 level and O(n4) for 4 level.

java jsonxpth parsing json jumping to node

I have the following data and i am using "http://commons.apache.org/jxpath/" i want to directly read the coordinates: [51.464426 -0.382974] which is lat,lng how can i read this any quick example i search around and found there is another jsonpath as well is jsonxpath going to work for me any quick solution ?
{
authenticationResultCode: "ValidCredentials"
brandLogoUri: http://dev.virtualearth.net/Branding/logo_powered_by.png
copyright: "Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation."
-
resourceSets: [
-
{
estimatedTotal: 1
-
resources: [
-
{
__type: "Location:http://schemas.microsoft.com/search/local/ws/rest/v1"
-
bbox: [
51.46056328242933
-0.39124021297987016
51.46828871757068
-0.3747077870201298
]
name: "TW4 5AP, Hounslow, United Kingdom"
-
point: {
type: "Point"
-
coordinates: [
51.464426
-0.382974
]
}
-
address: {
adminDistrict: "England"
adminDistrict2: "Hounslow"
countryRegion: "United Kingdom"
formattedAddress: "TW4 5AP, Hounslow, United Kingdom"
postalCode: "TW4 5AP"
}
confidence: "High"
entityType: "Postcode1"
}
]
}
]
statusCode: 200
statusDescription: "OK"
traceId: "16c9b05027c4486fa3adab793cfdb97e|EWRM001665|02.00.82.2800|EWRMSNVM001812, EWRMSNVM001724"
}
https://github.com/jayway/JsonPath/tree/master/json-path or http://code.google.com/p/json-path/. I dont

Categories