2222import org .apache .camel .LoggingLevel ;
2323import org .apache .camel .builder .RouteBuilder ;
2424import org .apache .http .ProtocolException ;
25+
26+ import org .hl7 .fhir .dstu3 .model .Bundle ;
27+ import org .hl7 .fhir .dstu3 .model .Identifier ;
2528import org .hl7 .fhir .dstu3 .model .Patient ;
29+ import org .hl7 .fhir .dstu3 .model .Resource ;
30+ import org .hl7 .fhir .instance .model .api .IBaseResource ;
2631import org .springframework .stereotype .Component ;
2732
2833/**
@@ -36,29 +41,34 @@ public class MyCamelRouter extends RouteBuilder {
3641 @ Override
3742 public void configure () throws Exception {
3843 from ("file:{{input}}" ).routeId ("fhir-example" )
39- .onException (ProtocolException .class )
44+ .onException (ProtocolException .class )
4045 .handled (true )
4146 .log (LoggingLevel .ERROR , "Error connecting to FHIR server with URL:{{serverUrl}}, please check the application.properties file ${exception.message}" )
42- .end ()
43- .log ("Converting ${file:name}" )
44- .unmarshal ().csv ()
45- .process (exchange -> {
46- List <Patient > bundle = new ArrayList <>();
47- @ SuppressWarnings ("unchecked" )
48- List <List <String >> patients = (List <List <String >>) exchange .getIn ().getBody ();
49- for (List <String > patient : patients ) {
50- Patient fhirPatient = new Patient ();
51- fhirPatient .setId (patient .get (0 ));
52- fhirPatient .addName ().addGiven (patient .get (1 ));
53- fhirPatient .getNameFirstRep ().setFamily (patient .get (2 ));
54- bundle .add (fhirPatient );
55- }
56- exchange .getIn ().setBody (bundle );
57- })
58- // create Patient in our FHIR server
59- .to ("fhir://transaction/withResources?inBody=resources&serverUrl={{serverUrl}}&username={{serverUser}}&password={{serverPassword}}&fhirVersion={{fhirVersion}}" )
60- // log the outcome
61- .log ("Patients created successfully: ${body}" );
47+ .end ()
48+ .log ("Converting ${file:name}" )
49+ .unmarshal ().csv ()
50+ .process (exchange -> {
51+
52+ Bundle bundleTest = new Bundle ();
53+ bundleTest .setId ("bundle-simplified-001" );
54+ bundleTest .setIdentifier (new Identifier ().setValue ("001" ));
55+ bundleTest .setType (org .hl7 .fhir .dstu3 .model .Bundle .BundleType .TRANSACTION );
56+
57+ @ SuppressWarnings ("unchecked" )
58+ List <List <String >> patients = (List <List <String >>) exchange .getIn ().getBody ();
59+ for (List <String > patient : patients ) {
60+ Patient fhirPatient = new Patient ();
61+ fhirPatient .setId (patient .get (0 ));
62+ fhirPatient .addName ().addGiven (patient .get (1 ));
63+ fhirPatient .getNameFirstRep ().setFamily (patient .get (2 ));
64+ bundleTest .addEntry ().setResource (fhirPatient ).getRequest ().setMethod (Bundle .HTTPVerb .POST );
65+ }
66+ exchange .getIn ().setBody (bundleTest );
67+ })
68+ // create Patient in our FHIR server
69+ .to ("fhir://transaction/withBundle?inBody=bundle&serverUrl={{serverUrl}}&username={{serverUser}}&password={{serverPassword}}&fhirVersion={{fhirVersion}}" )
70+ // log the outcome
71+ .log ("Patients created successfully: ${body}" );
6272 }
6373
6474}
0 commit comments