To reduce the complexity, for the first pass, i would not worry about transactions. I would just write code that saves data assuming it is correctly formatted and hence passes all validations.
After that is done and confirmed to work, i would then look into the transactional issues.
@ssmusoke- It would probably be easier if you could find a way to create encounters first then add observations later. You can add another column to the file, with generated UUIDs and each encounter would be saved with the corresponding UUID. The added column would also be a way of tagging this encounters so you can recognize them easily. It will also help you to map observations to their corresponding encounters later when you get to creating observations. …and because you will have that mapping, you can decide to create observations one column at a time.
I assume the following would work:
Encounter existingEncounter = Context.getEncounterService().getEncounterByUuid("some uuid");
Obs o = new Obs();
o.setConcept(Context.getConceptService().getConcept("The concept in the current column"));
o.setValueText("valueText"); //or o.setValueCoded(Context.getConceptService().getConcept(someConcept)); or o.setValueDate(valueDate); or o.setValueText(valueText);
o.setEncounter(existingEncounter);
existingEncounter.addObs(o);
Context.getEncounterService().saveEncounter(existingEncounter);
On saving encounters, I would prefer to save them all at once. …having @Transactional annotation on the saving method in your service implementation would let Spring start and commit/rollback transactions for you.