Medical Services challenge with Prolog

2021-02-02

My #swi #prolog solution for “Benchmark ‘Medical Services’” proposed by dmcommunity.org challenge Feb 2021 can be tested running a public docker image

	docker run -p 8888:8888 -d --name matteoredaelli/dmcommunity_org_2021_02:latest
	wget https://github.com/DMCommunity/dmcommunity_shared/raw/master/MedicalServices.json
	curl -XPOST -d @MedicalServices.json -H "Accept: application/json" -H "Content-type: application/json" http://localhost:8888/many

The decision table is a set of prolog facts like

decision_table('Office','acupuncture','PL123','L','Y','N','2015-01-01','2023-12-31','N','N','N').
decision_table('Outpatient','acupuncture','PL123','L','Y','N','2015-01-01','2023-12-31','N','N','N').
decision_table('Inpatient','acupuncture','PL123','L','N','N','2015-01-01','2023-12-31','N','N','N').

The core of the solution is inside the rules.pl file

parse_input(json([placeOfService=PlaceOfService,
		  type=Type,
		  plan=Plan,
		  groupSize=GroupSize,
		  inNetwork=InNetwork,
		  isCovered=IsCovered,
		  dateOfService=DateOfService,
		  coveredInFull=_,
		  copay=_,
		  coInsurance=_]),
		json([placeOfService=PlaceOfService,
		  type=Type,
		  plan=Plan,
		  groupSize=GroupSize,
		  inNetwork=InNetwork,
		  isCovered=IsCovered,
		  dateOfService=DateOfService,
		  coveredInFull=CoveredInFull,
		  copay=Copay,
		  coInsurance=CoInsurance])):-
	decision_table(PlaceOfService,
			   Type,
			   Plan,
			   GroupSize,
			   InNetwork,
			   IsCovered,
			   DateOfService1,
			   DateOfService2,
			   CoveredInFull,
			   Copay,
			   CoInsurance),
	%% check date: must be between the two dates in decision_table
	atom_string(DateOfService, DateOfServiceString),
	atom_string(DateOfService1, DateOfService1String),
	atom_string(DateOfService2, DateOfService2String),
	DateOfService1String @=< DateOfServiceString,
	DateOfServiceString  @=< DateOfService2String.

The file server.pl contains the code for the rest server that exposes the core functions as http POST requests.

References:


Enter your instance's address


More posts like this

Smart investment Problem with Prolog

2024-07-14 | #programming #prolog

Below my #prolog solution for Smart investment problem. It is a sample of Linear Programming using Prolog. A client of an investment firm has $10000 available for investment. He has instructed that his money be invested in particular stocks, so that no more than $5000 is invested in any one stock but at least $1000 be invested in each stock.

Continue reading 


Stable Marriage Problem with Prolog

2024-06-07 | #programming #prolog

My #prolog solution for Stable Marriage Problem proposed by dmcommunity.org challenge Jun 2024. Given n men and n women, where each person has ranked all members of the opposite sex in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners.

Continue reading 